From d983a96744f00b0a6776162f7748ae3ccbe09b5c Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 11 Aug 2015 18:49:36 -0400 Subject: [PATCH] sync (#80): new files --- src/css/cloud-ui.css | 87 +++++++++++++++++++ src/img/cloud.png | Bin 0 -> 5017 bytes src/js/cloud-ui.js | 199 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 src/css/cloud-ui.css create mode 100644 src/img/cloud.png create mode 100644 src/js/cloud-ui.js diff --git a/src/css/cloud-ui.css b/src/css/cloud-ui.css new file mode 100644 index 000000000..b6f941fca --- /dev/null +++ b/src/css/cloud-ui.css @@ -0,0 +1,87 @@ +#cloudWidget { + background: url("../img/cloud.png") hsl(216, 100%, 93%); + border-radius: 3px; + margin: 0.5em 0; + padding: 1em; + position: relative; + } +#cloudWidget.hide { + display: none; + } +#cloudWidget > button { + font-size: 160%; + padding: 0.1em 0.2em; + } +#cloudPull[disabled] { + visibility: hidden; + } +body[dir="ltr"] #cloudPush:after , +body[dir="ltr"] #cloudPull:before { + font-family: FontAwesome; + font-style: normal; + font-weight: normal; + line-height: 1; + vertical-align: baseline; + display: inline-block; + } +body[dir="ltr"] #cloudPush:after { + content: '\f0ee'; + } +body[dir="rtl"] #cloudPush:after { + content: '\f0ee'; + } +body[dir="ltr"] #cloudPull:before { + content: '\f0ed'; + } +body[dir="rtl"] #cloudPull:before { + content: '\f0ed'; + } +#cloudWidget > span { + color: gray; + display: inline-block; + font-size: 90%; + margin: 0 1em; + padding: 0; + vertical-align: bottom; + white-space: pre; + } +#cloudWidget > .nodata { + } +#cloudWidget > #cloudCog { + cursor: pointer; + display: inline-block; + font-size: 110%; + margin: 0; + opacity: 0.5; + padding: 4px; + position: absolute; + right: 0; + top: 0; + } +#cloudWidget > #cloudCog:hover { + opacity: 1; + } +#cloudWidget > #cloudOptions { + align-items: center; + -webkit-align-items: center; + background-color: rgba(0, 0, 0, 0.75); + bottom: 0; + display: none; + justify-content: center; + -webkit-justify-content: center; + left: 0; + position: fixed; + right: 0; + top: 0; + z-index: 2000; + } +#cloudWidget > #cloudOptions.show { + display: flex; + display: -webkit-flex; + } +#cloudWidget > #cloudOptions > div { + background-color: white; + border-radius: 3px; + padding: 1em; + text-align: center; + } diff --git a/src/img/cloud.png b/src/img/cloud.png new file mode 100644 index 0000000000000000000000000000000000000000..6c78dde2e027afd5108223aab236ea93e2e52ca7 GIT binary patch literal 5017 zcmV;K6K3p*P)$~8z;4QB@qI_4|zoV&&;-&egAshW)_cEd%Qj$ z{&@A`=j?acBbv|r{anSrtM58LKOXnBANTxy-1|QMzPsnuyjItHj>GTo*va)}??rQc zMvk8o*K>|t_3r?G)2*BJcz!)ztLN|EXZK^r_x>KM?_{pO&Fufj>o+m~-TGd|&ql1v zos69kHsON3ony1jY=3?Y=y`Md*DG3NMjF2-|Hm#C@DgwQ`Sb>etXag>J$A;w2#|VS z*G~R!ALFtMqnj?6YF_Oauje?N|7HOo1JDx$5CELxTg~_R{pULP`t`b!b&deQz*=0w z=4X#B=*7DJ^LL-eAX>4|&_vn*k-8nnM1*yKw2?3Xe+;@G6L13nEC^KB zcN%=flrm78>>7xbdGc=qK;R9qTQPQM_dh`*V^tNPc0jNmK+vt3o87oum(}<>$vPBf zmjc`8vG`YEl()3RipB3D1DK#*9E)>5?(;-{KfoXwBz_YBEOEK2$M5UkU>v(~w`QSb zzYF5;PQzE3-AW9-at{^>08s$v*8u?WV8HX5*e+Q^xi(0LV0e5XaXp#?~7fnA(Do^S#V0KEs{CjaTed7T`AXVV&@u zyTQt+m`cM|6A9=j;<;cM7hnOA)|&5QA3-i&^w}x^cw_h-1Mq`UoqEp_0KmxcMf!=6 z+K4iL6X89*rca~j8!?$i82%yz5ys~+0ZgJ%t{HZq3NeacSw%r^ggYk{YXf6;%L`4TTop-08b$#1e!oBitBo zcHv6j+Q+}o(69qrU>PT3mMpNcU?4p{muQc&0c`*R>}M({+{O5BcRwZciHs6~fDI;` zF%|{@v+-pCTnS~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SL%VJ7HF|t5P-o)nPs1ydN;pMWLpyEQ ztP3krxf#X~7eLSz-AvdWGI|$3kD>fu4GUmT0IC>YW$e3H>(8!KP8xr=j^hFZl=SnG zIeY}=+Qo_OUXg)xLQj_hIuW`8>>Ny5Gt&~vY?dg*p46ir+Bw-ZoCJcY=yw|a7XX1y z0PLzOPvbvXKsWDQC~^T80BKYP)*5@(Bh4~Df*6Nl`jx8Buz(;3n59>f;SZA+B1voOp`67UT1%TcB{<-t7#`R+XU|F9FFv$pH+%Fca(`d%W zW-W|RUwH-u*quR%wK7Q|)nKS}m_2xu0jta>-GWPCh7Wgf@V)|Y)z9aFFV%5h?C$?H z0D$xRb^#7w0sv(5%q9VK^Y6yx*C_L(^wsQE zLdpMD)ZnwaQH_S&3Zn)9qgn^q&c7O<=>)*9=BWTcSl)y3bn(^$3{L+)#0`pJt@eWQ zk2YOtqx~FIC~Mc{)}Q#pRBEA}Hk!|326>qlYn?RFU`s*KVyG1B(;u~j4WOO=b|Fmw z!xCkkX>;}*o3Bd%u)@eU(0abCKX)>Ki@OL-fZhE&R~4m68_>tXer854`;`aa_OqCV zRVS4)O|})%#IRO_g4xY8MjXb)u9vtQRPMuCZi~b+7vKv3!3hB8 zyr1i-^Z&mR;0;1V>^7)dR*Irctb2)4kDu#peIE3u%6JO`m8Smh1OU{5&Xiw9E$;67 z1^~J^`ELAHOLjGM@F(h0Yv6jq>awY?NH00000NkvXXu0mjfcl9xH literal 0 HcmV?d00001 diff --git a/src/js/cloud-ui.js b/src/js/cloud-ui.js new file mode 100644 index 000000000..9bca1fbcf --- /dev/null +++ b/src/js/cloud-ui.js @@ -0,0 +1,199 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 2015 Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +/* global uDom */ +'use strict'; + +/******************************************************************************/ + +(function() { + +/******************************************************************************/ + +self.cloud = { + options: {}, + datakey: '', + data: undefined, + onPush: null, + onPull: null +}; + +/******************************************************************************/ + +var widget = uDom.nodeFromId('cloudWidget'); +if ( widget === null ) { + return; +} + +self.cloud.datakey = widget.getAttribute('data-cloud-entry') || ''; +if ( self.cloud.datakey === '' ) { + return; +} + +/******************************************************************************/ + +var messager = vAPI.messaging.channel('cloud-ui.js'); + +/******************************************************************************/ + +var onCloudDataReceived = function(entry) { + if ( typeof entry !== 'object' || entry === null ) { + return; + } + + self.cloud.data = entry.data; + + uDom.nodeFromId('cloudPull').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 fetchCloudData = function() { + messager.send( + { + what: 'cloudPull', + datakey: self.cloud.datakey + }, + onCloudDataReceived + ); +}; + +/******************************************************************************/ + +var pushData = function() { + if ( typeof self.cloud.onPush !== 'function' ) { + return; + } + messager.send( + { + what: 'cloudPush', + datakey: self.cloud.datakey, + data: self.cloud.onPush() + }, + fetchCloudData + ); +}; + +/******************************************************************************/ + +var pullData = function() { + if ( typeof self.cloud.onPull === 'function' ) { + self.cloud.onPull(self.cloud.data); + } +}; + +/******************************************************************************/ + +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 closeOptions = function(ev) { + var root = uDom.nodeFromId('cloudOptions'); + if ( ev.target !== root ) { + return; + } + root.classList.remove('show'); +}; + +/******************************************************************************/ + +var submitOptions = function() { + var onOptions = function(options) { + if ( typeof options !== 'object' || options === null ) { + return; + } + self.cloud.options = options; + }; + + messager.send({ + 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; + + fetchCloudData(); + + var html = [ + '', + '', + '', + '', + '
', + '
', + '

', + '

', + '

', + '
', + ].join(''); + + vAPI.insertHTML(widget, html); + vAPI.i18n.render(widget); + widget.classList.remove('hide'); + + uDom('#cloudPush').on('click', pushData); + uDom('#cloudPull').on('click', pullData); + uDom('#cloudCog').on('click', openOptions); + uDom('#cloudOptions').on('click', closeOptions); + uDom('#cloudOptionsSubmit').on('click', submitOptions); +}; + +messager.send({ what: 'cloudGetOptions' }, onInitialize); + +/******************************************************************************/ + +})();