Skip to content
This repository
Browse code

Merge branch 'develop' of git://github.com/mozilla/openwebapps into d…

…evelop
  • Loading branch information...
commit 7c42242a558012fca7c9bcc2ae8b401d495189ed 2 parents 4333598 + 0f0310c
David Clarke dclarke authored
3  site/index.html
@@ -24,7 +24,8 @@
24 24 <div id="dashboard">
25 25 <p class="msg">Click to launch:</p>
26 26 <div id="apps" class="dashboardclipper well" style="width:800px; height:500px;">
27   - <div id="help">You have no apps installed. Apps are available <a href="https://apps-preview.mozilla.org/en-US/apps/" target="_blank">here</a>.
  27 + <div id="help">You have no apps installed. Apps are available
  28 + <a href="https://marketplace.mozilla.org/" target="_blank">in the Marketplace</a>.
28 29 </div>
29 30 </div>
30 31 </div>
18 site/js/jibe.js
@@ -137,9 +137,9 @@ $(document).ready(function() {
137 137 function eventUninstall(ev) {
138 138 doUpdate("uninstall", [ev.application]);
139 139 }
140   - if (navigator.mozApps.mgmt.addEventListener) {
141   - navigator.mozApps.mgmt.addEventListener('install', eventInstall);
142   - navigator.mozApps.mgmt.addEventListener('uninstall', eventUninstall);
  140 + if (navigator.mozApps.getInstalled) {
  141 + navigator.mozApps.mgmt.oninstall = eventInstall;
  142 + navigator.mozApps.mgmt.onuninstall = eventUninstall;
143 143 eventListenerBound = true;
144 144 }
145 145
@@ -149,17 +149,9 @@ $(document).ready(function() {
149 149 navigator.mozApps.mgmt.clearWatch(watcherID);
150 150 }
151 151 if (eventListenerBound) {
152   - navigator.mozApps.mgmt.removeEventListener('install', eventInstall);
153   - navigator.mozApps.mgmt.removeEventListener('uninstall', eventUninstall);
  152 + navigator.mozApps.mgmt.oninstall = null;
  153 + navigator.mozApps.mgmt.onuninstall = null;
154 154 }
155 155 });
156 156
157   - if (navigator.mozApps.mgmt.syncButton) {
158   - var syncButton = navigator.mozApps.mgmt.syncButton();
159   - syncButton.appendTo('login');
160   - $(document).click(function () {
161   - syncButton.makeCompact();
162   - });
163   - }
164   -
165 157 });
2  site/jsapi/include.html
@@ -290,8 +290,6 @@
290 290 <script src="repo.js"></script>
291 291
292 292 <script src="trusted.js"></script>
293   -<script src="sync/sync.js"></script>
294   -<script src="syncbuttonbridge.js"></script>
295 293
296 294 </body>
297 295 </html>
79 site/jsapi/include.js
@@ -703,7 +703,7 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
703 703 if (this.manifest.launch_path) {
704 704 url += this.manifest.launch_path;
705 705 }
706   - var name = ("openwebapp_" + id).replace(/[.:]/g, "_").replace(/[^a-zA-Z0-9_]/g, "");
  706 + var name = ("openwebapp_" + url).replace(/[.:]/g, "_").replace(/[^a-zA-Z0-9_]/g, "");
