aboutsummaryrefslogtreecommitdiffstats
path: root/js/cloud-ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/cloud-ui.js')
-rw-r--r--js/cloud-ui.js298
1 files changed, 149 insertions, 149 deletions
diff --git a/js/cloud-ui.js b/js/cloud-ui.js
index 1afd9d1..0f81833 100644
--- a/js/cloud-ui.js
+++ b/js/cloud-ui.js
@@ -29,187 +29,187 @@
(function() {
-/******************************************************************************/
-
-self.cloud = {
- options: {},
- datakey: '',
- data: undefined,
- onPush: null,
- onPull: null
-};
-
-/******************************************************************************/
-
-var widget = uDom.nodeFromId('cloudWidget');
-if ( widget === null ) {
- return;
-}
+ /******************************************************************************/
+
+ self.cloud = {
+ options: {},
+ datakey: '',
+ data: undefined,
+ onPush: null,
+ onPull: null
+ };
-self.cloud.datakey = widget.getAttribute('data-cloud-entry') || '';
-if ( self.cloud.datakey === '' ) {
- return;
-}
+ /******************************************************************************/
-/******************************************************************************/
+ var widget = uDom.nodeFromId('cloudWidget');
+ if ( widget === null ) {
+ return;
+ }
-var onCloudDataReceived = function(entry) {
- if ( typeof entry !== 'object' || entry === null ) {
+ self.cloud.datakey = widget.getAttribute('data-cloud-entry') || '';
+ if ( self.cloud.datakey === '' ) {
return;
}
- self.cloud.data = entry.data;
+ /******************************************************************************/
- uDom.nodeFromId('cloudPull').removeAttribute('disabled');
- uDom.nodeFromId('cloudPullAndMerge').removeAttribute('disabled');
+ var onCloudDataReceived = function(entry) {
+ if ( typeof entry !== 'object' || entry === null ) {
+ return;
+ }
- var timeOptions = {
- weekday: 'short',
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- timeZoneName: 'short'
+ self.cloud.data = entry.data;
+
+ uDom.nodeFromId('cloudPull').removeAttribute('disabled');
+ uDom.nodeFromId('cloudPullAndMerge').removeAttribute('disabled');
+
+ var timeOptions = {
+ weekday: 'short',
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: 'numeric',
+ second: 'numeric',
+ timeZoneName: 'short'
+ };
+
+ var time = new Date(entry.tstamp);
+ widget.querySelector('span').textContent =
+ entry.source + '\n' +
+ time.toLocaleString('fullwide', timeOptions);
};
- var time = new Date(entry.tstamp);
- widget.querySelector('span').textContent =
- entry.source + '\n' +
- time.toLocaleString('fullwide', timeOptions);
-};
-
-/******************************************************************************/
-
-var fetchCloudData = function() {
- vAPI.messaging.send(
- 'cloud-ui.js',
- {
- what: 'cloudPull',
- datakey: self.cloud.datakey
- },
- onCloudDataReceived
- );
-};
-
-/******************************************************************************/
-
-var pushData = function() {
- if ( typeof self.cloud.onPush !== 'function' ) {
- return;
- }
- vAPI.messaging.send(
- 'cloud-ui.js',
- {
- what: 'cloudPush',
- datakey: self.cloud.datakey,
- data: self.cloud.onPush()
- },
- fetchCloudData
- );
-};
+ /******************************************************************************/
+
+ var fetchCloudData = function() {
+ vAPI.messaging.send(
+ 'cloud-ui.js',
+ {
+ what: 'cloudPull',
+ datakey: self.cloud.datakey
+ },
+ onCloudDataReceived
+ );
+ };
-/******************************************************************************/
+ /******************************************************************************/
-var pullData = function(ev) {
- if ( typeof self.cloud.onPull === 'function' ) {
- self.cloud.onPull(self.cloud.data, ev.shiftKey);
- }
-};
+ var pushData = function() {
+ if ( typeof self.cloud.onPush !== 'function' ) {
+ return;
+ }
+ vAPI.messaging.send(
+ 'cloud-ui.js',
+ {
+ what: 'cloudPush',
+ datakey: self.cloud.datakey,
+ data: self.cloud.onPush()
+ },
+ fetchCloudData
+ );
+ };
-/******************************************************************************/
+ /******************************************************************************/
-var pullAndMergeData = function() {
- if ( typeof self.cloud.onPull === 'function' ) {
- self.cloud.onPull(self.cloud.data, true);
- }
-};
+ var pullData = function(ev) {
+ if ( typeof self.cloud.onPull === 'function' ) {
+ self.cloud.onPull(self.cloud.data, ev.shiftKey);
+ }
+ };
-/******************************************************************************/
+ /******************************************************************************/
-var openOptions = function() {
- var input = uDom.nodeFromId('cloudDeviceName');
- input.value = self.cloud.options.deviceName;
- input.setAttribute('placeholder', self.cloud.options.defaultDeviceName);
- uDom.nodeFromId('cloudOptions').classList.add('show');
-};
+ var pullAndMergeData = function() {
+ if ( typeof self.cloud.onPull === 'function' ) {
+ self.cloud.onPull(self.cloud.data, true);
+ }
+ };
-/******************************************************************************/
+ /******************************************************************************/
-var closeOptions = function(ev) {
- var root = uDom.nodeFromId('cloudOptions');
- if ( ev.target !== root ) {
- return;
- }
- root.classList.remove('show');
-};
+ var openOptions = function() {
+ var input = uDom.nodeFromId('cloudDeviceName');
+ input.value = self.cloud.options.deviceName;
+ input.setAttribute('placeholder', self.cloud.options.defaultDeviceName);
+ uDom.nodeFromId('cloudOptions').classList.add('show');
+ };
-/******************************************************************************/
+ /******************************************************************************/
-var submitOptions = function() {
- var onOptions = function(options) {
- if ( typeof options !== 'object' || options === null ) {
+ var closeOptions = function(ev) {
+ var root = uDom.nodeFromId('cloudOptions');
+ if ( ev.target !== root ) {
return;
}
- self.cloud.options = options;
+ root.classList.remove('show');
};
- vAPI.messaging.send('cloud-ui.js', {
- what: 'cloudSetOptions',
- options: {
- deviceName: uDom.nodeFromId('cloudDeviceName').value
- }
- }, onOptions);
- uDom.nodeFromId('cloudOptions').classList.remove('show');
-};
-
-/******************************************************************************/
+ /******************************************************************************/
+
+ var submitOptions = function() {
+ var onOptions = function(options) {
+ if ( typeof options !== 'object' || options === null ) {
+ return;
+ }
+ self.cloud.options = options;
+ };
+
+ vAPI.messaging.send('cloud-ui.js', {
+ what: 'cloudSetOptions',
+ options: {
+ deviceName: uDom.nodeFromId('cloudDeviceName').value
+ }
+ }, onOptions);
+ uDom.nodeFromId('cloudOptions').classList.remove('show');
+ };
-var onInitialize = function(options) {
- if ( typeof options !== 'object' || options === null ) {
- return;
- }
+ /******************************************************************************/
- if ( !options.enabled ) {
- return;
- }
- self.cloud.options = options;
-
- var xhr = new XMLHttpRequest();
- xhr.open('GET', 'cloud-ui.html', true);
- xhr.overrideMimeType('text/html;charset=utf-8');
- xhr.responseType = 'text';
- xhr.onload = function() {
- this.onload = null;
- var parser = new DOMParser(),
- parsed = parser.parseFromString(this.responseText, 'text/html'),
- fromParent = parsed.body;
- while ( fromParent.firstElementChild !== null ) {
- widget.appendChild(
- document.adoptNode(fromParent.firstElementChild)
- );
+ var onInitialize = function(options) {
+ if ( typeof options !== 'object' || options === null ) {
+ return;
}
- vAPI.i18n.render(widget);
- widget.classList.remove('hide');
-
- uDom('#cloudPush').on('click', pushData);
- uDom('#cloudPull').on('click', pullData);
- uDom('#cloudPullAndMerge').on('click', pullAndMergeData);
- uDom('#cloudCog').on('click', openOptions);
- uDom('#cloudOptions').on('click', closeOptions);
- uDom('#cloudOptionsSubmit').on('click', submitOptions);
+ if ( !options.enabled ) {
+ return;
+ }
+ self.cloud.options = options;
- fetchCloudData();
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', 'cloud-ui.html', true);
+ xhr.overrideMimeType('text/html;charset=utf-8');
+ xhr.responseType = 'text';
+ xhr.onload = function() {
+ this.onload = null;
+ var parser = new DOMParser(),
+ parsed = parser.parseFromString(this.responseText, 'text/html'),
+ fromParent = parsed.body;
+ while ( fromParent.firstElementChild !== null ) {
+ widget.appendChild(
+ document.adoptNode(fromParent.firstElementChild)
+ );
+ }
+
+ vAPI.i18n.render(widget);
+ widget.classList.remove('hide');
+
+ uDom('#cloudPush').on('click', pushData);
+ uDom('#cloudPull').on('click', pullData);
+ uDom('#cloudPullAndMerge').on('click', pullAndMergeData);
+ uDom('#cloudCog').on('click', openOptions);
+ uDom('#cloudOptions').on('click', closeOptions);
+ uDom('#cloudOptionsSubmit').on('click', submitOptions);
+
+ fetchCloudData();
+ };
+ xhr.send();
};
- xhr.send();
-};
-vAPI.messaging.send('cloud-ui.js', { what: 'cloudGetOptions' }, onInitialize);
+ vAPI.messaging.send('cloud-ui.js', { what: 'cloudGetOptions' }, onInitialize);
-/******************************************************************************/
+ /******************************************************************************/
-// https://www.youtube.com/watch?v=aQFp67VoiDA
+ // https://www.youtube.com/watch?v=aQFp67VoiDA
})();