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) {
//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) {
document.querySelector('#status').textContent = statusMessage;
......@@ -52,7 +52,7 @@ function showCommands() {
}).then(function() {
// If the promise resolves, just display a success message.
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() {
......@@ -62,7 +62,7 @@ function showCommands() {
}).then(function() {
// 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.
}, setStatus); // If the promise rejects, then setStatus will be called with the error.
});
document.querySelector('#list-contents').addEventListener('click', function() {
......@@ -84,7 +84,7 @@ function showCommands() {
liElement.innerHTML = aElement.outerHTML;
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() {
......@@ -95,15 +95,15 @@ function showCommands() {
document.querySelector('#information').value = this.responseText;
}
);
})
});
document.querySelector('#save-path').value = document.location.origin;
document.querySelector('#save-contents').addEventListener('click', function() {
console.log('asking for the keys');
var path_to_save, path_to_save_length, application_id;
path_to_save = document.querySelector('#save-path').value
application_id = document.querySelector('#save-id').value
path_to_save_length = path_to_save.length
path_to_save = document.querySelector('#save-path').value;
application_id = document.querySelector('#save-id').value;
path_to_save_length = path_to_save.length;
sendMessage({
command: 'keys'
}).then(function(data) {
......@@ -116,43 +116,43 @@ function showCommands() {
[jio.put("/" + application_id + ".attachment/", {
// url: path_to_save
}),
jio.putAttachment("/", application_id, new Blob([JSON.stringify({url: path_to_save})],{type: "application/json"}))
jio.putAttachment("/", application_id, new Blob([JSON.stringify({url: path_to_save})],{type: "application/json"}))
]);
})
.push(function() {
var promise_list = [],
i, i_len, url;
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) {
promise_list.push(jIO.util.ajax({
'url': url,
dataType: "blob"
}));
}
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
var promise_list = [],
i, i_len, url, response, extension;
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i];
url = response.target.responseURL.substr(path_to_save_length)
extension = getExtension(url)
url = response.target.responseURL.substr(path_to_save_length);
extension = getExtension(url);
console.log("Pushing attachment " + url + " to " + path_to_save);
promise_list.push(
jio.putAttachment("/" + application_id + ".attachment/", btoa(url) + extension,
response.target.response
)
);
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(undefined, function(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;
......@@ -160,11 +160,11 @@ function showCommands() {
console.log('asking for the keys');
var url_list = [],
application_id;
application_id = document.querySelector('#load-id').value
application_id = document.querySelector('#load-id').value;
return new RSVP.Queue()
.push(function() {
console.log("put");
return jio.allAttachments("/" + application_id + ".attachment/")
return jio.allAttachments("/" + application_id + ".attachment/");
})
.push(function(response) {
var promise_list = [],
......@@ -173,21 +173,21 @@ function showCommands() {
if (response.hasOwnProperty(key)) {
extension = getExtension(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));
}
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
var promise_list = [],
i, i_len, url, index, response, location, location_len;
location = document.location.origin;
location_len = location.length
location_len = location.length;
console.log(url_list);
console.log(response_list);
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);
if (index != -1)
url = url.substr(index + location_len);
......@@ -195,7 +195,7 @@ function showCommands() {
command: 'add',
url: document.querySelector('#load-path').value + url,
information: response_list[i]
})
});
}
})
.push(undefined, function(error) {
......@@ -207,16 +207,11 @@ function showCommands() {
var url_list = document.querySelector('#mass-remove-list').value.match(/[^\r\n]+/g),
url_list_length = url_list.length,
i;
console.log(url_list)
for (i = 0; i < url_list_length; i += 1) {
console.log(url_list[i])
sendMessage({
command: 'delete',
url: url_list[i],
}).then(function() {
// 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.
url: url_list[i]
}); // 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*/
/*jslint indent: 2, maxlen: 80*/
(function (window, document, RSVP, rJS, Handlebars, console) {
(function (RSVP, rJS, Handlebars) {
"use strict";
function callCribSWGadget(gadget, method, param_list) {
......@@ -53,7 +53,7 @@
.push(function (crib_ide_gadget) {
return crib_ide_gadget.render();
});
})
});
}(window, document, RSVP, rJS, console));
\ No newline at end of file
}(RSVP, rJS, Handlebars));
\ No newline at end of file
......@@ -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) {
return RSVP.Queue()
.push(function () {
......@@ -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) {
var called = false;
return new RSVP.Queue()
.push(function () {
called = true;
return increaseLoadingCounter(gadget);
})
.push(function () {
return gadget.getDeclaredGadget("jio_gadget");
})
......@@ -116,19 +66,10 @@ function initHeaderOptions(gadget) {
return jio_gadget[method].apply(jio_gadget, param_list);
})
.push(function (result) {
return decreaseLoadingCounter(gadget)
.push(function () {
return result;
});
}, function (error) {
if (called) {
return decreaseLoadingCounter(gadget)
.push(function () {
throw error;
});
}
throw error;
});
return result;
}, function (error) {
throw error;
});
}
function displayErrorContent(gadget, error) {
......@@ -187,7 +128,7 @@ function initHeaderOptions(gadget) {
type: "indexeddb",
database: "setting"
});
})
})
.push(function () {
return setting_gadget.get("setting");
})
......@@ -274,26 +215,6 @@ function initHeaderOptions(gadget) {
.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) {
return g.getDeclaredGadget('router')
.push(function (router_gadget) {
......@@ -316,33 +237,7 @@ function initHeaderOptions(gadget) {
.allowPublicAcquisition("setSetting", function (argument_list) {
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) {
return this.getDeclaredGadget('router')
.push(function (router_gadget) {
......@@ -365,60 +260,6 @@ function initHeaderOptions(gadget) {
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) {
return callJioGadget(this, "createJio", param_list);
})
......@@ -487,21 +328,6 @@ function initHeaderOptions(gadget) {
// (ERP5 title by default + sidebar)
//initHeaderOptions(gadget);
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 () {
return gadget.getDeclaredGadget('router');
})
......@@ -522,10 +348,6 @@ function initHeaderOptions(gadget) {
.push(function (fragment) {
var element = gadget.props.content_element,
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
window.scrollTo(0, 0);
......@@ -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) {
return displayError(gadget, error);
});
......
/*global window, rJS, RSVP */
/*global window, rJS, RSVP, XMLHttpRequest, MessageChannel,
console, navigator, Blob
*/
/*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) {
"use strict";
(function (rJS, RSVP, jIO) {
"use strict";
/**
* Send request with XHR and return a promise. xhr.onload: The promise is
......@@ -20,10 +22,10 @@
*/
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
xhr.open(param.type || "GET", param.url, true);
xhr.addEventListener("load", function(e) {
xhr.addEventListener("load", function (e) {
var answer = {};
if (e.target.status >= 400) {
return reject(e);
......@@ -43,7 +45,7 @@
}
}
xhr.send();
}, function() {
}, function () {
xhr.abort();
});
}
......@@ -54,9 +56,9 @@
// 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
// a convenient wrapper.
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
var messageChannel = new MessageChannel();
messageChannel.port1.onmessage = function(event) {
messageChannel.port1.onmessage = function (event) {
console.log(event);
if (event.data.error) {
reject(event.data.error);
......@@ -83,25 +85,26 @@
return g.getElement()
.push(function (element) {
g.props.element = element;
});
});
})
.ready(function(gadget) {
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
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) {
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
navigator.serviceWorker.register('/sw.js', {scope: '/'}).then(
function(){
function () {
if (navigator.serviceWorker.controller) {
resolve();
} else {
reject("Please reload this page to allow Service Worker to control this page");
}
}).catch(function(error) {
reject(error);
});
})
.then(undefined, function (error) {
reject(error);
});
});
}
} else {
......@@ -115,17 +118,17 @@
* @params {Object} Not taken into account
* @return {} Return the data url of the document
*/
.declareMethod('allDocs', function(params) {
.declareMethod('allDocs', function (params) {
if (params && params.cached_only) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'keys'
});
});
}
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'allDocs'
});
......@@ -139,7 +142,7 @@
* @url {string} url of the document to retrieve
* @return {data_url} Return the data url of the document
*/
.declareMethod('get', function(url) {
.declareMethod('get', function (url) {
return new RSVP.Queue()
.push(function () {
return ajax({
......@@ -147,12 +150,12 @@
});
})
.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);
})
.push(function(e) {
.push(function (e) {
return e.target.result;
});
})
......@@ -165,17 +168,17 @@
* @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
*/
.declareMethod('put', function(url, parameter) {
.declareMethod('put', function (url, parameter) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'add',
url: url,
information: jIO.util.dataURItoBlob(parameter)
});
}).push(function() {
}).push(function () {
// 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();
}).fail(setStatus);
})
......@@ -186,9 +189,9 @@
* @url {string} url of the document to remove
* @return {}
*/
.declareMethod('remove', function(url) {
.declareMethod('remove', function (url) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'delete',
url: url
......@@ -196,4 +199,4 @@
});
});
}(window, rJS, RSVP, jIO));
\ No newline at end of file
}(rJS, RSVP, jIO));
\ No newline at end of file
/*global window, rJS, RSVP */
/*global window, rJS, RSVP, Blob, console */
/*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) {
"use strict";
(function (window, rJS, RSVP, jIO) {
"use strict";
function getStorageGadget(gadget) {
var storage_gadget, site_editor_gadget_url, getURL = window.location;
......@@ -20,9 +20,9 @@
"sandbox": "iframe",
"element": gadget.props.element.querySelector('div')
});
});
});
} else {
gadget.props.storage_gadget_url = url
gadget.props.storage_gadget_url = url;
return gadget.dropGadget("storage")
.push(function () {}, function () {})
.push(function () {
......@@ -33,18 +33,19 @@
"sandbox": "iframe",
"element": gadget.props.element.querySelector('div')
});
})
});
}
})
.push(undefined, function (e) {
// 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");
window.location.reload(false);
throw(e);
throw (e);
} else {
console.log(e);
throw(e);
throw (e);
}
});
}
......@@ -56,40 +57,39 @@
.push(function (element) {
var getURL = window.location;
g.props.element = element;
getURL.protocol + "//" + getURL.host + "/crib-enable.html"
});
});
})
.ready(function(gadget) {
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
return getStorageGadget(gadget);
})
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('allDocs', function(params) {
.declareMethod('allDocs', function (params) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.allDocs(params)
.push(function (storage_gadget) {
return storage_gadget.allDocs(params);
});
})
.declareMethod('get', function(url) {
.declareMethod('get', function (url) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.get(url)
.push(function (storage_gadget) {
return storage_gadget.get(url);
})
.push(function (result) {
return jIO.util.dataURItoBlob(result);
});
})
.declareMethod('put', function(url, parameter) {
.declareMethod('put', function (url, parameter) {
var blob, gadget = this;
if (parameter.blob !== undefined) {
blob = parameter.blob;
} else {
blob = new Blob(
[parameter.content],
{type: parameter.type,}
{type: parameter.type}
);
}
return RSVP.Queue()
......@@ -97,19 +97,19 @@
return RSVP.all([
getStorageGadget(gadget),
jIO.util.readBlobAsDataURL(blob)
]);
]);
})
.push(function (result_list) {
.push(function (result_list) {
return result_list[0].put(url, result_list[1].target.result);
})
.push(console.log, console.log)
;
})
.declareMethod('remove', function(url) {
.declareMethod('remove', function (url) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.remove(url)
.push(function (storage_gadget) {
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 */
/*global window, rJS, Handlebars, document, loopEventListener, RSVP */
(function (window, rJS, Handlebars, document, loopEventListener, RSVP) {
(function (rJS, Handlebars, loopEventListener, RSVP) {
"use strict";
/////////////////////////////////////////////////////////////////
......@@ -54,11 +54,6 @@
g.props.title_element = element.querySelector("h1");
});
})
/*
.ready(function (g) {
return g.render(g.stats.options);
})
*/
//////////////////////////////////////////////
// acquired methods
//////////////////////////////////////////////
......@@ -70,21 +65,6 @@
/////////////////////////////////////////////////////////////////
// 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 () {
if (this.stats.loaded) {
this.stats.loaded = false;
......@@ -97,28 +77,6 @@
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) {
var gadget = this,
page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "tools", "mass_remove"],
......@@ -126,8 +84,8 @@
gadget.stats.options = options;
page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page}))
})
promise_list.push(gadget.getUrlFor({page: page}));
});
// Handle main title
return new RSVP.Queue()
.push(function () {
......@@ -135,7 +93,7 @@
})
.push(function (link_list) {
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 @@
);
});
}(window, rJS, Handlebars, document, loopEventListener, RSVP));
\ No newline at end of file
}(rJS, Handlebars, loopEventListener, RSVP));
\ No newline at end of file
......@@ -26,8 +26,8 @@
promise_list = [];
page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page}))
})
promise_list.push(gadget.getUrlFor({page: page}));
});
// Handle main title
return new RSVP.Queue()
.push(function () {
......@@ -35,10 +35,10 @@
})
.push(function (link_list) {
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));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, jIO) {
"use strict";
......@@ -11,25 +11,26 @@
mimetype = gadget.props.element.querySelector("form.crib-editor-save .mimetype").value;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('codeeditor');
})
return gadget.getDeclaredGadget('codeeditor');
})
.push(function (code_editor_gadget) {
return code_editor_gadget.getContent();
return code_editor_gadget.getContent();
})
.push(function (data) {
content = data[CODE_CONTENT_KEY] || "";
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 ()
content = data[CODE_CONTENT_KEY] || "";
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();
});
}
function getUrlTextContent(gadget, event, url) {
var type;
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_get(url)
return gadget.crib_sw_get(url);
})
.push(function (data) {
type = data.type;
......@@ -38,33 +39,33 @@
.push(function (evt) {
return RSVP.all([
evt.target.result,
gadget.getDeclaredGadget('codeeditor')]);
gadget.getDeclaredGadget('codeeditor')
]);
})
.push(function(data_list) {
//gadget.props.element.querySelector("form.crib-editor-save .content").value = data_list[0].responseText;
.push(function (data_list) {
gadget.props.element.querySelector("form.crib-editor-save .mimetype").value = type;
return data_list[1].render({
key: CODE_CONTENT_KEY,
value: data_list[0],
mode: type
});
});
});
}
rJS(window)
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
});
})
.allowPublicAcquisition("notifySubmit", function () {
return saveTextContent(this, undefined);
})
.allowPublicAcquisition("notifyChange", function () {
return ;
return;
})
.declareAcquiredMethod("crib_sw_get", "crib_sw_get")
.declareAcquiredMethod("crib_sw_put", "crib_sw_put")
......@@ -73,24 +74,24 @@
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {}
options = {};
gadget.props.options = options;
return new RSVP.Queue()
.push(function () {
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 () {
if (options.url !== undefined) {
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 () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -115,9 +116,9 @@
gadget.props.element.querySelector(".crib-editor-save"),
'submit',
false,
function (event) {saveTextContent(gadget, event)}
function (event) {saveTextContent(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(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*/
(function (window, rJS, loopEventListener) {
"use strict";
......@@ -12,13 +12,14 @@
promise_list = [];
for (i = 0; i < url_list_length; i += 1) {
promise_list.push(gadget.crib_sw_remove(url_list[i]));
};
}
return RSVP.all(promise_list);
})
.push(function() {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = "Removed " + url_list.length + " files at "+ Date ()
.push(function () {
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;
console.log(error);
});
......@@ -31,7 +32,7 @@
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
});
})
.declareAcquiredMethod("crib_sw_remove", "crib_sw_remove")
.declareMethod('render', function (options) {
......@@ -42,7 +43,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -57,9 +58,9 @@
gadget.props.element.querySelector(".crib-mass-remove"),
'submit',
false,
function (event) {massRemoveFromCache(gadget, event)}
function (event) {massRemoveFromCache(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(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*/
(function (window, rJS, loopEventListener, JSZip, FileSaver) {
"use strict";
......@@ -15,84 +15,87 @@
function saveContentToZIP(gadget, event) {
var path_to_save, path_to_save_length, application_id, crib_sw_gadget,
jio_gadget, url_list = [], saved_number = 0, zip;
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
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;
path_to_save_length = path_to_save.length;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('jio_gadget')]);
gadget.getDeclaredGadget('jio_gadget')
]);
})
.push(function (gadget_list) {
jio_gadget = gadget_list[0];
return gadget.crib_sw_allDocs({cached_only: true});
})
.push(function(data) {
.push(function (data) {
var promise_list = [],
i, i_len, url;
if ( data.hasOwnProperty("urls") ) {
if (data.hasOwnProperty("urls")) {
data = data.urls;
} else {
data = data
data = data;
}
if (Array.isArray(data)) {
url_list = data;
} else {
url_list = Object.keys(data);
url_list = Object.keys(data);
}
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) {
saved_number += 1;
promise_list.push(gadget.crib_sw_get(url));
};
};
}
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
.push(function (response_list) {
var promise_list = [],
i, i_len, url, response, extension, zip;
zip = new JSZip();
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i];
url = url_list[i].substr(path_to_save_length)
if ( url.endsWith("//") ) {
url = url_list[i].substr(path_to_save_length);
if (url.endsWith("//")) {
url = url.substr(0, url.length - 1);
}
if ( url.endsWith("/./") ) {
if (url.endsWith("/./")) {
url = url.substr(0, url.length - 2);
}
if ( url.endsWith("/") ) {
if (url.endsWith("/")) {
url = url + "index.html";
}
if ( url.startsWith("./") ) {
if (url.startsWith("./")) {
url = url.substr(1);
}
zip.file(url, response)
};
return zip.generateAsync({type:"blob"});
zip.file(url, response);
}
return zip.generateAsync({type: "blob"});
})
.push(function(content) {
return saveAs(content, application_id)
.push(function (content) {
return saveAs(content, application_id);
})
.push(function() {
gadget.props.element.querySelector(".crib-save-to-zip-status").textContent = "Saved " + saved_number + " files at "+ Date ()
.push(function () {
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) {
var path_to_load, path_to_load_length, file_list, crib_sw_gadget,
jio_gadget, url_list = [], file, url_number = 0;
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
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;
if (file_list.length === 0) {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Please put a Zip at "+ Date ()
return
gadget.props.element.querySelector(".crib-load-from-zip-status")
.textContent = "Please put a Zip at " + Date();
return;
}
path_to_load_length = path_to_load.length;
file = file_list[0]
file = file_list[0];
return new RSVP.Queue()
.push(function () {
return JSZip.loadAsync(file);
......@@ -102,42 +105,43 @@
zip.forEach(function (relativePath, zipEntry) {
var end_url;
url_number += 1;
if ( zipEntry.dir ) {
return
if (zipEntry.dir) {
return;
}
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("/")) {
end_url = path_to_load + relativePath.substring(1);
} else {
end_url = path_to_load + relativePath
end_url = path_to_load + relativePath;
}
promise_list.push(
new RSVP.Queue().
push(function () {
new RSVP.Queue()
.push(function () {
return zipEntry.async('blob');
})
.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
result = result.slice(0, result.size, "application/javascript")
} else if ( end_url.endsWith(".html") ) {
result = result.slice(0, result.size, "application/javascript");
} else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html")
} else if ( end_url.endsWith(".css") ) {
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// 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() {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Loaded " + url_number + " files at "+ Date ()
.push(function () {
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)
.ready(function (g) {
......@@ -146,7 +150,7 @@
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
});
})
.declareAcquiredMethod("crib_sw_allDocs", "crib_sw_allDocs")
.declareAcquiredMethod("crib_sw_get", "crib_sw_get")
......@@ -161,7 +165,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -176,16 +180,16 @@
gadget.props.element.querySelector(".crib-save-to-zip"),
'submit',
false,
function (event) {saveContentToZIP(gadget, event)}
function (event) {saveContentToZIP(gadget, event); }
));
// promise to load content from ZIP
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-load-from-zip"),
'submit',
false,
function (event) {loadContentFromZIP(gadget, event)}
function (event) {loadContentFromZIP(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(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*/
(function (window, rJS, loopEventListener) {
"use strict";
function setSiteGadgetUrl(gadget, event) {
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)
.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)
......@@ -19,7 +20,7 @@
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
});
})
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
......@@ -34,12 +35,12 @@
return gadget.getSetting(
"site_editor_gadget_url",
getURL.protocol + "//" + getURL.host + "/crib-enable.html"
)
);
})
.push(function (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();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -54,9 +55,9 @@
gadget.props.element.querySelector(".site-editor-gadget-url"),
'submit',
false,
function (event) {setSiteGadgetUrl(gadget, event)}
function (event) {setSiteGadgetUrl(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(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*/
(function (window, rJS, loopEventListener) {
"use strict";
......@@ -7,24 +7,24 @@
var url_list;
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_allDocs()
return gadget.crib_sw_allDocs();
})
.push(function (data) {
var promise_list = [],
url;
if ( data.hasOwnProperty("urls") ) {
url_list = data.urls;
if (data.hasOwnProperty("urls")) {
url_list = data.urls;
} else {
url_list = data
url_list = data;
}
for (url in url_list) {
if (url_list.hasOwnProperty(url)) {
promise_list.push(gadget.getUrlFor({page: 'editor', url: url}));
promise_list.push(gadget.getUrlFor({page: 'editor', url: url}));
}
}
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'),
footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'),
url_number = 0, cached_number = 0,
......@@ -40,7 +40,7 @@
var element;
trElement = document.createElement('tr');
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);
tdElement = document.createElement('td');
element = document.createElement('a');
......@@ -60,7 +60,7 @@
cached_number = url_list[url].cached ? cached_number + 1 : cached_number;
url_number += 1;
}
};
}
while (footer_element.firstChild) {
footer_element.removeChild(footer_element.firstChild);
}
......@@ -74,24 +74,24 @@
tdElement = document.createElement('td');
trElement.appendChild(tdElement);
footer_element.appendChild(trElement);
})
});
}
rJS(window)
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
});
})
.declareAcquiredMethod("crib_sw_allDocs", "crib_sw_allDocs")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {}
options = {};
gadget.props.options = options;
return new RSVP.Queue()
.push(function () {
......@@ -99,7 +99,7 @@
})
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -112,8 +112,8 @@
gadget.props.element.querySelector(".crib-url-list-content"),
'submit',
false,
function (event) {displayURLList(gadget, event)}
)
function (event) {displayURLList(gadget, event); }
);
});
})
});
}(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS */
/*global window, rJS, document, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) {
(function (window, rJS, loopEventListener) {
"use strict";
var gadget_klass = rJS(window),
......@@ -54,7 +54,7 @@
};
})
.declareMethod("getCommandUrlFor", function(options) {
.declareMethod("getCommandUrlFor", function (options) {
var prefix = '',
result,
key;
......@@ -116,9 +116,9 @@
);
}
return {
url: MAIN_PAGE_PREFIX + "jio_"
+ base_portal_type
+ "_" + args.page + ".html",
url: MAIN_PAGE_PREFIX + "jio_" +
base_portal_type +
"_" + args.page + ".html",
options: sub_options
};
});
......@@ -140,4 +140,4 @@
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, loopEventListener));
\ No newline at end of file
/*globals window, document, RSVP, rJS,
location, console*/
/*jslint indent: 2, maxlen: 80*/
/*jslint browser: true, indent: 2, maxlen: 80*/
/*globals RSVP, rJS,
location, console, fetch, Promise*/
(function (window, document, RSVP, rJS, location, console, JSZip) {
"use strict";
......@@ -13,8 +13,9 @@
}
function getSetting(gadget, key, default_value) {
if ( key === "site_editor_gadget_url" ) {
return window.location.protocol + "//" + window.location.host + "/crib-enable.html"
if (key === "site_editor_gadget_url") {
return window.location.protocol + "//" + window.location.host +
"/crib-enable.html";
}
return default_value;
}
......@@ -24,41 +25,41 @@
zip.forEach(function (relativePath, zipEntry) {
var end_url;
url_number += 1;
if ( zipEntry.dir ) {
return
if (zipEntry.dir) {
return;
}
if ( !relativePath.startsWith(from_path) ) {
return
if (!relativePath.startsWith(from_path)) {
return;
}
relativePath = relativePath.substring(from_path.length);
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("/")) {
end_url = path_to_load + relativePath.substring(1);
} else {
end_url = path_to_load + relativePath
end_url = path_to_load + relativePath;
}
promise_list.push(
new RSVP.Queue().
push(function () {
new RSVP.Queue()
.push(function () {
return zipEntry.async('blob');
})
.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
result = result.slice(0, result.size, "application/javascript")
} else if ( end_url.endsWith(".html") ) {
result = result.slice(0, result.size, "application/javascript");
} else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html")
} else if ( end_url.endsWith(".css") ) {
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// 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) {
......@@ -73,12 +74,14 @@
return RSVP.all([
gadget.getDeclaredGadget('crib_sw_gadget'),
JSZip.loadAsync(file_list[0])
]);
]);
})
.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);
}
......@@ -95,17 +98,17 @@
return fetch(zip_url)
.then(function (response) { // 2) filter on 200 OK
if (response.status === 200 || response.status === 0) {
return Promise.resolve(response.blob());
return Promise.resolve(response.blob());
} else {
return Promise.reject(new Error(response.statusText));
return Promise.reject(new Error(response.statusText));
}
});
});
})
.push(JSZip.loadAsync)
.push(function (zip) {
return loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load);
})
.push(console.log, console.log)
.push(console.log, console.log);
}
rJS(window)
......@@ -120,6 +123,6 @@
})
.allowPublicAcquisition("getSetting", function (argument_list) {
return getSetting(this, argument_list[0], argument_list[1]);
})
});
}(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