iv123 lin
/
connected-lights
sample_pir-lights_rgb
webapp/public/helper-functions.js@0:7a352727249b, 2017-06-18 (annotated)
- Committer:
- iv123
- Date:
- Sun Jun 18 10:14:56 2017 +0000
- Revision:
- 0:7a352727249b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iv123 | 0:7a352727249b | 1 | function getElement(endpoint) { |
iv123 | 0:7a352727249b | 2 | return document.querySelector('li[data-endpoint="' + endpoint + '"]'); |
iv123 | 0:7a352727249b | 3 | } |
iv123 | 0:7a352727249b | 4 | |
iv123 | 0:7a352727249b | 5 | function updateStatusUi(endpoint, status) { |
iv123 | 0:7a352727249b | 6 | var statusEl = getElement(endpoint).querySelector('.status'); |
iv123 | 0:7a352727249b | 7 | [].forEach.call(statusEl.children, function(el) { |
iv123 | 0:7a352727249b | 8 | el.classList.remove('selected'); |
iv123 | 0:7a352727249b | 9 | }); |
iv123 | 0:7a352727249b | 10 | statusEl.querySelector('*[data-action="' + status + '"]').classList.add('selected'); |
iv123 | 0:7a352727249b | 11 | } |
iv123 | 0:7a352727249b | 12 | |
iv123 | 0:7a352727249b | 13 | function getDeviceName(endpoint, trim) { |
iv123 | 0:7a352727249b | 14 | var name = localStorage.getItem(endpoint + '-name') || endpoint; |
iv123 | 0:7a352727249b | 15 | if (trim && name.length > 20) name = name.substr(0, 20) + '...'; |
iv123 | 0:7a352727249b | 16 | return name; |
iv123 | 0:7a352727249b | 17 | } |
iv123 | 0:7a352727249b | 18 | |
iv123 | 0:7a352727249b | 19 | var notificationTo; |
iv123 | 0:7a352727249b | 20 | function showNotification(msg) { |
iv123 | 0:7a352727249b | 21 | clearTimeout(notificationTo); |
iv123 | 0:7a352727249b | 22 | |
iv123 | 0:7a352727249b | 23 | var el = document.querySelector('#notification'); |
iv123 | 0:7a352727249b | 24 | el.textContent = msg; |
iv123 | 0:7a352727249b | 25 | el.style.opacity = 1; |
iv123 | 0:7a352727249b | 26 | el.style.visibility = 'visible'; |
iv123 | 0:7a352727249b | 27 | |
iv123 | 0:7a352727249b | 28 | notificationTo = setTimeout(function() { |
iv123 | 0:7a352727249b | 29 | el.style.opacity = 0; |
iv123 | 0:7a352727249b | 30 | el.style.visibility = 'hidden'; |
iv123 | 0:7a352727249b | 31 | }, 6000); |
iv123 | 0:7a352727249b | 32 | |
iv123 | 0:7a352727249b | 33 | el.onclick = function() { |
iv123 | 0:7a352727249b | 34 | clearTimeout(notificationTo); |
iv123 | 0:7a352727249b | 35 | el.style.opacity = 0; |
iv123 | 0:7a352727249b | 36 | el.style.visibility = 'hidden'; |
iv123 | 0:7a352727249b | 37 | }; |
iv123 | 0:7a352727249b | 38 | } |