|
1 | | -//https://webbit.webduino.io/blockly/?demo=default#EqdrNJvwYzQy6 |
| 1 | +/* |
| 2 | + * demo site: https://webbit.webduino.io/blockly/?demo=default#EqdrNJvwYzQy6 |
| 3 | +*/ |
| 4 | + |
2 | 5 | ~async function () { |
3 | | - // 凱比定位 |
| 6 | + // 載入 js 之後顯示所有元件 |
4 | 7 | const content = document.querySelector('.content'); |
5 | 8 | content.classList.remove('loading'); |
| 9 | + |
| 10 | + // 凱比機器人和中間的圓形 logo 定位 |
6 | 11 | const kebbi = document.getElementById('svgKebbi'); |
7 | 12 | const circle = document.querySelector('.circle'); |
8 | 13 | const ww = content.offsetWidth; |
|
52 | 57 | }; |
53 | 58 |
|
54 | 59 | const urlOrigin = location.origin; |
| 60 | + const urlPath = location.pathname; |
55 | 61 | const urlHash = location.hash.replace('#', ''); |
56 | 62 | const config = { |
57 | 63 | databaseURL: "https://webbit-remote.firebaseio.com/" |
|
70 | 76 | saveBtn.addEventListener('click', async function () { |
71 | 77 | let write = await database.ref('/').push(list); |
72 | 78 | popup.classList.add('show'); |
73 | | - saveUrl.innerText = urlOrigin + '/#' + write.key; |
74 | | - window.history.pushState({}, 0, urlOrigin + '#' + write.key); |
| 79 | + let url = `${urlOrigin}${urlPath}#${write.key}`; |
| 80 | + saveUrl.innerText = url; |
| 81 | + window.history.pushState({}, 0, url); |
75 | 82 | document.getSelection().removeAllRanges(); |
76 | 83 | }); |
77 | 84 |
|
|
168 | 175 | await webduinoBroadcastor.connect(); |
169 | 176 | } |
170 | 177 | // 發送 mqtt 訊號 |
171 | | - const mqtt = async function (topic, msg) { |
| 178 | + const mqttPush = async function (topic, msg) { |
172 | 179 | if (topic == list.topic1) { |
173 | 180 | webduinoBroadcastor.send({ |
174 | 181 | topic: topic, |
|
199 | 206 | monsterBtn.forEach(e => { |
200 | 207 | let self = e; |
201 | 208 | self.addEventListener('click', () => { |
202 | | - mqtt(list.topic1, list[self.id]); |
| 209 | + mqttPush(list.topic1, list[self.id]); |
| 210 | + self.classList.add('click'); |
| 211 | + setTimeout(()=>{ |
| 212 | + self.classList.remove('click'); |
| 213 | + },100); |
203 | 214 | }); |
204 | 215 | }); |
205 | 216 |
|
|
208 | 219 | let self = e; |
209 | 220 | let msg = self.getAttribute('msg'); |
210 | 221 | self.addEventListener('click', () => { |
211 | | - mqtt(list.topic1, list[msg]); |
| 222 | + mqttPush(list.topic1, list[msg]); |
| 223 | + self.classList.add('click'); |
| 224 | + setTimeout(()=>{ |
| 225 | + self.classList.remove('click'); |
| 226 | + },100); |
212 | 227 | }); |
213 | 228 | }); |
214 | 229 |
|
215 | | - |
216 | | - |
217 | 230 | let send = { |
218 | 231 | center: false, |
219 | 232 | top: false, |
|
258 | 271 | if (kx < ww * 0.2) { |
259 | 272 | if (!send.left) { |
260 | 273 | sendCheck('left'); |
261 | | - mqtt(list.topic1, list.kebbiLeft); |
| 274 | + mqttPush(list.topic1, list.kebbiLeft); |
262 | 275 | } |
263 | 276 | } else if (kx > ww * 0.5) { |
264 | 277 | if (!send.right) { |
265 | 278 | sendCheck('right'); |
266 | | - mqtt(list.topic1, list.kebbiRight); |
| 279 | + mqttPush(list.topic1, list.kebbiRight); |
267 | 280 | } |
268 | 281 | } else { |
269 | 282 | if (ky < wh * 0.2) { |
270 | 283 | if (!send.top) { |
271 | 284 | sendCheck('top'); |
272 | | - mqtt(list.topic1, list.kebbiTop); |
| 285 | + mqttPush(list.topic1, list.kebbiTop); |
273 | 286 | } |
274 | 287 | } else if (ky > wh * 0.4) { |
275 | 288 | if (!send.bottom) { |
276 | 289 | sendCheck('bottom'); |
277 | | - mqtt(list.topic1, list.kebbiBottom); |
| 290 | + mqttPush(list.topic1, list.kebbiBottom); |
278 | 291 | } |
279 | 292 | } else { |
280 | 293 | if (!send.center) { |
281 | 294 | sendCheck('center'); |
282 | | - mqtt(list.topic1, list.kebbiReset); |
| 295 | + mqttPush(list.topic1, list.kebbiReset); |
283 | 296 | } |
284 | 297 | } |
285 | 298 | } |
|
303 | 316 | function reset() { |
304 | 317 | if (send.top || send.bottom || send.left || send.right) { |
305 | 318 | console.log('reset'); |
306 | | - mqtt(list.topic1, list.kebbiReset); |
| 319 | + mqttPush(list.topic1, list.kebbiReset); |
307 | 320 | } |
308 | 321 | sendCheck(); |
309 | 322 | drag = false; |
|
0 commit comments