707 707 window.open(url, name);
708 708 };
709 709
@@ -1016,80 +1016,6 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
1016 1016 function callRegisterHandler(activity, message, func) {
1017 1017 }
1018 1018
1019   - function callSyncButton(options) {
1020   - return new SyncButton(options);
1021   - }
1022   -
1023   - function SyncButton(options) {
1024   - options = options || {};
1025   - setupWindow();
1026   - var iframe = document.createElement('iframe');
1027   - iframe.style.height = '22px';
1028   - iframe.style.width = '150px';
1029   - iframe.scrolling = "no";
1030   - iframe.setAttribute('frameborder', '0');
1031   - iframe.setAttribute('marginwidth', '0');
1032   - iframe.setAttribute('marginheight', '0');
1033   - iframe.setAttribute('id', 'syncbutton-frame');
1034   - var url = AppRepositoryOrigin + "/jsapi/syncbutton.html";
1035   - var params = [];
1036   - if (options.buttonColor) {
1037   - params.push('buttonColor=' + encodeURIComponent(options.buttonColor));
1038   - }
1039   - if (options.backgroundColor) {
1040   - params.push('backgroundColor=' + encodeURIComponent(options.backgroundColor));
1041   - }
1042   - if (options.foregroundColor) {
1043   - params.push('foregroundColor=' + encodeURIComponent(options.foregroundColor));
1044   - }
1045   - if (params.length) {
1046   - url += '#';
1047   - for (var i=0; i<params.length; i++) {
1048   - if (i) {
1049   - url += '&';
1050   - }
1051   - url += params[i];
1052   - }
1053   - }
1054   - iframe.src = url;
1055   - this.iframe = iframe;
1056   - iframe.addEventListener('load', function () {
1057   - window.addEventListener("message", function (event) {
1058   - if (event.origin != AppRepositoryOrigin) {
1059   - // FIXME: signal an error?
1060   - return;
1061   - }
1062   - var message = JSON.parse(event.data);
1063   - if (message.size == 'expanded') {
1064   - iframe.style.height = '150px';
1065   - } else if (message.size == 'compact') {
1066   - iframe.style.height = '22px';
1067   - }
1068   - }, false);
1069   - iframe.contentWindow.postMessage('hello', AppRepositoryOrigin);
1070   - }, false);
1071   - };
1072   -
1073   - SyncButton.prototype.makeCompact = function () {
1074   - if (this.iframe.style.height == '22px') {
1075   - return;
1076   - }
1077   - this.iframe.contentWindow.postMessage(JSON.stringify({size: "compact"}), AppRepositoryOrigin);
1078   - this.iframe.style.height = '22px';
1079   - };
1080   -
1081   - SyncButton.prototype.appendTo = function (elOrId) {
1082   - if (typeof elOrId == 'string') {
1083   - var el = document.getElementById(elOrId);
1084   - } else {
1085   - var el = elOrId;
1086   - }
1087   - if (! el) {
1088   - throw 'No element found ' + elOrId;
1089   - }
1090   - el.appendChild(this.iframe);
1091   - };
1092   -
1093 1019 // Return AppClient object with exposed API calls
1094 1020 var api = {
1095 1021 install: callInstall,
@@ -1109,8 +1035,7 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
1109 1035 addEventListener: callAddEventListener,
1110 1036 removeEventListener: callRemoveEventListener,
1111 1037 oninstall: null,
1112   - onuninstall: null,
1113   - syncButton: callSyncButton
  1038 + onuninstall: null
1114 1039 };
1115 1040 }
1116 1041
1  site/jsapi/sync
49 site/jsapi/syncbutton.html
... ... @@ -1,49 +0,0 @@
1   -<!DOCTYPE html>
2   -<html>
3   -<head>
4   -<title>Sync Button</title>
5   -<style type="text/css" media="screen">
6   -body {
7   - font-family: Helvetica, sans-serif;
8   - margin: 0;
9   - padding: 0;
10   -}
11   -/* The .with-status class is set on the sync button (syncbutton-expanded/compact) when
12   - there is some status from the sync service (typically an error) */
13   -.with-status a {
14   - color: #f00;
15   -}
16   -a:link, a:visited {
17   - text-decoration: none;
18   - color: #00f;
19   -}
20   -a:hover {
21   - text-decoration: underline;
22   -}
23   -#syncbutton-compacter, #syncbutton-expander {
24   - color: #000;
25   - text-decoration: none;
26   -}
27   -
28   -</style>
29   -</head>
30   -<body>
31   -
32   -<div id="syncbutton-login"><a id="login" href="#"><img id="login-image" src="https://browserid.org/i/sign_in_blue.png"></a></div>
33   -
34   -<div id="syncbutton-compact" style="display: none"><a id="syncbutton-expander" href="#" title="" style="width: 140px">sync &#9656;<!-- FIXME: should be image --></a></div>
35   -
36   -<div id="syncbutton-expanded" style="display: none">
37   - <a id="syncbutton-compacter" href="#" title="" style="width: 140px">sync &#9662;<!-- FIXME: should be image or header --></a><br>
38   - <span id="username"></span><br>
39   - <a href="#" id="sync-now">sync now</a><br>
40   - <a href="#" id="logout">logout</a><br>
41   - <span id="status-updated"></span>
42   - <span id="status"></span><br>
43   -</div>
44   -
45   -<script src="syncbutton.js"></script>
46   -<script src="https://browserid.org/include.js"></script>
47   -
48   -</body>
49   -</html>
257 site/jsapi/syncbutton.js
... ... @@ -1,257 +0,0 @@
1   -var gContainerSource = null;
2   -var gCurrentUsername = null;
3   -var gUpdated = null;
4   -
5   -window.addEventListener('storage', function (event) {
6   - if (event.key !== 'syncbutton-comm') {
7   - return;
8   - }
9   - var value = JSON.parse(event.newValue);
10   - updateStatus(value);
11   -}, false);
12   -
13   -function updateStatus(value) {
14   - if (value.logout) {
15   - setUsername('');
16   - gCurrentUsername = null;
17   - setStatus('');
18   - makeLogout();
19   - }
20   - if (value.username && value.username != gCurrentUsername) {
21   - gCurrentUsername = value.username;
22   - setUsername(value.username);
23   - makeCompactLayout();
24   - var username = document.getElementById('username');
25   - username.innerHTML = value.username;
26   - }
27   - if (value.status) {
28   - setStatus(value.status);
29   - var statusMessage = document.getElementById('status');
30   - statusMessage.innerHTML = value.status;
31   - }
32   - if (value.last_sync_get || value.last_sync_put) {
33   - var date = new Date(value.last_sync_get || value.last_sync_put);
34   - // FIXME: format better:
35   - gUpdated = date;
36   - displayUpdated();
37   - document.getElementById('sync-now').innerHTML = 'sync now';
38   - }
39   -}
40   -
41   -function displayUpdated() {
42   - if (gUpdated === null) {
43   - return;
44   - }
45   - var seconds = (gUpdated - new Date()) / 1000;
46   - var disp;
47   - if (seconds > 60*60*24) {
48   - disp = parseInt(seconds / 60 / 60 / 24);
49   - if (disp == 1) {
50   - disp = 'yesterday';
51   - } else {
52   - disp = disp + ' days ago';
53   - }
54   - } else if (seconds > 60*60) {
55   - disp = parseInt(seconds / 60 / 60);
56   - if (disp == 1) {
57   - disp = '1 hour ago';
58   - } else {
59   - disp = disp + ' hours ago';
60   - }
61   - } else if (seconds > 60) {
62   - disp = parseInt(seconds / 60);
63   - if (disp == 1) {
64   - disp = '1 minute ago';
65   - } else {
66   - disp = disp + ' minutes ago';
67   - }
68   - } else {
69   - if (seconds > 10) {
70   - disp = seconds + ' seconds ago';
71   - } else {
72   - disp = 'just now';
73   - }
74   - }
75   - var statusUpdated = document.getElementById('status-updated');
76   - statusUpdated.innerHTML = 'synced ' + disp;
77   -}
78   -
79   -// We have to update this display periodically because it's a
80   -// relative, not absolute displayed time:
81   -setInterval(displayUpdated, 5*60*1000);
82   -
83   -function setUsername(username) {
84   - document.getElementById('syncbutton-expander').setAttribute('title', username);
85   - document.getElementById('username').innerHTML = username;
86   -}
87   -
88   -function setStatus(status) {
89   - var expander = document.getElementById('syncbutton-expander');
90   - if (status) {
91   - expander.className = 'with-status';
92   - } else {
93   - expander.className = '';
94   - }
95   - document.getElementById('status').innerHTML = status;
96   -}
97   -
98   -window.addEventListener('load', function () {
99   - var prevValue = localStorage.getItem('syncbutton-comm');
100   - if (prevValue) {
101   - prevValue = JSON.parse(prevValue);
102   - updateStatus(prevValue);
103   - }
104   - var login = document.getElementById('login');
105   - login.addEventListener('click', function (ev) {
106   - ev.preventDefault();
107   - ev.stopPropagation();
108   - // FIXME: maybe switch to the grey icon?
109   - navigator.id.getVerifiedEmail(function (assertion) {
110   - if (! assertion) {
111   - // FIXME: report error
112   - return;
113   - }
114   - localStorage.setItem('syncbutton-assertion', assertion);
115   - });
116   - }, false);
117   - var logout = document.getElementById('logout');
118   - logout.addEventListener('click', function (ev) {
119   - ev.preventDefault();
120   - ev.stopPropagation();
121   - console.log('syncbutton.js logging out');
122   - // We have to swap back and forth to make sure we are going to generate a
123   - // storage message:
124   - if (localStorage.getItem('syncbutton-assertion') == 'logout1') {
125   - localStorage.setItem('syncbutton-assertion', 'logout2');
126   - } else {
127   - localStorage.setItem('syncbutton-assertion', 'logout1');
128   - }
129   - }, false);
130   - var expander = document.getElementById('syncbutton-expander');
131   - expander.addEventListener('click', function (ev) {
132   - ev.preventDefault();
133   - ev.stopPropagation();
134   - makeExpanded();
135   - }, false);
136   - var compacter = document.getElementById('syncbutton-compacter');
137   - compacter.addEventListener('click', function (ev) {
138   - ev.preventDefault();
139   - ev.stopPropagation();
140   - makeCompact();
141   - }, false);
142   - var syncNow = document.getElementById('sync-now');
143   - var syncCounter = 1;
144   - syncNow.addEventListener('click', function (ev) {
145   - ev.preventDefault();
146   - ev.stopPropagation();
147   - localStorage.setItem('syncbutton-syncnow', syncCounter++);
148   - syncNow.innerHTML = 'syncing...';
149   - }, false);
150   -}, false);
151   -
152   -function parseQueryString(s) {
153   - var params = {};
154   - s = s.split('&');
155   - for (var i=0; i<s.length; i++) {
156   - if (s[i].indexOf('=') == -1) {
157   - var name = decodeURIComponent(s[i]);
158   - var value = null;
159   - } else {
160   - var name = decodeURIComponent(s[i].substr(0, s[i].indexOf('=')));
161   - var value = decodeURIComponent(s[i].substr(s[i].indexOf('=')+1));
162   - }
163   - if (name in params) {
164   - if (params[name] === null || typeof params[name] == 'string') {
165   - params[name] = [params[name], value];
166   - } else {
167   - params[name].push(value);
168   - }
169   - } else {
170   - params[name] = value;
171   - }
172   - }
173   - return params;
174   -}
175   -
176   -var iconsByColor = {
177   - red: 'https://browserid.org/i/sign_in_red.png',
178   - blue: 'https://browserid.org/i/sign_in_blue.png',
179   - orange: 'https://browserid.org/i/sign_in_orange.png',
180   - green: 'https://browserid.org/i/sign_in_green.png',
181   - grey: 'https://browserid.org/i/sign_in_grey.png'
182   -};
183   -
184   -function getLoginIcon(color) {
185   - color = (color || '').toLowerCase();
186   - return iconsByColor[color] || iconsByColor['blue'];
187   -}
188   -
189   -var params = {};
190   -if (location.hash) {
191   - params = parseQueryString(location.hash.substr(1));
192   -}
193   -
194   -if (params.buttonColor) {
195   - // FIXME: technically this element might not be available at this time:
196   - document.getElementById('login-image').src = getLoginIcon(params.buttonColor);
197   -}
198   -
199   -if (params.foregroundColor) {
200   - document.body.style.color = params.foregroundColor;
201   -}
202   -
203   -if (params.backgroundColor) {
204   - // FIXME: check that it's a color, not url(javascript:) or something
205   - document.body.style.backgroundColor = params.backgroundColor;
206   -}
207   -
208   -window.addEventListener("message", function (event) {
209   - var message = event.data;
210   - if (message == "hello") {
211   - gContainerSource = event.source;
212   - return;
213   - }
214   - message = JSON.parse(message);
215   - if (message.size == "compact") {
216   - makeCompactLayout();
217   - }
218   -}, false);
219   -
220   -function makeCompact() {
221   - sendSize('compact');
222   - makeCompactLayout();
223   -}
224   -
225   -function makeCompactLayout() {
226   - document.getElementById('syncbutton-expanded').style.display = 'none';
227   - document.getElementById('syncbutton-compact').style.display = '';
228   - document.getElementById('syncbutton-login').style.display = 'none';
229   -}
230   -
231   -function makeExpanded() {
232   - sendSize('expanded');
233   - makeExpandedLayout();
234   -}
235   -
236   -function makeExpandedLayout() {
237   - document.getElementById('syncbutton-expanded').style.display = '';
238   - document.getElementById('syncbutton-compact').style.display = 'none';
239   - document.getElementById('syncbutton-login').style.display = 'none';
240   -}
241   -
242   -function makeLogout() {
243   - sendSize('compact');
244   - makeLogoutLayout();
245   -}
246   -
247   -function makeLogoutLayout() {
248   - document.getElementById('syncbutton-expanded').style.display = 'none';
249   - document.getElementById('syncbutton-compact').style.display = 'none';
250   - document.getElementById('syncbutton-login').style.display = '';
251   -}
252   -
253   -function sendSize(size) {
254   - if (gContainerSource) {
255   - gContainerSource.postMessage(JSON.stringify({size: size}), '*');
256   - }
257   -}
137 site/jsapi/syncbuttonbridge.js
... ... @@ -1,137 +0,0 @@
1   -window.addEventListener('storage', function (event) {
2   - if (event.key == 'syncbutton-syncnow') {
3   - // Note we are doing forcePut, but this is all a hacky method anyway:
4   - console.warn('manual sync');
5   - syncNow(function (error, result) {console.log('synced', error, result);}, true);
6   - return;
7   - }
8   - if (event.key == 'syncbutton-deletenow') {
9   - console.warn('manual delete');
10   - sync.deleteCollection({reason: 'manual deletion'}, function (error) {console.log('did delete', error);});
11   - sync.reset(function () {console.log('did reset');});
12   - return;
13   - }
14   - if (event.key !== 'syncbutton-assertion') {
15   - return;
16   - }
17   - if (event.newValue == 'logout1' || event.newValue === 'logout2') {
18   - console.log('Logout out via bridge.js');
19   - sync.logout(function (error) {
20   - if (error) {
21   - // FIXME: how can this happen?
22   - // FIXME: could it mean that you were already logged out? Ideally no
23   - setButtonData({status: "Logout failed: " + error}, true);
24   - return;
25   - }
26   - localStorage.setItem('syncbutton-saved-authdata', null);
27   - setButtonData({logout: true}, false);
28   - });
29   - return;
30   - }
31   - var audience = getOrigin(location.href);
32   - var loginData = {assertion: event.newValue, audience: audience};
33   - login(loginData);
34   -}, false);
35   -
36   -function login(loginData) {
37   - sync.login(loginData, loginHandler);
38   -}
39   -
40   -function loginHandler(error, status) {
41   - if (error) {
42   - setButtonData({status: "Login failed: " + JSON.stringify(error)}, true);
43   - localStorage.setItem('syncbutton-saved-authdata', null);
44   - setButtonData({logout: true}, false);
45   - return;
46   - }
47   - localStorage.setItem('syncbutton-saved-authdata', JSON.stringify(sync.getAuthData()));
48   - setButtonData({logout: false, username: status.email, status: null}, false);
49   -}
50   -
51   -window.addEventListener('load', function () {
52   - var authData = localStorage.getItem('syncbutton-saved-authdata');
53   - if (authData) {
54   - authData = JSON.parse(authData);
55   - if (authData) {
56   - sync.setAuthData(authData, loginHandler);
57   - return;
58   - }
59   - }
60   - setButtonData({logout: true}, false);
61   -}, false);
62   -
63   -function syncNow(callback, forcePut) {
64   - sync.syncNow(function (error, result) {
65   - // FIXME: get better way to display error
66   - if (error && (! error.error == 'uuid_changed')) {
67   - sync.onstatus({error: true, detail: error});
68   - } else {
69   - setButtonData({lastUpdate: new Date().getTime()}, true);
70   - }
71   - callback(error, result);
72   - }, forcePut);
73   -}
74   -
75   -
76   -function setButtonData(data, merge) {
77   - if (merge) {
78   - var mergeData = data;
79   - data = localStorage.getItem('syncbutton-comm');
80   - if (data) {
81   - data = JSON.parse(data);
82   - } else {
83   - data = {};
84   - }
85   - for (var i in mergeData) {
86   - if (mergeData.hasOwnProperty(i)) {
87   - data[i] = mergeData[i];
88   - }
89   - }
90   - }
91   - localStorage.setItem('syncbutton-comm', JSON.stringify(data));
92   -}
93   -
94   -function getOrigin(url) {
95   - var protocol = url.substr(0, url.indexOf('//')).toLowerCase();
96   - var domain = url.substr(url.indexOf('//')+2);
97   - if (domain.indexOf('/') != -1) {
98   - domain = domain.substr(0, domain.indexOf('/'));
99   - }
100   - domain = domain.toLowerCase();
101   - if (protocol == 'http:' && domain.search(/:80$/) != -1) {
102   - domain = domain.replace(/:80$/, '');
103   - } else if (protocol == 'https:' && domain.search(/:443$/) != -1) {
104   - domain = domain.replace(/:443$/, '');
105   - }
106   - return protocol + '//' + domain;
107   -}
108   -
109   -var sync = new SyncService({
110   - repo: Repo,
111   - server: new Server('/verify')
112   -});
113   -
114   -sync.onstatus = function (status) {
115   - if (status.error) {
116   - if (status.detail.error != 'uuid_changed') {
117   - var message = status.detail.error;
118   - if (status.detail.message) {
119   - message = status.detail.message;
120   - } else if (status.detail.error == 'Non-200 response code') {
121   - message = 'server error';
122   - }
123   - setButtonData({status: "Error: " + message}, true);
124   - }
125   - } else if (status.status) {
126   - if (status.status == 'sync_get') {
127   - setButtonData({last_sync_get: status.timestamp}, true);
128   - } else if (status.status == 'sync_put_complete' || (status.status == 'sync_put' && status.count === 0)) {
129   - setButtonData({last_sync_put: status.timestamp}, true);
130   - }
131   - }
132   -};
133   -
134   -var scheduler = new Scheduler(sync);
135   -scheduler.onerror = function (error) {
136   - sync.onstatus({error: true, detail: error});
137   -};
2  site/tools/apps.mozillalabs.com
... ... @@ -1 +1 @@
1   -Subproject commit 08686c43e559c1ff6664d14bacd2a4e93fbaa990
  1 +Subproject commit b711b3018b2f6a841d67fbadbc40427a1ca887d2
4 site/tools/build_static
@@ -95,7 +95,3 @@ echo "Creating minified jsapi/include.js"
95 95 cp ${DEST}/jsapi/include.js ${DEST}/jsapi/include.complete.js
96 96 echo "/* For unminified source see ${HOST}/jsapi/include.complete.js */" > ${DEST}/jsapi/include.js
97 97 java -jar ${COMP_DIR}/yuicompressor-2.4.2.jar ${DEST}/jsapi/include.complete.js >> ${DEST}/jsapi/include.js
98   -
99   -echo "Creating minified jsapi/syncbutton.html"
100   -cp ${DEST}/jsapi/syncbutton.html ${DEST}/jsapi/syncbutton.complete.html
101   -${SITE}/tools/compress_html.py ${DEST}/jsapi/syncbutton.html -o ${DEST}/jsapi/syncbutton.html --compress --compressor-dir "$COMP_DIR" --comment "The original (unminified) source is at ${HOST}/jsapi/syncbutton.complete.html"

0 comments on commit 7c42242

Please sign in to comment.
Something went wrong with that request. Please try again.