Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -24,7 +24,8 @@
<div id="dashboard">
<p class="msg">Click to launch:</p>
<div id="apps" class="dashboardclipper well" style="width:800px; height:500px;">
- <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>.
+ <div id="help">You have no apps installed. Apps are available
+ <a href="https://marketplace.mozilla.org/" target="_blank">in the Marketplace</a>.
</div>
</div>
</div>
18 site/js/jibe.js
View
@@ -137,9 +137,9 @@ $(document).ready(function() {
function eventUninstall(ev) {
doUpdate("uninstall", [ev.application]);
}
- if (navigator.mozApps.mgmt.addEventListener) {
- navigator.mozApps.mgmt.addEventListener('install', eventInstall);
- navigator.mozApps.mgmt.addEventListener('uninstall', eventUninstall);
+ if (navigator.mozApps.getInstalled) {
+ navigator.mozApps.mgmt.oninstall = eventInstall;
+ navigator.mozApps.mgmt.onuninstall = eventUninstall;
eventListenerBound = true;
}
@@ -149,17 +149,9 @@ $(document).ready(function() {
navigator.mozApps.mgmt.clearWatch(watcherID);
}
if (eventListenerBound) {
- navigator.mozApps.mgmt.removeEventListener('install', eventInstall);
- navigator.mozApps.mgmt.removeEventListener('uninstall', eventUninstall);
+ navigator.mozApps.mgmt.oninstall = null;
+ navigator.mozApps.mgmt.onuninstall = null;
}
});
- if (navigator.mozApps.mgmt.syncButton) {
- var syncButton = navigator.mozApps.mgmt.syncButton();
- syncButton.appendTo('login');
- $(document).click(function () {
- syncButton.makeCompact();
- });
- }
-
});
2  site/jsapi/include.html
View
@@ -290,8 +290,6 @@
<script src="repo.js"></script>
<script src="trusted.js"></script>
-<script src="sync/sync.js"></script>
-<script src="syncbuttonbridge.js"></script>
</body>
</html>
79 site/jsapi/include.js
View
@@ -703,7 +703,7 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
if (this.manifest.launch_path) {
url += this.manifest.launch_path;
}
- var name = ("openwebapp_" + id).replace(/[.:]/g, "_").replace(/[^a-zA-Z0-9_]/g, "");
+ var name = ("openwebapp_" + url).replace(/[.:]/g, "_").replace(/[^a-zA-Z0-9_]/g, "");
window.open(url, name);
};
@@ -1016,80 +1016,6 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
function callRegisterHandler(activity, message, func) {
}
- function callSyncButton(options) {
- return new SyncButton(options);
- }
-
- function SyncButton(options) {
- options = options || {};
- setupWindow();
- var iframe = document.createElement('iframe');
- iframe.style.height = '22px';
- iframe.style.width = '150px';
- iframe.scrolling = "no";
- iframe.setAttribute('frameborder', '0');
- iframe.setAttribute('marginwidth', '0');
- iframe.setAttribute('marginheight', '0');
- iframe.setAttribute('id', 'syncbutton-frame');
- var url = AppRepositoryOrigin + "/jsapi/syncbutton.html";
- var params = [];
- if (options.buttonColor) {
- params.push('buttonColor=' + encodeURIComponent(options.buttonColor));
- }
- if (options.backgroundColor) {
- params.push('backgroundColor=' + encodeURIComponent(options.backgroundColor));
- }
- if (options.foregroundColor) {
- params.push('foregroundColor=' + encodeURIComponent(options.foregroundColor));
- }
- if (params.length) {
- url += '#';
- for (var i=0; i<params.length; i++) {
- if (i) {
- url += '&';
- }
- url += params[i];
- }
- }
- iframe.src = url;
- this.iframe = iframe;
- iframe.addEventListener('load', function () {
- window.addEventListener("message", function (event) {
- if (event.origin != AppRepositoryOrigin) {
- // FIXME: signal an error?
- return;
- }
- var message = JSON.parse(event.data);
- if (message.size == 'expanded') {
- iframe.style.height = '150px';
- } else if (message.size == 'compact') {
- iframe.style.height = '22px';
- }
- }, false);
- iframe.contentWindow.postMessage('hello', AppRepositoryOrigin);
- }, false);
- };
-
- SyncButton.prototype.makeCompact = function () {
- if (this.iframe.style.height == '22px') {
- return;
- }
- this.iframe.contentWindow.postMessage(JSON.stringify({size: "compact"}), AppRepositoryOrigin);
- this.iframe.style.height = '22px';
- };
-
- SyncButton.prototype.appendTo = function (elOrId) {
- if (typeof elOrId == 'string') {
- var el = document.getElementById(elOrId);
- } else {
- var el = elOrId;
- }
- if (! el) {
- throw 'No element found ' + elOrId;
- }
- el.appendChild(this.iframe);
- };
-
// Return AppClient object with exposed API calls
var api = {
install: callInstall,
@@ -1109,8 +1035,7 @@ if (!navigator.mozApps.install || navigator.mozApps.html5Implementation) {
addEventListener: callAddEventListener,
removeEventListener: callRemoveEventListener,
oninstall: null,
- onuninstall: null,
- syncButton: callSyncButton
+ onuninstall: null
};
}
1  site/jsapi/sync
View
49 site/jsapi/syncbutton.html
View
@@ -1,49 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Sync Button</title>
-<style type="text/css" media="screen">
-body {
- font-family: Helvetica, sans-serif;
- margin: 0;
- padding: 0;
-}
-/* The .with-status class is set on the sync button (syncbutton-expanded/compact) when
- there is some status from the sync service (typically an error) */
-.with-status a {
- color: #f00;
-}
-a:link, a:visited {
- text-decoration: none;
- color: #00f;
-}
-a:hover {
- text-decoration: underline;
-}
-#syncbutton-compacter, #syncbutton-expander {
- color: #000;
- text-decoration: none;
-}
-
-</style>
-</head>
-<body>
-
-<div id="syncbutton-login"><a id="login" href="#"><img id="login-image" src="https://browserid.org/i/sign_in_blue.png"></a></div>
-
-<div id="syncbutton-compact" style="display: none"><a id="syncbutton-expander" href="#" title="" style="width: 140px">sync &#9656;<!-- FIXME: should be image --></a></div>
-
-<div id="syncbutton-expanded" style="display: none">
- <a id="syncbutton-compacter" href="#" title="" style="width: 140px">sync &#9662;<!-- FIXME: should be image or header --></a><br>
- <span id="username"></span><br>
- <a href="#" id="sync-now">sync now</a><br>
- <a href="#" id="logout">logout</a><br>
- <span id="status-updated"></span>
- <span id="status"></span><br>
-</div>
-
-<script src="syncbutton.js"></script>
-<script src="https://browserid.org/include.js"></script>
-
-</body>
-</html>
257 site/jsapi/syncbutton.js
View
@@ -1,257 +0,0 @@
-var gContainerSource = null;
-var gCurrentUsername = null;
-var gUpdated = null;
-
-window.addEventListener('storage', function (event) {
- if (event.key !== 'syncbutton-comm') {
- return;
- }
- var value = JSON.parse(event.newValue);
- updateStatus(value);
-}, false);
-
-function updateStatus(value) {
- if (value.logout) {
- setUsername('');
- gCurrentUsername = null;
- setStatus('');
- makeLogout();
- }
- if (value.username && value.username != gCurrentUsername) {
- gCurrentUsername = value.username;
- setUsername(value.username);
- makeCompactLayout();
- var username = document.getElementById('username');
- username.innerHTML = value.username;
- }
- if (value.status) {
- setStatus(value.status);
- var statusMessage = document.getElementById('status');
- statusMessage.innerHTML = value.status;
- }
- if (value.last_sync_get || value.last_sync_put) {
- var date = new Date(value.last_sync_get || value.last_sync_put);
- // FIXME: format better:
- gUpdated = date;
- displayUpdated();
- document.getElementById('sync-now').innerHTML = 'sync now';
- }
-}
-
-function displayUpdated() {
- if (gUpdated === null) {
- return;
- }
- var seconds = (gUpdated - new Date()) / 1000;
- var disp;
- if (seconds > 60*60*24) {
- disp = parseInt(seconds / 60 / 60 / 24);
- if (disp == 1) {
- disp = 'yesterday';
- } else {
- disp = disp + ' days ago';
- }
- } else if (seconds > 60*60) {
- disp = parseInt(seconds / 60 / 60);
- if (disp == 1) {
- disp = '1 hour ago';
- } else {
- disp = disp + ' hours ago';
- }
- } else if (seconds > 60) {
- disp = parseInt(seconds / 60);
- if (disp == 1) {
- disp = '1 minute ago';
- } else {
- disp = disp + ' minutes ago';
- }
- } else {
- if (seconds > 10) {
- disp = seconds + ' seconds ago';
- } else {
- disp = 'just now';
- }
- }
- var statusUpdated = document.getElementById('status-updated');
- statusUpdated.innerHTML = 'synced ' + disp;
-}
-
-// We have to update this display periodically because it's a
-// relative, not absolute displayed time:
-setInterval(displayUpdated, 5*60*1000);
-
-function setUsername(username) {
- document.getElementById('syncbutton-expander').setAttribute('title', username);
- document.getElementById('username').innerHTML = username;
-}
-
-function setStatus(status) {
- var expander = document.getElementById('syncbutton-expander');
- if (status) {
- expander.className = 'with-status';
- } else {
- expander.className = '';
- }
- document.getElementById('status').innerHTML = status;
-}
-
-window.addEventListener('load', function () {
- var prevValue = localStorage.getItem('syncbutton-comm');
- if (prevValue) {
- prevValue = JSON.parse(prevValue);
- updateStatus(prevValue);
- }
- var login = document.getElementById('login');
- login.addEventListener('click', function (ev) {
- ev.preventDefault();
- ev.stopPropagation();
- // FIXME: maybe switch to the grey icon?
- navigator.id.getVerifiedEmail(function (assertion) {
- if (! assertion) {
- // FIXME: report error
- return;
- }
- localStorage.setItem('syncbutton-assertion', assertion);
- });
- }, false);
- var logout = document.getElementById('logout');
- logout.addEventListener('click', function (ev) {
- ev.preventDefault();
- ev.stopPropagation();
- console.log('syncbutton.js logging out');
- // We have to swap back and forth to make sure we are going to generate a
- // storage message:
- if (localStorage.getItem('syncbutton-assertion') == 'logout1') {
- localStorage.setItem('syncbutton-assertion', 'logout2');
- } else {
- localStorage.setItem('syncbutton-assertion', 'logout1');
- }
- }, false);
- var expander = document.getElementById('syncbutton-expander');
- expander.addEventListener('click', function (ev) {
- ev.preventDefault();
- ev.stopPropagation();
- makeExpanded();
- }, false);
- var compacter = document.getElementById('syncbutton-compacter');
- compacter.addEventListener('click', function (ev) {
- ev.preventDefault();
- ev.stopPropagation();
- makeCompact();
- }, false);
- var syncNow = document.getElementById('sync-now');
- var syncCounter = 1;
- syncNow.addEventListener('click', function (ev) {
- ev.preventDefault();
- ev.stopPropagation();
- localStorage.setItem('syncbutton-syncnow', syncCounter++);
- syncNow.innerHTML = 'syncing...';
- }, false);
-}, false);
-
-function parseQueryString(s) {
- var params = {};
- s = s.split('&');
- for (var i=0; i<s.length; i++) {
- if (s[i].indexOf('=') == -1) {
- var name = decodeURIComponent(s[i]);
- var value = null;
- } else {
- var name = decodeURIComponent(s[i].substr(0, s[i].indexOf('=')));
- var value = decodeURIComponent(s[i].substr(s[i].indexOf('=')+1));
- }
- if (name in params) {
- if (params[name] === null || typeof params[name] == 'string') {
- params[name] = [params[name], value];
- } else {
- params[name].push(value);
- }
- } else {
- params[name] = value;
- }
- }
- return params;
-}
-
-var iconsByColor = {
- red: 'https://browserid.org/i/sign_in_red.png',
- blue: 'https://browserid.org/i/sign_in_blue.png',
- orange: 'https://browserid.org/i/sign_in_orange.png',
- green: 'https://browserid.org/i/sign_in_green.png',
- grey: 'https://browserid.org/i/sign_in_grey.png'
-};
-
-function getLoginIcon(color) {
- color = (color || '').toLowerCase();
- return iconsByColor[color] || iconsByColor['blue'];
-}
-
-var params = {};
-if (location.hash) {
- params = parseQueryString(location.hash.substr(1));
-}
-
-if (params.buttonColor) {
- // FIXME: technically this element might not be available at this time:
- document.getElementById('login-image').src = getLoginIcon(params.buttonColor);
-}
-
-if (params.foregroundColor) {
- document.body.style.color = params.foregroundColor;
-}
-
-if (params.backgroundColor) {
- // FIXME: check that it's a color, not url(javascript:) or something
- document.body.style.backgroundColor = params.backgroundColor;
-}
-
-window.addEventListener("message", function (event) {
- var message = event.data;
- if (message == "hello") {
- gContainerSource = event.source;
- return;
- }
- message = JSON.parse(message);
- if (message.size == "compact") {
- makeCompactLayout();
- }
-}, false);
-
-function makeCompact() {
- sendSize('compact');
- makeCompactLayout();
-}
-
-function makeCompactLayout() {
- document.getElementById('syncbutton-expanded').style.display = 'none';
- document.getElementById('syncbutton-compact').style.display = '';
- document.getElementById('syncbutton-login').style.display = 'none';
-}
-
-function makeExpanded() {
- sendSize('expanded');
- makeExpandedLayout();
-}
-
-function makeExpandedLayout() {
- document.getElementById('syncbutton-expanded').style.display = '';
- document.getElementById('syncbutton-compact').style.display = 'none';
- document.getElementById('syncbutton-login').style.display = 'none';
-}
-
-function makeLogout() {
- sendSize('compact');
- makeLogoutLayout();
-}
-
-function makeLogoutLayout() {
- document.getElementById('syncbutton-expanded').style.display = 'none';
- document.getElementById('syncbutton-compact').style.display = 'none';
- document.getElementById('syncbutton-login').style.display = '';
-}
-
-function sendSize(size) {
- if (gContainerSource) {
- gContainerSource.postMessage(JSON.stringify({size: size}), '*');
- }
-}
137 site/jsapi/syncbuttonbridge.js
View
@@ -1,137 +0,0 @@
-window.addEventListener('storage', function (event) {
- if (event.key == 'syncbutton-syncnow') {
- // Note we are doing forcePut, but this is all a hacky method anyway:
- console.warn('manual sync');
- syncNow(function (error, result) {console.log('synced', error, result);}, true);
- return;
- }
- if (event.key == 'syncbutton-deletenow') {
- console.warn('manual delete');
- sync.deleteCollection({reason: 'manual deletion'}, function (error) {console.log('did delete', error);});
- sync.reset(function () {console.log('did reset');});
- return;
- }
- if (event.key !== 'syncbutton-assertion') {
- return;
- }
- if (event.newValue == 'logout1' || event.newValue === 'logout2') {
- console.log('Logout out via bridge.js');
- sync.logout(function (error) {
- if (error) {
- // FIXME: how can this happen?
- // FIXME: could it mean that you were already logged out? Ideally no
- setButtonData({status: "Logout failed: " + error}, true);
- return;
- }
- localStorage.setItem('syncbutton-saved-authdata', null);
- setButtonData({logout: true}, false);
- });
- return;
- }
- var audience = getOrigin(location.href);
- var loginData = {assertion: event.newValue, audience: audience};
- login(loginData);
-}, false);
-
-function login(loginData) {
- sync.login(loginData, loginHandler);
-}
-
-function loginHandler(error, status) {
- if (error) {
- setButtonData({status: "Login failed: " + JSON.stringify(error)}, true);
- localStorage.setItem('syncbutton-saved-authdata', null);
- setButtonData({logout: true}, false);
- return;
- }
- localStorage.setItem('syncbutton-saved-authdata', JSON.stringify(sync.getAuthData()));
- setButtonData({logout: false, username: status.email, status: null}, false);
-}
-
-window.addEventListener('load', function () {
- var authData = localStorage.getItem('syncbutton-saved-authdata');
- if (authData) {
- authData = JSON.parse(authData);
- if (authData) {
- sync.setAuthData(authData, loginHandler);
- return;
- }
- }
- setButtonData({logout: true}, false);
-}, false);
-
-function syncNow(callback, forcePut) {
- sync.syncNow(function (error, result) {
- // FIXME: get better way to display error
- if (error && (! error.error == 'uuid_changed')) {
- sync.onstatus({error: true, detail: error});
- } else {
- setButtonData({lastUpdate: new Date().getTime()}, true);
- }
- callback(error, result);
- }, forcePut);
-}
-
-
-function setButtonData(data, merge) {
- if (merge) {
- var mergeData = data;
- data = localStorage.getItem('syncbutton-comm');
- if (data) {
- data = JSON.parse(data);
- } else {
- data = {};
- }
- for (var i in mergeData) {
- if (mergeData.hasOwnProperty(i)) {
- data[i] = mergeData[i];
- }
- }
- }
- localStorage.setItem('syncbutton-comm', JSON.stringify(data));
-}
-
-function getOrigin(url) {
- var protocol = url.substr(0, url.indexOf('//')).toLowerCase();
- var domain = url.substr(url.indexOf('//')+2);
- if (domain.indexOf('/') != -1) {
- domain = domain.substr(0, domain.indexOf('/'));
- }
- domain = domain.toLowerCase();
- if (protocol == 'http:' && domain.search(/:80$/) != -1) {
- domain = domain.replace(/:80$/, '');
- } else if (protocol == 'https:' && domain.search(/:443$/) != -1) {
- domain = domain.replace(/:443$/, '');
- }
- return protocol + '//' + domain;
-}
-
-var sync = new SyncService({
- repo: Repo,
- server: new Server('/verify')
-});
-
-sync.onstatus = function (status) {
- if (status.error) {
- if (status.detail.error != 'uuid_changed') {
- var message = status.detail.error;
- if (status.detail.message) {
- message = status.detail.message;
- } else if (status.detail.error == 'Non-200 response code') {
- message = 'server error';
- }
- setButtonData({status: "Error: " + message}, true);
- }
- } else if (status.status) {
- if (status.status == 'sync_get') {
- setButtonData({last_sync_get: status.timestamp}, true);
- } else if (status.status == 'sync_put_complete' || (status.status == 'sync_put' && status.count === 0)) {
- setButtonData({last_sync_put: status.timestamp}, true);
- }
- }
-};
-
-var scheduler = new Scheduler(sync);
-scheduler.onerror = function (error) {
- sync.onstatus({error: true, detail: error});
-};
2  site/tools/apps.mozillalabs.com
@@ -1 +1 @@
-Subproject commit 08686c43e559c1ff6664d14bacd2a4e93fbaa990
+Subproject commit b711b3018b2f6a841d67fbadbc40427a1ca887d2
4 site/tools/build_static
View
@@ -95,7 +95,3 @@ echo "Creating minified jsapi/include.js"
cp ${DEST}/jsapi/include.js ${DEST}/jsapi/include.complete.js
echo "/* For unminified source see ${HOST}/jsapi/include.complete.js */" > ${DEST}/jsapi/include.js
java -jar ${COMP_DIR}/yuicompressor-2.4.2.jar ${DEST}/jsapi/include.complete.js >> ${DEST}/jsapi/include.js
-
-echo "Creating minified jsapi/syncbutton.html"
-cp ${DEST}/jsapi/syncbutton.html ${DEST}/jsapi/syncbutton.complete.html
-${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"
Please sign in to comment.
Something went wrong with that request. Please try again.