Commit 66f0ae9b authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

JSLint Javascript Code

parent dff89c6d
...@@ -26,7 +26,7 @@ if ('serviceWorker' in navigator) { ...@@ -26,7 +26,7 @@ if ('serviceWorker' in navigator) {
//jio = jIO.createJIO({type: "indexeddb", database: "cribjs"}); //jio = jIO.createJIO({type: "indexeddb", database: "cribjs"});
jio = jIO.createJIO({type:"dav", url: "https://cedriclendav.node.vifib.com/toto", basic_login: btoa("cedriclen:foo")}) jio = jIO.createJIO({type:"dav", url: "https://cedriclendav.node.vifib.com/toto", basic_login: btoa("cedriclen:foo")});
function setStatus(statusMessage) { function setStatus(statusMessage) {
document.querySelector('#status').textContent = statusMessage; document.querySelector('#status').textContent = statusMessage;
...@@ -52,7 +52,7 @@ function showCommands() { ...@@ -52,7 +52,7 @@ function showCommands() {
}).then(function() { }).then(function() {
// If the promise resolves, just display a success message. // If the promise resolves, just display a success message.
setStatus('Added to cache: ' + url + ' at ' + Date()); setStatus('Added to cache: ' + url + ' at ' + Date());
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error. }, setStatus);
}); });
document.querySelector('#delete').addEventListener('click', function() { document.querySelector('#delete').addEventListener('click', function() {
...@@ -62,7 +62,7 @@ function showCommands() { ...@@ -62,7 +62,7 @@ function showCommands() {
}).then(function() { }).then(function() {
// If the promise resolves, just display a success message. // If the promise resolves, just display a success message.
setStatus('Deleted from cache.'); setStatus('Deleted from cache.');
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error. }, setStatus); // If the promise rejects, then setStatus will be called with the error.
}); });
document.querySelector('#list-contents').addEventListener('click', function() { document.querySelector('#list-contents').addEventListener('click', function() {
...@@ -84,7 +84,7 @@ function showCommands() { ...@@ -84,7 +84,7 @@ function showCommands() {
liElement.innerHTML = aElement.outerHTML; liElement.innerHTML = aElement.outerHTML;
contentsElement.appendChild(liElement); contentsElement.appendChild(liElement);
}); });
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error. }, setStatus); // If the promise rejects, then setStatus will be called with the error.
}); });
document.querySelector('#get').addEventListener('click', function() { document.querySelector('#get').addEventListener('click', function() {
...@@ -95,15 +95,15 @@ function showCommands() { ...@@ -95,15 +95,15 @@ function showCommands() {
document.querySelector('#information').value = this.responseText; document.querySelector('#information').value = this.responseText;
} }
); );
}) });
document.querySelector('#save-path').value = document.location.origin; document.querySelector('#save-path').value = document.location.origin;
document.querySelector('#save-contents').addEventListener('click', function() { document.querySelector('#save-contents').addEventListener('click', function() {
console.log('asking for the keys'); console.log('asking for the keys');
var path_to_save, path_to_save_length, application_id; var path_to_save, path_to_save_length, application_id;
path_to_save = document.querySelector('#save-path').value path_to_save = document.querySelector('#save-path').value;
application_id = document.querySelector('#save-id').value application_id = document.querySelector('#save-id').value;
path_to_save_length = path_to_save.length path_to_save_length = path_to_save.length;
sendMessage({ sendMessage({
command: 'keys' command: 'keys'
}).then(function(data) { }).then(function(data) {
...@@ -123,36 +123,36 @@ function showCommands() { ...@@ -123,36 +123,36 @@ function showCommands() {
var promise_list = [], var promise_list = [],
i, i_len, url; i, i_len, url;
for (i = 0, i_len = data.urls.length; i < i_len; i += 1) { for (i = 0, i_len = data.urls.length; i < i_len; i += 1) {
url = new String(data.urls[i]); url = String(data.urls[i]);
if (url.indexOf(path_to_save) === 0) { if (url.indexOf(path_to_save) === 0) {
promise_list.push(jIO.util.ajax({ promise_list.push(jIO.util.ajax({
'url': url, 'url': url,
dataType: "blob" dataType: "blob"
})); }));
} }
}; }
return RSVP.all(promise_list) return RSVP.all(promise_list);
}) })
.push(function(response_list) { .push(function(response_list) {
var promise_list = [], var promise_list = [],
i, i_len, url, response, extension; i, i_len, url, response, extension;
for (i = 0, i_len = response_list.length; i < i_len; i += 1) { for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i]; response = response_list[i];
url = response.target.responseURL.substr(path_to_save_length) url = response.target.responseURL.substr(path_to_save_length);
extension = getExtension(url) extension = getExtension(url);
console.log("Pushing attachment " + url + " to " + path_to_save); console.log("Pushing attachment " + url + " to " + path_to_save);
promise_list.push( promise_list.push(
jio.putAttachment("/" + application_id + ".attachment/", btoa(url) + extension, jio.putAttachment("/" + application_id + ".attachment/", btoa(url) + extension,
response.target.response response.target.response
) )
); );
}; }
return RSVP.all(promise_list) return RSVP.all(promise_list);
}) })
.push(undefined, function(error) { .push(undefined, function(error) {
console.log(error); console.log(error);
}); });
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error. }, setStatus); // If the promise rejects, then setStatus will be called with the error.
}); });
document.querySelector('#load-path').value = document.location.origin; document.querySelector('#load-path').value = document.location.origin;
...@@ -160,11 +160,11 @@ function showCommands() { ...@@ -160,11 +160,11 @@ function showCommands() {
console.log('asking for the keys'); console.log('asking for the keys');
var url_list = [], var url_list = [],
application_id; application_id;
application_id = document.querySelector('#load-id').value application_id = document.querySelector('#load-id').value;
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function() {
console.log("put"); console.log("put");
return jio.allAttachments("/" + application_id + ".attachment/") return jio.allAttachments("/" + application_id + ".attachment/");
}) })
.push(function(response) { .push(function(response) {
var promise_list = [], var promise_list = [],
...@@ -173,21 +173,21 @@ function showCommands() { ...@@ -173,21 +173,21 @@ function showCommands() {
if (response.hasOwnProperty(key)) { if (response.hasOwnProperty(key)) {
extension = getExtension(key); extension = getExtension(key);
console.log(key); console.log(key);
url_list.push(atob(key.substr(0, key.length - extension.length))) url_list.push(atob(key.substr(0, key.length - extension.length)));
promise_list.push(jio.getAttachment("/" + application_id + ".attachment/", key)); promise_list.push(jio.getAttachment("/" + application_id + ".attachment/", key));
} }
}; }
return RSVP.all(promise_list) return RSVP.all(promise_list);
}) })
.push(function(response_list) { .push(function(response_list) {
var promise_list = [], var promise_list = [],
i, i_len, url, index, response, location, location_len; i, i_len, url, index, response, location, location_len;
location = document.location.origin; location = document.location.origin;
location_len = location.length location_len = location.length;
console.log(url_list); console.log(url_list);
console.log(response_list); console.log(response_list);
for (i = 0, i_len = response_list.length; i < i_len; i += 1) { for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
url = url_list[i] url = url_list[i];
index = url.indexOf(location); index = url.indexOf(location);
if (index != -1) if (index != -1)
url = url.substr(index + location_len); url = url.substr(index + location_len);
...@@ -195,7 +195,7 @@ function showCommands() { ...@@ -195,7 +195,7 @@ function showCommands() {
command: 'add', command: 'add',
url: document.querySelector('#load-path').value + url, url: document.querySelector('#load-path').value + url,
information: response_list[i] information: response_list[i]
}) });
} }
}) })
.push(undefined, function(error) { .push(undefined, function(error) {
...@@ -207,16 +207,11 @@ function showCommands() { ...@@ -207,16 +207,11 @@ function showCommands() {
var url_list = document.querySelector('#mass-remove-list').value.match(/[^\r\n]+/g), var url_list = document.querySelector('#mass-remove-list').value.match(/[^\r\n]+/g),
url_list_length = url_list.length, url_list_length = url_list.length,
i; i;
console.log(url_list)
for (i = 0; i < url_list_length; i += 1) { for (i = 0; i < url_list_length; i += 1) {
console.log(url_list[i])
sendMessage({ sendMessage({
command: 'delete', command: 'delete',
url: url_list[i], url: url_list[i]
}).then(function() { }); // If the promise rejects, then setStatus will be called with the error.
// If the promise resolves, just display a success message.
setStatus('Deleted from cache.');
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
} }
}); });
......
This diff is collapsed.
/*global window, rJS, RSVP, URI, location,
loopEventListener*/
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP) {
"use strict";
function setERP5Configuration(gadget) {
var old_date = new Date(),
configuration = {};
// We are looking for documents modified in the past 3 month
old_date.setMonth(old_date - 2);
old_date.setDay(1);
configuration = {
type: "replicate",
// XXX This drop the signature lists...
query: {
query: 'portal_type:"Web Page" '
// XX Synchonizing the whole module is too much, here is a way to start quietly
// Supsended until modification_date is handled for synchronization
+ ' AND modification_date:>="'
+ today.toISOString(),
limit: [0, 1234567890]
},
use_remote_post: true,
conflict_handling: 1,
check_local_modification: true,
check_local_creation: true,
check_local_deletion: false,
check_remote_modification: true,
check_remote_creation: true,
check_remote_deletion: true,
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs"
}
}
},
remote_sub_storage: {
type: "erp5",
url: (new URI("hateoas"))
.absoluteTo(location.href)
.toString(),
default_view_reference: "jio_view"
}
};
return gadget.setSetting('jio_storage_description', configuration)
.push(function () {
return gadget.setSetting('jio_storage_name', "ERP5");
})
.push(function () {
return gadget.reload();
});
}
function setLocalConfiguration(gadget) {
var configuration = {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs"
}
}
};
return gadget.setSetting('jio_storage_description', configuration)
.push(function () {
return gadget.reload();
});
}
function setDAVConfiguration(gadget) {
return gadget.redirect({page: 'jio_dav_configurator'});
}
var gadget_klass = rJS(window);
gadget_klass
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.deferred = RSVP.defer();
});
})
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("reload", "reload")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function () {
var gadget = this;
return gadget.updateHeader({
title: "Storage Configuration"
}).push(function () {
return gadget.props.deferred.resolve();
});
})
/////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
})
.push(function () {
return RSVP.all([
loopEventListener(
gadget.props.element.querySelector('form.select-erp5-form'),
'submit',
true,
function () {
return setERP5Configuration(gadget);
}
),
loopEventListener(
gadget.props.element.querySelector('form.select-local-form'),
'submit',
true,
function () {
return setLocalConfiguration(gadget);
}
),
loopEventListener(
gadget.props.element.querySelector('form.select-dav-form'),
'submit',
true,
function () {
return setDAVConfiguration(gadget);
}
)
]);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
/*globals window, document, RSVP, rJS, Handlebars, console*/ /*globals window, document, RSVP, rJS, Handlebars, console*/
/*jslint indent: 2, maxlen: 80*/ /*jslint indent: 2, maxlen: 80*/
(function (window, document, RSVP, rJS, Handlebars, console) { (function (RSVP, rJS, Handlebars) {
"use strict"; "use strict";
function callCribSWGadget(gadget, method, param_list) { function callCribSWGadget(gadget, method, param_list) {
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
.push(function (crib_ide_gadget) { .push(function (crib_ide_gadget) {
return crib_ide_gadget.render(); return crib_ide_gadget.render();
}); });
}) });
}(window, document, RSVP, rJS, console)); }(RSVP, rJS, Handlebars));
\ No newline at end of file \ No newline at end of file
...@@ -41,15 +41,6 @@ ...@@ -41,15 +41,6 @@
}); });
} }
/*
function initHeaderOptions(gadget) {
gadget.props.header_argument_list = {
panel_action: true,
title: gadget.props.application_title || "OfficeJS"
};
}
*/
function route(my_root_gadget, my_scope, my_method, my_param_list) { function route(my_root_gadget, my_scope, my_method, my_param_list) {
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
...@@ -64,51 +55,10 @@ function initHeaderOptions(gadget) { ...@@ -64,51 +55,10 @@ function initHeaderOptions(gadget) {
} }
/*
function updateHeader(gadget) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.render(gadget.props.header_argument_list);
});
}
function increaseLoadingCounter(gadget) {
return new RSVP.Queue()
.push(function () {
gadget.props.loading_counter += 1;
if (gadget.props.loading_counter === 1) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.notifyLoading();
});
}
});
}
function decreaseLoadingCounter(gadget) {
return new RSVP.Queue()
.push(function () {
gadget.props.loading_counter -= 1;
if (gadget.props.loading_counter < 0) {
gadget.props.loading_counter = 0;
// throw new Error("Unexpected negative loading counter");
}
if (gadget.props.loading_counter === 0) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.notifyLoaded();
});
}
});
}
*/
function callJioGadget(gadget, method, param_list) { function callJioGadget(gadget, method, param_list) {
var called = false; var called = false;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () {
called = true;
return increaseLoadingCounter(gadget);
})
.push(function () { .push(function () {
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
...@@ -116,17 +66,8 @@ function initHeaderOptions(gadget) { ...@@ -116,17 +66,8 @@ function initHeaderOptions(gadget) {
return jio_gadget[method].apply(jio_gadget, param_list); return jio_gadget[method].apply(jio_gadget, param_list);
}) })
.push(function (result) { .push(function (result) {
return decreaseLoadingCounter(gadget)
.push(function () {
return result; return result;
});
}, function (error) { }, function (error) {
if (called) {
return decreaseLoadingCounter(gadget)
.push(function () {
throw error;
});
}
throw error; throw error;
}); });
} }
...@@ -274,26 +215,6 @@ function initHeaderOptions(gadget) { ...@@ -274,26 +215,6 @@ function initHeaderOptions(gadget) {
.toString() .toString()
); );
}) })
// Configure jIO storage
/*.ready(function (g) {
var jio_gadget;
return g.getDeclaredGadget("jio_gadget")
.push(function (result) {
jio_gadget = result;
return getSetting(g, 'jio_storage_description');
})
.push(function (result) {
return jio_gadget.createJio(result);
});
})*/
/*
.ready(function (g) {
return g.getDeclaredGadget('panel')
.push(function (panel_gadget) {
return panel_gadget.render();
});
})
*/
.ready(function (g) { .ready(function (g) {
return g.getDeclaredGadget('router') return g.getDeclaredGadget('router')
.push(function (router_gadget) { .push(function (router_gadget) {
...@@ -316,33 +237,7 @@ function initHeaderOptions(gadget) { ...@@ -316,33 +237,7 @@ function initHeaderOptions(gadget) {
.allowPublicAcquisition("setSetting", function (argument_list) { .allowPublicAcquisition("setSetting", function (argument_list) {
return setSetting(this, argument_list[0], argument_list[1]); return setSetting(this, argument_list[0], argument_list[1]);
}) })
/*
.allowPublicAcquisition("translateHtml", function (argument_list) {
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
return translation_gadget.translateHtml(argument_list[0]);
});
})
// XXX Those methods may be directly integrated into the header,
// as it handles the submit triggering
.allowPublicAcquisition('notifySubmitting', function () {
return route(this, "header", 'notifySubmitting');
})
.allowPublicAcquisition('notifySubmitted', function () {
return route(this, "header", "notifySubmitted");
})
.allowPublicAcquisition('notifyChange', function () {
return route(this, "header", 'notifyChange');
})
.allowPublicAcquisition("translate", function (argument_list) {
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
return translation_gadget.translate(argument_list[0]);
});
})
/**/
.allowPublicAcquisition("redirect", function (param_list) { .allowPublicAcquisition("redirect", function (param_list) {
return this.getDeclaredGadget('router') return this.getDeclaredGadget('router')
.push(function (router_gadget) { .push(function (router_gadget) {
...@@ -365,60 +260,6 @@ function initHeaderOptions(gadget) { ...@@ -365,60 +260,6 @@ function initHeaderOptions(gadget) {
param_list); param_list);
}); });
}) })
/*
.allowPublicAcquisition("updateHeader", function (param_list) {
var gadget = this;
initHeaderOptions(gadget);
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
var promise_list = [],
key;
for (key in param_list[0]) {
if (param_list[0].hasOwnProperty(key)) {
gadget.props.header_argument_list[key] = param_list[0][key];
}
}
promise_list.push(translation_gadget.translate(
gadget.props.header_argument_list.title
));
if (gadget.props.header_argument_list.hasOwnProperty('right_title')) {
promise_list.push(translation_gadget.translate(
gadget.props.header_argument_list.right_title
));
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
gadget.props.header_argument_list.title = result_list[0];
if (result_list.length === 2) {
gadget.props.header_argument_list.right_title = result_list[1];
}
// XXX Sven hack: number of _url determine padding for
// subheader on ui-content
var key,
count = 0;
for (key in gadget.props.header_argument_list) {
if (gadget.props.header_argument_list.hasOwnProperty(key)) {
if (key.indexOf('_url') > -1) {
count += 1;
}
}
}
if (count > 2) {
gadget.props.sub_header_class = "ui-has-subheader";
}
});
})
.allowPublicAcquisition('triggerPanel', function () {
return route(this, "panel", "toggle");
})
.allowPublicAcquisition('renderEditorPanel', function (param_list) {
return route(this, "editor_panel", 'render', param_list);
})
/**/
.allowPublicAcquisition("jio_createJio", function (param_list) { .allowPublicAcquisition("jio_createJio", function (param_list) {
return callJioGadget(this, "createJio", param_list); return callJioGadget(this, "createJio", param_list);
}) })
...@@ -487,21 +328,6 @@ function initHeaderOptions(gadget) { ...@@ -487,21 +328,6 @@ function initHeaderOptions(gadget) {
// (ERP5 title by default + sidebar) // (ERP5 title by default + sidebar)
//initHeaderOptions(gadget); //initHeaderOptions(gadget);
return new RSVP.Queue() return new RSVP.Queue()
/*.push(function () {
return increaseLoadingCounter(gadget);
})
.push(function () {
return gadget.getDeclaredGadget('panel');
})
.push(function (panel_gadget) {
return panel_gadget.close();
})
.push(function () {
return gadget.getDeclaredGadget('editor_panel');
})
.push(function (editor_panel) {
return editor_panel.close();
})/**/
.push(function () { .push(function () {
return gadget.getDeclaredGadget('router'); return gadget.getDeclaredGadget('router');
}) })
...@@ -522,10 +348,6 @@ function initHeaderOptions(gadget) { ...@@ -522,10 +348,6 @@ function initHeaderOptions(gadget) {
.push(function (fragment) { .push(function (fragment) {
var element = gadget.props.content_element, var element = gadget.props.content_element,
content_container = document.createElement("div"); content_container = document.createElement("div");
//content_container.className = "ui-content " +
// (gadget.props.sub_header_class || "");
// reset subheader indicator
//delete gadget.props.sub_header_class;
// go to the top of the page // go to the top of the page
window.scrollTo(0, 0); window.scrollTo(0, 0);
...@@ -545,14 +367,6 @@ function initHeaderOptions(gadget) { ...@@ -545,14 +367,6 @@ function initHeaderOptions(gadget) {
}); });
} }
}) })
/*.push(function () {
return decreaseLoadingCounter(gadget);
}, function (error) {
return decreaseLoadingCounter(gadget)
.push(function () {
throw error;
});
})/**/
.push(undefined, function (error) { .push(undefined, function (error) {
return displayError(gadget, error); return displayError(gadget, error);
}); });
......
/*global window, rJS, RSVP */ /*global window, rJS, RSVP, XMLHttpRequest, MessageChannel,
console, navigator, Blob
*/
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) { (function (rJS, RSVP, jIO) {
"use strict"; "use strict";
/** /**
...@@ -20,10 +22,10 @@ ...@@ -20,10 +22,10 @@
*/ */
function ajax(param) { function ajax(param) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
return new RSVP.Promise(function(resolve, reject, notify) { return new RSVP.Promise(function (resolve, reject, notify) {
var k; var k;
xhr.open(param.type || "GET", param.url, true); xhr.open(param.type || "GET", param.url, true);
xhr.addEventListener("load", function(e) { xhr.addEventListener("load", function (e) {
var answer = {}; var answer = {};
if (e.target.status >= 400) { if (e.target.status >= 400) {
return reject(e); return reject(e);
...@@ -43,7 +45,7 @@ ...@@ -43,7 +45,7 @@
} }
} }
xhr.send(); xhr.send();
}, function() { }, function () {
xhr.abort(); xhr.abort();
}); });
} }
...@@ -54,9 +56,9 @@ ...@@ -54,9 +56,9 @@
// contain an error, and reject with the error if it does. If you'd prefer, it's possible to call // contain an error, and reject with the error if it does. If you'd prefer, it's possible to call
// controller.postMessage() and set up the onmessage handler independently of a promise, but this is // controller.postMessage() and set up the onmessage handler independently of a promise, but this is
// a convenient wrapper. // a convenient wrapper.
return new RSVP.Promise(function(resolve, reject, notify) { return new RSVP.Promise(function (resolve, reject, notify) {
var messageChannel = new MessageChannel(); var messageChannel = new MessageChannel();
messageChannel.port1.onmessage = function(event) { messageChannel.port1.onmessage = function (event) {
console.log(event); console.log(event);
if (event.data.error) { if (event.data.error) {
reject(event.data.error); reject(event.data.error);
...@@ -85,21 +87,22 @@ ...@@ -85,21 +87,22 @@
g.props.element = element; g.props.element = element;
}); });
}) })
.ready(function(gadget) { .ready(function (gadget) {
// Initialize the gadget local parameters // Initialize the gadget local parameters
gadget.state_parameter_dict = {}; gadget.state_parameter_dict = {};
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
// XXX Hack to not add a new service worker when one is already declared // XXX Hack to not add a new service worker when one is already declared
if (!navigator.serviceWorker.controller) { if (!navigator.serviceWorker.controller) {
return new RSVP.Promise(function(resolve, reject, notify) { return new RSVP.Promise(function (resolve, reject, notify) {
navigator.serviceWorker.register('/sw.js', {scope: '/'}).then( navigator.serviceWorker.register('/sw.js', {scope: '/'}).then(
function(){ function () {
if (navigator.serviceWorker.controller) { if (navigator.serviceWorker.controller) {
resolve(); resolve();
} else { } else {
reject("Please reload this page to allow Service Worker to control this page"); reject("Please reload this page to allow Service Worker to control this page");
} }
}).catch(function(error) { })
.then(undefined, function (error) {
reject(error); reject(error);
}); });
}); });
...@@ -115,17 +118,17 @@ ...@@ -115,17 +118,17 @@
* @params {Object} Not taken into account * @params {Object} Not taken into account
* @return {} Return the data url of the document * @return {} Return the data url of the document
*/ */
.declareMethod('allDocs', function(params) { .declareMethod('allDocs', function (params) {
if (params && params.cached_only) { if (params && params.cached_only) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return sendMessage({ return sendMessage({
command: 'keys' command: 'keys'
}); });
}); });
} }
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return sendMessage({ return sendMessage({
command: 'allDocs' command: 'allDocs'
}); });
...@@ -139,7 +142,7 @@ ...@@ -139,7 +142,7 @@
* @url {string} url of the document to retrieve * @url {string} url of the document to retrieve
* @return {data_url} Return the data url of the document * @return {data_url} Return the data url of the document
*/ */
.declareMethod('get', function(url) { .declareMethod('get', function (url) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return ajax({ return ajax({
...@@ -147,12 +150,12 @@ ...@@ -147,12 +150,12 @@
}); });
}) })
.push(function (result) { .push(function (result) {
return new Blob([result.responseText], {type: result.responseType}) return new Blob([result.responseText], {type: result.responseType});
}) })
.push(function(result) { .push(function (result) {
return jIO.util.readBlobAsDataURL(result); return jIO.util.readBlobAsDataURL(result);
}) })
.push(function(e) { .push(function (e) {
return e.target.result; return e.target.result;
}); });
}) })
...@@ -165,17 +168,17 @@ ...@@ -165,17 +168,17 @@
* @parameter {data_url} data url of the document to put, it will be transformed in a blob * @parameter {data_url} data url of the document to put, it will be transformed in a blob
* @return {data_url} Return the data url of the document * @return {data_url} Return the data url of the document
*/ */
.declareMethod('put', function(url, parameter) { .declareMethod('put', function (url, parameter) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return sendMessage({ return sendMessage({
command: 'add', command: 'add',
url: url, url: url,
information: jIO.util.dataURItoBlob(parameter) information: jIO.util.dataURItoBlob(parameter)
}); });
}).push(function() { }).push(function () {
// If the promise resolves, just display a success message. // If the promise resolves, just display a success message.
console.log("Done adding "+ url); console.log("Done adding " + url);
return 'Added to cache: ' + url + ' at ' + Date(); return 'Added to cache: ' + url + ' at ' + Date();
}).fail(setStatus); }).fail(setStatus);
}) })
...@@ -186,9 +189,9 @@ ...@@ -186,9 +189,9 @@
* @url {string} url of the document to remove * @url {string} url of the document to remove
* @return {} * @return {}
*/ */
.declareMethod('remove', function(url) { .declareMethod('remove', function (url) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return sendMessage({ return sendMessage({
command: 'delete', command: 'delete',
url: url url: url
...@@ -196,4 +199,4 @@ ...@@ -196,4 +199,4 @@
}); });
}); });
}(window, rJS, RSVP, jIO)); }(rJS, RSVP, jIO));
\ No newline at end of file \ No newline at end of file
/*global window, rJS, RSVP */ /*global window, rJS, RSVP, Blob, console */
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) { (function (window, rJS, RSVP, jIO) {
"use strict"; "use strict";
function getStorageGadget(gadget) { function getStorageGadget(gadget) {
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
}); });
}); });
} else { } else {
gadget.props.storage_gadget_url = url gadget.props.storage_gadget_url = url;
return gadget.dropGadget("storage") return gadget.dropGadget("storage")
.push(function () {}, function () {}) .push(function () {}, function () {})
.push(function () { .push(function () {
...@@ -33,18 +33,19 @@ ...@@ -33,18 +33,19 @@
"sandbox": "iframe", "sandbox": "iframe",
"element": gadget.props.element.querySelector('div') "element": gadget.props.element.querySelector('div')
}); });
}) });
} }
}) })
.push(undefined, function (e) { .push(undefined, function (e) {
// Ugly Hack to reload page and make service worker available // Ugly Hack to reload page and make service worker available
if (e && e.indexOf("Please reload this page to allow Service Worker to control this page") > -1 ) { if (e &&
e.indexOf("Please reload this page to allow Service Worker to control this page") > -1) {
console.log("reload"); console.log("reload");
window.location.reload(false); window.location.reload(false);
throw(e); throw (e);
} else { } else {
console.log(e); console.log(e);
throw(e); throw (e);
} }
}); });
} }
...@@ -56,40 +57,39 @@ ...@@ -56,40 +57,39 @@
.push(function (element) { .push(function (element) {
var getURL = window.location; var getURL = window.location;
g.props.element = element; g.props.element = element;
getURL.protocol + "//" + getURL.host + "/crib-enable.html"
}); });
}) })
.ready(function(gadget) { .ready(function (gadget) {
// Initialize the gadget local parameters // Initialize the gadget local parameters
gadget.state_parameter_dict = {}; gadget.state_parameter_dict = {};
return getStorageGadget(gadget); return getStorageGadget(gadget);
}) })
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('allDocs', function(params) { .declareMethod('allDocs', function (params) {
return getStorageGadget(this) return getStorageGadget(this)
.push(function (storage_gadget) { .push(function (storage_gadget) {
return storage_gadget.allDocs(params) return storage_gadget.allDocs(params);
}); });
}) })
.declareMethod('get', function(url) { .declareMethod('get', function (url) {
return getStorageGadget(this) return getStorageGadget(this)
.push(function (storage_gadget) { .push(function (storage_gadget) {
return storage_gadget.get(url) return storage_gadget.get(url);
}) })
.push(function (result) { .push(function (result) {
return jIO.util.dataURItoBlob(result); return jIO.util.dataURItoBlob(result);
}); });
}) })
.declareMethod('put', function(url, parameter) { .declareMethod('put', function (url, parameter) {
var blob, gadget = this; var blob, gadget = this;
if (parameter.blob !== undefined) { if (parameter.blob !== undefined) {
blob = parameter.blob; blob = parameter.blob;
} else { } else {
blob = new Blob( blob = new Blob(
[parameter.content], [parameter.content],
{type: parameter.type,} {type: parameter.type}
); );
} }
return RSVP.Queue() return RSVP.Queue()
...@@ -106,10 +106,10 @@ ...@@ -106,10 +106,10 @@
; ;
}) })
.declareMethod('remove', function(url) { .declareMethod('remove', function (url) {
return getStorageGadget(this) return getStorageGadget(this)
.push(function (storage_gadget) { .push(function (storage_gadget) {
return storage_gadget.remove(url) return storage_gadget.remove(url);
}); });
}); });
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Codemirror Gadget</title>
<script src="../lib/rsvp.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<link rel="stylesheet" href="../lib/codemirror.css">
<link rel="stylesheet" href="../lib/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="../lib/codemirror/addon/search/matchesonscrollbar.css">
<script src="../lib/codemirror.js"></script>
<script src="../lib/codemirror/mode/css/css.js"></script>
<script src="../lib/codemirror/mode/xml/xml.js"></script>
<script src="../lib/codemirror/mode/javascript/javascript.js"></script>
<script src="../lib/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="../lib/codemirror/addon/dialog/dialog.js"></script>
<script src="../lib/codemirror/addon/search/searchcursor.js"></script>
<script src="../lib/codemirror/addon/search/search.js"></script>
<script src="../lib/codemirror/addon/scroll/annotatescrollbar.js"></script>
<script src="../lib/codemirror/addon/search/matchesonscrollbar.js"></script>
<script src="./gadget_codemirror.js" type="text/javascript"></script>
</head>
<body>
<div class="codemirror_gadget"><textarea name="code"></textarea></div>
</body>
</html>
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, CodeMirror */
(function (window, rJS, CodeMirror) {
"use strict";
rJS(window)
.declareAcquiredMethod("saveContent", "editor_saveContent")
.declareMethod('render', function (options) {
this.props.key = options.key || {};
this.props.editor.setOption("mode", options.mode || "htmlmixed");
this.props.editor.setValue(options.value || "");
})
.declareMethod('getContent', function () {
var result = {};
result[this.props.key || "text_content"] = this.props.editor.getValue();
return result;
})
.declareService(function () {
this.props.editor.refresh();
this.props.editor.focus();
})
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
CodeMirror.commands.save = function () {
return new RSVP.Queue()
.push(function () {
return g.saveContent()
})
};
g.props.editor = CodeMirror.fromTextArea(g.props.element.querySelector("textarea"), {
lineNumbers: true,
mode: "text/html", /*{
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
},*/
// fullScreen: true,
matchBrackets: true,
showCursorWhenSelecting: true,
extraKeys: {"Alt-F": "findPersistent"}
});
// XXX custom styling for CribJS, should be put somewhere else
g.props.element.querySelector('.CodeMirror').setAttribute('style', 'height: calc(100vh - 270px);')
});
});
}(window, rJS, CodeMirror));
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, Handlebars, document, loopEventListener, RSVP */ /*global window, rJS, Handlebars, document, loopEventListener, RSVP */
(function (window, rJS, Handlebars, document, loopEventListener, RSVP) { (function (rJS, Handlebars, loopEventListener, RSVP) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -54,11 +54,6 @@ ...@@ -54,11 +54,6 @@
g.props.title_element = element.querySelector("h1"); g.props.title_element = element.querySelector("h1");
}); });
}) })
/*
.ready(function (g) {
return g.render(g.stats.options);
})
*/
////////////////////////////////////////////// //////////////////////////////////////////////
// acquired methods // acquired methods
////////////////////////////////////////////// //////////////////////////////////////////////
...@@ -70,21 +65,6 @@ ...@@ -70,21 +65,6 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/*
.declareMethod('notifyError', function () {
this.stats.loaded = true;
this.stats.submitted = true;
this.stats.error = true;
var gadget = this;
return this.render(this.stats.options)
.push(function () {
gadget.stats.error = false;
});
})
.declareMethod('notifyUpdate', function () {
return this.render(this.stats.options);
})
*/
.declareMethod('notifyLoading', function () { .declareMethod('notifyLoading', function () {
if (this.stats.loaded) { if (this.stats.loaded) {
this.stats.loaded = false; this.stats.loaded = false;
...@@ -97,28 +77,6 @@ ...@@ -97,28 +77,6 @@
return this.render(this.stats.options); return this.render(this.stats.options);
} }
}) })
/*
.declareMethod('notifyChange', function () {
if (!this.stats.modified) {
this.stats.modified = true;
return this.render(this.stats.options);
}
})
.declareMethod('notifySubmitting', function () {
if (this.stats.submitted) {
this.stats.submitted = false;
return this.render(this.stats.options);
}
})
.declareMethod('notifySubmitted', function () {
if (!this.stats.submitted) {
this.stats.submitted = true;
// Change modify here, to allow user to redo some modification and being correctly notified
this.stats.modified = false;
return this.render(this.stats.options);
}
})
*/
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this, var gadget = this,
page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "tools", "mass_remove"], page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "tools", "mass_remove"],
...@@ -126,8 +84,8 @@ ...@@ -126,8 +84,8 @@
gadget.stats.options = options; gadget.stats.options = options;
page_list.forEach(function (page) { page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page})) promise_list.push(gadget.getUrlFor({page: page}));
}) });
// Handle main title // Handle main title
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -135,7 +93,7 @@ ...@@ -135,7 +93,7 @@
}) })
.push(function (link_list) { .push(function (link_list) {
for (var i = 0; i < link_list.length; i++) { for (var i = 0; i < link_list.length; i++) {
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i] gadget.props.element.querySelector("." + page_list[i]).href = link_list[i];
} }
}); });
}) })
...@@ -167,4 +125,4 @@ ...@@ -167,4 +125,4 @@
); );
}); });
}(window, rJS, Handlebars, document, loopEventListener, RSVP)); }(rJS, Handlebars, loopEventListener, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
promise_list = []; promise_list = [];
page_list.forEach(function (page) { page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page})) promise_list.push(gadget.getUrlFor({page: page}));
}) });
// Handle main title // Handle main title
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -35,10 +35,10 @@ ...@@ -35,10 +35,10 @@
}) })
.push(function (link_list) { .push(function (link_list) {
for (var i = 0; i < link_list.length; i++) { for (var i = 0; i < link_list.length; i++) {
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i] gadget.props.element.querySelector("." + page_list[i]).href = link_list[i];
} }
}); });
}) });
}(window, rJS, document, RSVP)); }(window, rJS, document, RSVP));
\ No newline at end of file
/*global window, rJS, loopEventListener */ /*global window, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, jIO) { (function (window, rJS, loopEventListener, jIO) {
"use strict"; "use strict";
...@@ -18,18 +18,19 @@ ...@@ -18,18 +18,19 @@
}) })
.push(function (data) { .push(function (data) {
content = data[CODE_CONTENT_KEY] || ""; content = data[CODE_CONTENT_KEY] || "";
return gadget.crib_sw_put(url, {content:content, type:mimetype}); return gadget.crib_sw_put(url, {content: content, type: mimetype});
})
.push(function() {
gadget.props.element.querySelector(".crib-editor-save-status").textContent = "Saved " + url + " files at "+ Date ()
}) })
.push(function () {
gadget.props.element.querySelector(".crib-editor-save-status")
.textContent = "Saved " + url + " files at " + Date();
});
} }
function getUrlTextContent(gadget, event, url) { function getUrlTextContent(gadget, event, url) {
var type; var type;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.crib_sw_get(url) return gadget.crib_sw_get(url);
}) })
.push(function (data) { .push(function (data) {
type = data.type; type = data.type;
...@@ -38,10 +39,10 @@ ...@@ -38,10 +39,10 @@
.push(function (evt) { .push(function (evt) {
return RSVP.all([ return RSVP.all([
evt.target.result, evt.target.result,
gadget.getDeclaredGadget('codeeditor')]); gadget.getDeclaredGadget('codeeditor')
]);
}) })
.push(function(data_list) { .push(function (data_list) {
//gadget.props.element.querySelector("form.crib-editor-save .content").value = data_list[0].responseText;
gadget.props.element.querySelector("form.crib-editor-save .mimetype").value = type; gadget.props.element.querySelector("form.crib-editor-save .mimetype").value = type;
return data_list[1].render({ return data_list[1].render({
key: CODE_CONTENT_KEY, key: CODE_CONTENT_KEY,
...@@ -64,7 +65,7 @@ ...@@ -64,7 +65,7 @@
return saveTextContent(this, undefined); return saveTextContent(this, undefined);
}) })
.allowPublicAcquisition("notifyChange", function () { .allowPublicAcquisition("notifyChange", function () {
return ; return;
}) })
.declareAcquiredMethod("crib_sw_get", "crib_sw_get") .declareAcquiredMethod("crib_sw_get", "crib_sw_get")
.declareAcquiredMethod("crib_sw_put", "crib_sw_put") .declareAcquiredMethod("crib_sw_put", "crib_sw_put")
...@@ -73,24 +74,24 @@ ...@@ -73,24 +74,24 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this; var gadget = this;
if (options === undefined) if (options === undefined)
options = {} options = {};
gadget.props.options = options; gadget.props.options = options;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (gadget.props.options.crib_enable_url !== undefined) { if (gadget.props.options.crib_enable_url !== undefined) {
return gadget.setSetting("site_editor_gadget_url", gadget.props.options.crib_enable_url); return gadget.setSetting("site_editor_gadget_url", gadget.props.options.crib_enable_url);
} }
return ; return;
}) })
.push(function () { .push(function () {
if (options.url !== undefined) { if (options.url !== undefined) {
gadget.props.element.querySelector("form.crib-editor-get .url").value = options.url; gadget.props.element.querySelector("form.crib-editor-get .url").value = options.url;
return getUrlTextContent(gadget, undefined, options.url) return getUrlTextContent(gadget, undefined, options.url);
} }
}) })
.push(function () { .push(function () {
return gadget.props.start_deferred.resolve(); return gadget.props.start_deferred.resolve();
}) });
}) })
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
...@@ -115,9 +116,9 @@ ...@@ -115,9 +116,9 @@
gadget.props.element.querySelector(".crib-editor-save"), gadget.props.element.querySelector(".crib-editor-save"),
'submit', 'submit',
false, false,
function (event) {saveTextContent(gadget, event)} function (event) {saveTextContent(gadget, event); }
)); ));
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}) });
}(window, rJS, loopEventListener, jIO)); }(window, rJS, loopEventListener, jIO));
\ No newline at end of file
/*global window, rJS, loopEventListener */ /*global window, rJS, loopEventListener, RSVP, console */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) { (function (window, rJS, loopEventListener) {
"use strict"; "use strict";
...@@ -12,13 +12,14 @@ ...@@ -12,13 +12,14 @@
promise_list = []; promise_list = [];
for (i = 0; i < url_list_length; i += 1) { for (i = 0; i < url_list_length; i += 1) {
promise_list.push(gadget.crib_sw_remove(url_list[i])); promise_list.push(gadget.crib_sw_remove(url_list[i]));
}; }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function() { .push(function () {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = "Removed " + url_list.length + " files at "+ Date () gadget.props.element.querySelector(".crib-mass-remove-status")
.textContent = "Removed " + url_list.length + " files at " + Date();
}) })
.fail(function(error) { .fail(function (error) {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = error; gadget.props.element.querySelector(".crib-mass-remove-status").textContent = error;
console.log(error); console.log(error);
}); });
...@@ -42,7 +43,7 @@ ...@@ -42,7 +43,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.props.start_deferred.resolve(); return gadget.props.start_deferred.resolve();
}) });
}) })
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
...@@ -57,9 +58,9 @@ ...@@ -57,9 +58,9 @@
gadget.props.element.querySelector(".crib-mass-remove"), gadget.props.element.querySelector(".crib-mass-remove"),
'submit', 'submit',
false, false,
function (event) {massRemoveFromCache(gadget, event)} function (event) {massRemoveFromCache(gadget, event); }
)); ));
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}) });
}(window, rJS, loopEventListener)); }(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS, loopEventListener */ /*global window, rJS, loopEventListener, RSVP, console, document, saveAs */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, JSZip, FileSaver) { (function (window, rJS, loopEventListener, JSZip, FileSaver) {
"use strict"; "use strict";
...@@ -15,25 +15,26 @@ ...@@ -15,25 +15,26 @@
function saveContentToZIP(gadget, event) { function saveContentToZIP(gadget, event) {
var path_to_save, path_to_save_length, application_id, crib_sw_gadget, var path_to_save, path_to_save_length, application_id, crib_sw_gadget,
jio_gadget, url_list = [], saved_number = 0, zip; jio_gadget, url_list = [], saved_number = 0, zip;
path_to_save = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-path').value path_to_save = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-path').value;
application_id = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-id').value application_id = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-id').value;
path_to_save_length = path_to_save.length; path_to_save_length = path_to_save.length;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getDeclaredGadget('jio_gadget')]); gadget.getDeclaredGadget('jio_gadget')
]);
}) })
.push(function (gadget_list) { .push(function (gadget_list) {
jio_gadget = gadget_list[0]; jio_gadget = gadget_list[0];
return gadget.crib_sw_allDocs({cached_only: true}); return gadget.crib_sw_allDocs({cached_only: true});
}) })
.push(function(data) { .push(function (data) {
var promise_list = [], var promise_list = [],
i, i_len, url; i, i_len, url;
if ( data.hasOwnProperty("urls") ) { if (data.hasOwnProperty("urls")) {
data = data.urls; data = data.urls;
} else { } else {
data = data data = data;
} }
if (Array.isArray(data)) { if (Array.isArray(data)) {
url_list = data; url_list = data;
...@@ -41,58 +42,60 @@ ...@@ -41,58 +42,60 @@
url_list = Object.keys(data); url_list = Object.keys(data);
} }
for (i = 0, i_len = url_list.length; i < i_len; i += 1) { for (i = 0, i_len = url_list.length; i < i_len; i += 1) {
url = new String(url_list[i]); url = String(url_list[i]);
if (url.indexOf(path_to_save) === 0) { if (url.indexOf(path_to_save) === 0) {
saved_number += 1; saved_number += 1;
promise_list.push(gadget.crib_sw_get(url)); promise_list.push(gadget.crib_sw_get(url));
}; }
}; }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function(response_list) { .push(function (response_list) {
var promise_list = [], var promise_list = [],
i, i_len, url, response, extension, zip; i, i_len, url, response, extension, zip;
zip = new JSZip(); zip = new JSZip();
for (i = 0, i_len = response_list.length; i < i_len; i += 1) { for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i]; response = response_list[i];
url = url_list[i].substr(path_to_save_length) url = url_list[i].substr(path_to_save_length);
if ( url.endsWith("//") ) { if (url.endsWith("//")) {
url = url.substr(0, url.length - 1); url = url.substr(0, url.length - 1);
} }
if ( url.endsWith("/./") ) { if (url.endsWith("/./")) {
url = url.substr(0, url.length - 2); url = url.substr(0, url.length - 2);
} }
if ( url.endsWith("/") ) { if (url.endsWith("/")) {
url = url + "index.html"; url = url + "index.html";
} }
if ( url.startsWith("./") ) { if (url.startsWith("./")) {
url = url.substr(1); url = url.substr(1);
} }
zip.file(url, response) zip.file(url, response);
}; }
return zip.generateAsync({type:"blob"}); return zip.generateAsync({type: "blob"});
}) })
.push(function(content) { .push(function (content) {
return saveAs(content, application_id) return saveAs(content, application_id);
}) })
.push(function() { .push(function () {
gadget.props.element.querySelector(".crib-save-to-zip-status").textContent = "Saved " + saved_number + " files at "+ Date () gadget.props.element.querySelector(".crib-save-to-zip-status")
.textContent = "Saved " + saved_number + " files at " + Date();
}) })
.push(console.log, console.log) .push(console.log, console.log);
} }
function loadContentFromZIP(gadget, event) { function loadContentFromZIP(gadget, event) {
var path_to_load, path_to_load_length, file_list, crib_sw_gadget, var path_to_load, path_to_load_length, file_list, crib_sw_gadget,
jio_gadget, url_list = [], file, url_number = 0; jio_gadget, url_list = [], file, url_number = 0;
path_to_load = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-path').value path_to_load = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-path').value;
file_list = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-file').files file_list = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-file').files;
if (file_list.length === 0) { if (file_list.length === 0) {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Please put a Zip at "+ Date () gadget.props.element.querySelector(".crib-load-from-zip-status")
return .textContent = "Please put a Zip at " + Date();
return;
} }
path_to_load_length = path_to_load.length; path_to_load_length = path_to_load.length;
file = file_list[0] file = file_list[0];
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return JSZip.loadAsync(file); return JSZip.loadAsync(file);
...@@ -102,42 +105,43 @@ ...@@ -102,42 +105,43 @@
zip.forEach(function (relativePath, zipEntry) { zip.forEach(function (relativePath, zipEntry) {
var end_url; var end_url;
url_number += 1; url_number += 1;
if ( zipEntry.dir ) { if (zipEntry.dir) {
return return;
} }
if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) { if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) {
end_url = path_to_load + "/" + relativePath end_url = path_to_load + "/" + relativePath;
} else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) { } else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) {
end_url = path_to_load + relativePath.substring(1); end_url = path_to_load + relativePath.substring(1);
} else { } else {
end_url = path_to_load + relativePath end_url = path_to_load + relativePath;
} }
promise_list.push( promise_list.push(
new RSVP.Queue(). new RSVP.Queue()
push(function () { .push(function () {
return zipEntry.async('blob'); return zipEntry.async('blob');
}) })
.push(function (result) { .push(function (result) {
if ( end_url.endsWith(".js") ) { if (end_url.endsWith(".js")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "application/javascript") result = result.slice(0, result.size, "application/javascript");
} else if ( end_url.endsWith(".html") ) { } else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html") result = result.slice(0, result.size, "text/html");
} else if ( end_url.endsWith(".css") ) { } else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css") result = result.slice(0, result.size, "text/css");
} }
return gadget.crib_sw_put(end_url, {blob: result}) return gadget.crib_sw_put(end_url, {blob: result});
})
)
}) })
return RSVP.all(promise_list) );
});
return RSVP.all(promise_list);
}) })
.push(function() { .push(function () {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Loaded " + url_number + " files at "+ Date () gadget.props.element.querySelector(".crib-load-from-zip-status")
.textContent = "Loaded " + url_number + " files at " + Date();
}) })
.push(console.log, console.log) .push(console.log, console.log);
} }
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
...@@ -161,7 +165,7 @@ ...@@ -161,7 +165,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.props.start_deferred.resolve(); return gadget.props.start_deferred.resolve();
}) });
}) })
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
...@@ -176,16 +180,16 @@ ...@@ -176,16 +180,16 @@
gadget.props.element.querySelector(".crib-save-to-zip"), gadget.props.element.querySelector(".crib-save-to-zip"),
'submit', 'submit',
false, false,
function (event) {saveContentToZIP(gadget, event)} function (event) {saveContentToZIP(gadget, event); }
)); ));
// promise to load content from ZIP // promise to load content from ZIP
promise_list.push(loopEventListener( promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-load-from-zip"), gadget.props.element.querySelector(".crib-load-from-zip"),
'submit', 'submit',
false, false,
function (event) {loadContentFromZIP(gadget, event)} function (event) {loadContentFromZIP(gadget, event); }
)); ));
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}) });
}(window, rJS, loopEventListener, JSZip, FileSaver)); }(window, rJS, loopEventListener, JSZip, FileSaver));
\ No newline at end of file
/*global window, rJS, loopEventListener */ /*global window, rJS, loopEventListener, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) { (function (window, rJS, loopEventListener) {
"use strict"; "use strict";
function setSiteGadgetUrl(gadget, event) { function setSiteGadgetUrl(gadget, event) {
var site_editor_gadget_url; var site_editor_gadget_url;
site_editor_gadget_url = gadget.props.element.querySelector('form.site-editor-gadget-url .url').value site_editor_gadget_url = gadget.props.element.querySelector('form.site-editor-gadget-url .url').value;
return gadget.setSetting("site_editor_gadget_url", site_editor_gadget_url) return gadget.setSetting("site_editor_gadget_url", site_editor_gadget_url)
.push(function () { .push(function () {
gadget.props.element.querySelector(".crib-site-save-status").textContent = "Saved " + site_editor_gadget_url + " files at "+ Date () gadget.props.element.querySelector(".crib-site-save-status")
}) .textContent = "Saved " + site_editor_gadget_url + " files at " + Date();
});
} }
rJS(window) rJS(window)
...@@ -34,12 +35,12 @@ ...@@ -34,12 +35,12 @@
return gadget.getSetting( return gadget.getSetting(
"site_editor_gadget_url", "site_editor_gadget_url",
getURL.protocol + "//" + getURL.host + "/crib-enable.html" getURL.protocol + "//" + getURL.host + "/crib-enable.html"
) );
}) })
.push(function (site_editor_gadget_url) { .push(function (site_editor_gadget_url) {
gadget.props.element.querySelector('form.site-editor-gadget-url .url').value = site_editor_gadget_url; gadget.props.element.querySelector('form.site-editor-gadget-url .url').value = site_editor_gadget_url;
return gadget.props.start_deferred.resolve(); return gadget.props.start_deferred.resolve();
}) });
}) })
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
...@@ -54,9 +55,9 @@ ...@@ -54,9 +55,9 @@
gadget.props.element.querySelector(".site-editor-gadget-url"), gadget.props.element.querySelector(".site-editor-gadget-url"),
'submit', 'submit',
false, false,
function (event) {setSiteGadgetUrl(gadget, event)} function (event) {setSiteGadgetUrl(gadget, event); }
)); ));
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}) });
}(window, rJS, loopEventListener)); }(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS, loopEventListener */ /*global window, rJS, loopEventListener, RSVP, console, document */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) { (function (window, rJS, loopEventListener) {
"use strict"; "use strict";
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
var url_list; var url_list;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.crib_sw_allDocs() return gadget.crib_sw_allDocs();
}) })
.push(function (data) { .push(function (data) {
var promise_list = [], var promise_list = [],
url; url;
if ( data.hasOwnProperty("urls") ) { if (data.hasOwnProperty("urls")) {
url_list = data.urls; url_list = data.urls;
} else { } else {
url_list = data url_list = data;
} }
for (url in url_list) { for (url in url_list) {
if (url_list.hasOwnProperty(url)) { if (url_list.hasOwnProperty(url)) {
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function(url_link_list) { .push(function (url_link_list) {
var contentsElement = gadget.props.element.querySelector('.crib-url-list-content tbody'), var contentsElement = gadget.props.element.querySelector('.crib-url-list-content tbody'),
footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'), footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'),
url_number = 0, cached_number = 0, url_number = 0, cached_number = 0,
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
var element; var element;
trElement = document.createElement('tr'); trElement = document.createElement('tr');
tdElement = document.createElement('td'); tdElement = document.createElement('td');
tdElement.innerHTML = (url_list[url].cached ? "<span>&#x2713;</span>" : "") tdElement.innerHTML = (url_list[url].cached ? "<span>&#x2713;</span>" : "");
trElement.appendChild(tdElement); trElement.appendChild(tdElement);
tdElement = document.createElement('td'); tdElement = document.createElement('td');
element = document.createElement('a'); element = document.createElement('a');
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
cached_number = url_list[url].cached ? cached_number + 1 : cached_number; cached_number = url_list[url].cached ? cached_number + 1 : cached_number;
url_number += 1; url_number += 1;
} }
}; }
while (footer_element.firstChild) { while (footer_element.firstChild) {
footer_element.removeChild(footer_element.firstChild); footer_element.removeChild(footer_element.firstChild);
} }
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
tdElement = document.createElement('td'); tdElement = document.createElement('td');
trElement.appendChild(tdElement); trElement.appendChild(tdElement);
footer_element.appendChild(trElement); footer_element.appendChild(trElement);
}) });
} }
rJS(window) rJS(window)
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this; var gadget = this;
if (options === undefined) if (options === undefined)
options = {} options = {};
gadget.props.options = options; gadget.props.options = options;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
}) })
.push(function () { .push(function () {
return gadget.props.start_deferred.resolve(); return gadget.props.start_deferred.resolve();
}) });
}) })
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
...@@ -112,8 +112,8 @@ ...@@ -112,8 +112,8 @@
gadget.props.element.querySelector(".crib-url-list-content"), gadget.props.element.querySelector(".crib-url-list-content"),
'submit', 'submit',
false, false,
function (event) {displayURLList(gadget, event)} function (event) {displayURLList(gadget, event); }
) );
});
}); });
})
}(window, rJS, loopEventListener)); }(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS */ /*global window, rJS, document, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) { (function (window, rJS, loopEventListener) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
}; };
}) })
.declareMethod("getCommandUrlFor", function(options) { .declareMethod("getCommandUrlFor", function (options) {
var prefix = '', var prefix = '',
result, result,
key; key;
...@@ -116,9 +116,9 @@ ...@@ -116,9 +116,9 @@
); );
} }
return { return {
url: MAIN_PAGE_PREFIX + "jio_" url: MAIN_PAGE_PREFIX + "jio_" +
+ base_portal_type base_portal_type +
+ "_" + args.page + ".html", "_" + args.page + ".html",
options: sub_options options: sub_options
}; };
}); });
...@@ -140,4 +140,4 @@ ...@@ -140,4 +140,4 @@
}); });
}); });
}(window, rJS)); }(window, rJS, loopEventListener));
\ No newline at end of file \ No newline at end of file
/*globals window, document, RSVP, rJS, /*jslint browser: true, indent: 2, maxlen: 80*/
location, console*/ /*globals RSVP, rJS,
/*jslint indent: 2, maxlen: 80*/ location, console, fetch, Promise*/
(function (window, document, RSVP, rJS, location, console, JSZip) { (function (window, document, RSVP, rJS, location, console, JSZip) {
"use strict"; "use strict";
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
} }
function getSetting(gadget, key, default_value) { function getSetting(gadget, key, default_value) {
if ( key === "site_editor_gadget_url" ) { if (key === "site_editor_gadget_url") {
return window.location.protocol + "//" + window.location.host + "/crib-enable.html" return window.location.protocol + "//" + window.location.host +
"/crib-enable.html";
} }
return default_value; return default_value;
} }
...@@ -24,41 +25,41 @@ ...@@ -24,41 +25,41 @@
zip.forEach(function (relativePath, zipEntry) { zip.forEach(function (relativePath, zipEntry) {
var end_url; var end_url;
url_number += 1; url_number += 1;
if ( zipEntry.dir ) { if (zipEntry.dir) {
return return;
} }
if ( !relativePath.startsWith(from_path) ) { if (!relativePath.startsWith(from_path)) {
return return;
} }
relativePath = relativePath.substring(from_path.length); relativePath = relativePath.substring(from_path.length);
if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) { if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) {
end_url = path_to_load + "/" + relativePath end_url = path_to_load + "/" + relativePath;
} else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) { } else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) {
end_url = path_to_load + relativePath.substring(1); end_url = path_to_load + relativePath.substring(1);
} else { } else {
end_url = path_to_load + relativePath end_url = path_to_load + relativePath;
} }
promise_list.push( promise_list.push(
new RSVP.Queue(). new RSVP.Queue()
push(function () { .push(function () {
return zipEntry.async('blob'); return zipEntry.async('blob');
}) })
.push(function (result) { .push(function (result) {
if ( end_url.endsWith(".js") ) { if (end_url.endsWith(".js")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "application/javascript") result = result.slice(0, result.size, "application/javascript");
} else if ( end_url.endsWith(".html") ) { } else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html") result = result.slice(0, result.size, "text/html");
} else if ( end_url.endsWith(".css") ) { } else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS // This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css") result = result.slice(0, result.size, "text/css");
} }
return crib_sw_gadget.put(end_url, {blob: result}) return crib_sw_gadget.put(end_url, {blob: result});
})
)
}) })
return RSVP.all(promise_list) );
});
return RSVP.all(promise_list);
} }
function loadContentFromZIPFile(gadget, options) { function loadContentFromZIPFile(gadget, options) {
...@@ -76,9 +77,11 @@ ...@@ -76,9 +77,11 @@
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
return loadZipIntoCrib(result_list[0], result_list[1], from_path, path_to_load); return loadZipIntoCrib(
result_list[0], result_list[1], from_path, path_to_load
);
}) })
.push(console.log, console.log) .push(console.log, console.log);
} }
...@@ -105,7 +108,7 @@ ...@@ -105,7 +108,7 @@
.push(function (zip) { .push(function (zip) {
return loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load); return loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load);
}) })
.push(console.log, console.log) .push(console.log, console.log);
} }
rJS(window) rJS(window)
...@@ -120,6 +123,6 @@ ...@@ -120,6 +123,6 @@
}) })
.allowPublicAcquisition("getSetting", function (argument_list) { .allowPublicAcquisition("getSetting", function (argument_list) {
return getSetting(this, argument_list[0], argument_list[1]); return getSetting(this, argument_list[0], argument_list[1]);
}) });
}(window, document, RSVP, rJS, location, console, JSZip)); }(window, document, RSVP, rJS, location, console, JSZip));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment