Commit 19e01195 authored by Romain Courteaud's avatar Romain Courteaud Committed by Jérome Perrin

Add built files to ease usage.

parent 7da5424f
...@@ -12,4 +12,3 @@ outputJSON.json ...@@ -12,4 +12,3 @@ outputJSON.json
trace*.xls trace*.xls
npm-debug.log npm-debug.log
node_modules/ node_modules/
dream/platform/static/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create Document</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="create_document.js" type="text/javascript"></script>
</head>
<body>
<form class="import_form">
<input id="dream_import" type="file" required=""
name="dream_import">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-plus ui-btn-icon-right">Import</button>
</form>
</body>
</html>
/*global console, rJS, RSVP, FileReader */
(function(window, rJS, RSVP, FileReader) {
"use strict";
function promiseEventListener(target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function(evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
}
function promiseReadAsText(file) {
return new RSVP.Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
resolve(evt.target.result);
};
reader.onerror = function(evt) {
reject(evt);
};
reader.readAsText(file);
});
}
rJS(window).declareAcquiredMethod("aq_post", "jio_post").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayThisDocument", "whoWantToDisplayThisDocument").ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareMethod("startService", function() {
var gadget = this, json_data, name;
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("import_form")[0], "submit", false);
}).push(function(evt) {
// Prevent double click
gadget.props.element.getElementsByClassName("ui-btn")[0].disabled = true;
var file = evt.target.dream_import.files[0];
name = file.name;
return promiseReadAsText(file);
}).push(function(json) {
var now = new Date();
json_data = json;
// Create jIO document
return gadget.aq_post({
title: name,
type: "Dream",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()
});
}).push(function(jio_document) {
// Add JSON as attachment
return gadget.aq_putAttachment({
_id: jio_document.id,
_attachment: "body.json",
_data: json_data,
_mimetype: "application/json"
});
}).push(function(result) {
return gadget.whoWantToDisplayThisDocument(result.id);
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
});
})(window, rJS, RSVP, FileReader);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Debug JSON</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script>
<script src="debug_json.js" type="text/javascript"></script>
</head>
<body>
<label for="json_input">Input</label>
<textarea spellcheck="false" rows="20" name="json_input" class="json_input"></textarea>
<label for="json_output">Output</label>
<textarea spellcheck="false" rows="20" name="json_output" class="json_output"></textarea>
</body>
</html>
/*global console, rJS, RSVP, initDocumentPageMixin */
(function(window, rJS, RSVP, initDocumentPageMixin) {
"use strict";
var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass);
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareMethod("render", function(options) {
var gadget = this;
this.props.jio_key = options.id;
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
}), gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "simulation.json"
}) ]);
}).push(function(result_list) {
gadget.props.element.querySelector(".json_input").textContent = result_list[0];
gadget.props.element.querySelector(".json_output").textContent = result_list[1];
});
});
})(window, rJS, RSVP, initDocumentPageMixin);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Document List</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template">
<ul data-role="listview" data-inset="true" class="document-listview">
{{#documentlist}}
<li><a href="{{link}}">{{title}}</a></li>
{{/documentlist}}
</ul>
</script>
<script src="document_list.js" type="text/javascript"></script>
</head>
<body>
<section class="document_list"></section>
</body>
</html>
/*global console, rJS, RSVP, Handlebars */
/*jslint nomen: true */
(function(window, rJS, RSVP, Handlebars) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("table-template").innerHTML, table_template = Handlebars.compile(source);
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_allDocs", "allDocs").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayThisPage", "whoWantToDisplayThisPage").declareAcquiredMethod("whoWantToDisplayThisDocument", "whoWantToDisplayThisDocument").declareMethod("render", function(options) {
var gadget = this;
return gadget.aq_allDocs({
select_list: [ "title", "modified" ]
}).push(function(document_list) {
var result_list = [ gadget.whoWantToDisplayThisPage("create_document") ], doc, i;
for (i = 0; i < document_list.data.total_rows; i += 1) {
doc = document_list.data.rows[i];
result_list.push(RSVP.all([ gadget.whoWantToDisplayThisDocument(doc.id), doc.value.title, doc.value.modified ]));
}
return RSVP.all(result_list);
}).push(function(document_list) {
// Create new doc if nothing exists
if (document_list.length === 1) {
return gadget.pleaseRedirectMyHash(document_list[0]);
}
var i, parameter_list = [], doc;
for (i = 1; i < document_list.length; i += 1) {
doc = document_list[i];
parameter_list[i - 1] = {
link: doc[0],
title: doc[1] + " (" + doc[2] + ")"
};
}
// gadget.props.element.querySelector('a').href = document_list[0];
gadget.props.element.querySelector(".document_list").innerHTML = table_template({
documentlist: parameter_list
});
});
}).declareMethod("getNavigationList", function() {
return this.whoWantToDisplayThisPage("create_document").push(function(url) {
return [ {
title: "New Document",
link: url
} ];
});
});
})(window, rJS, RSVP, Handlebars);
\ No newline at end of file
/*global console, rJS, RSVP */
(function(window, rJS, RSVP) {
"use strict";
window.initDocumentPageMixin = function(gadget_klass) {
gadget_klass.declareAcquiredMethod("whoWantToDisplayThisDocumentPage", "whoWantToDisplayThisDocumentPage").declareMethod("getNavigationList", function() {
var key = this.props.jio_key, gadget = this;
return new RSVP.Queue().push(function() {
// XXX Conditional simulation menu
return RSVP.all([ gadget.whoWantToDisplayThisDocumentPage("edit_table", key), gadget.whoWantToDisplayThisDocumentPage("run_simulation", key), gadget.whoWantToDisplayThisDocumentPage("manage_document", key), gadget.whoWantToDisplayThisDocumentPage("debug_json", key) ]);
}).push(function(result_list) {
return [ {
link: result_list[0],
title: "Edit table"
}, {
link: result_list[1],
title: "Run simulation"
}, {
link: result_list[2],
title: "Manage document"
}, {
link: result_list[3],
title: "Debug JSON"
} ];
});
});
};
})(window, rJS, RSVP);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Edit table</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script>
<script src="edit_table.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="../handsontable/index.html"
data-gadget-scope="tableeditor"></div>
</body>
</html>
/*global console, rJS, RSVP, initDocumentPageMixin */
(function(window, rJS, RSVP, initDocumentPageMixin) {
"use strict";
var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass);
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareMethod("render", function(options) {
var jio_key = options.id, gadget = this;
gadget.props.jio_key = jio_key;
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.aq_getAttachment({
_id: jio_key,
_attachment: "body.json"
}), gadget.getDeclaredGadget("tableeditor") ]);
}).push(function(result_list) {
return result_list[1].render(JSON.stringify(JSON.parse(result_list[0]).shift_spreadsheet));
});
}).declareMethod("startService", function() {
return this.getDeclaredGadget("tableeditor").push(function(tableeditor) {
return tableeditor.startService();
});
});
})(window, rJS, RSVP, initDocumentPageMixin);
\ No newline at end of file
@media (min-width:35em){.jqm-navmenu-panel.ui-panel-closed{visibility:visible!important;width:17em;-webkit-transition:none!important;-moz-transition:none!important;transition:none!important;-webkit-transform:none!important;-moz-transform:none!important;transform:none!important;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;height:100%;position:absolute;display:block}.ui-panel-page-content-open{width:auto}.ui-panel-page-content-open.ui-panel-page-content-position-left{margin-right:17em}.ui-panel-dismiss,.menu_link{display:none!important}.gadget_container,header{margin-left:17em}.close-entry{display:none!important}.gadget_container{padding:1em}}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dream Simulation</title>
<link rel="stylesheet" href="../lib/jquerymobile.css">
<link rel="stylesheet" href="index.css" />
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<script id="navigation-template" type="text/x-handlebars-template">
<ul data-role="listview">
<li data-icon="delete" class="close-entry"><a href="#" data-rel="close">Close menu</a></li>
{{#navigationlist}}
<li><a href="{{link}}">{{title}}</a></li>
{{/navigationlist}}
</ul>
</script>
</head>
<body>
<!-- ID are bad, but required for JQM panel -->
<div class="jqm-navmenu-panel"
data-role="panel"
id="leftpanel"
data-display="overlay"
data-position="left"
data-theme="b">
</div>
<header data-role="header">
<a href="#leftpanel" class="menu_link">Menu</a>
<h1>Dream Simulation</h1>
<a class="home_link ui-btn ui-icon-home ui-btn-icon-left" data-icon="home">Home</a>
</header>
<article class="gadget_container"></article>
<aside>
<section data-gadget-url="../jio_bridge/index.html"
data-gadget-scope="jio"
data-gadget-sandbox="public"></section>
</aside>
</body>
</html>
/*global console, jQuery, rJS, RSVP, alert, Handlebars */
/*jslint nomen: true */
(function(window, $, rJS, RSVP, Handlebars) {
"use strict";
/////////////////////////////////////////////////////////////////
// Desactivate jQuery Mobile URL management
/////////////////////////////////////////////////////////////////
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
var navigation_template;
rJS(window).declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").allowPublicAcquisition("allDocs", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.allDocs.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_ajax", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.ajax.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_post", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_remove", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_get", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.get.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_putAttachment", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_getAttachment", function(param_list) {
return this.getDeclaredGadget("jio").push(function(jio_gadget) {
return jio_gadget.getAttachment.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("whoWantToDisplayHome", function(param_list) {
// Hey, I want to display some URL
return this.aq_pleasePublishMyState({});
}).allowPublicAcquisition("whoWantToDisplayThisPage", function(param_list) {
// Hey, I want to display some URL
return this.aq_pleasePublishMyState({
page: param_list[0]
});
}).allowPublicAcquisition("whoWantToDisplayThisDocument", function(param_list) {
// Hey, I want to display some jIO document
return this.aq_pleasePublishMyState({
page: "edit_table",
id: param_list[0]
});
}).allowPublicAcquisition("whoWantToDisplayThisDocumentPage", function(param_list) {
// Hey, I want to display some jIO document
return this.aq_pleasePublishMyState({
page: param_list[0],
id: param_list[1]
});
}).ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).ready(function(g) {
return g.aq_pleasePublishMyState({}).push(function(link) {
g.props.element.getElementsByClassName("home_link")[0].href = link;
});
}).ready(function(g) {
var jio_gadget;
return g.getDeclaredGadget("jio").push(function(gadget) {
jio_gadget = gadget;
return jio_gadget.createJio({
type: "local",
username: "dream",
applicationname: "dream"
});
}).push(function() {
// XXX Hardcoded relative URL
return jio_gadget.ajax({
url: "../../getConfigurationDict"
});
}).push(function(evt) {
g.props.configuration_dict = JSON.parse(evt.target.responseText);
});
}).ready(function(g) {
if (navigation_template === undefined) {
// XXX Only works as root gadget
var source = document.getElementById("navigation-template").innerHTML;
navigation_template = Handlebars.compile(source);
}
}).declareMethod("render", function(options) {
var gadget = this, page_gadget, element = gadget.props.element.getElementsByClassName("gadget_container")[0];
if (options.page === undefined) {
// Redirect to the about page
return gadget.aq_pleasePublishMyState({
page: "document_list"
}).push(gadget.pleaseRedirectMyHash.bind(gadget));
}
return gadget.declareGadget(options.page + ".html").push(function(g) {
page_gadget = g;
if (page_gadget.render !== undefined) {
return page_gadget.render(options);
}
}).push(function() {
var navigation_list = [];
if (page_gadget.getNavigationList !== undefined) {
navigation_list = page_gadget.getNavigationList();
}
return RSVP.all([ page_gadget.getTitle(), page_gadget.getElement(), navigation_list ]);
}).push(function(result_list) {
var title = result_list[0], page_element = result_list[1], navigation_list = result_list[2], panel = gadget.props.element.querySelector("#leftpanel");
gadget.props.element.querySelector("header h1").textContent = title;
while (panel.firstChild) {
panel.removeChild(panel.firstChild);
}
panel.innerHTML = navigation_template({
navigationlist: navigation_list
});
// XXX JQuery mobile
$(panel).trigger("create");
// Append in the DOM at the end to reduce flickering and reduce DOM
// modifications
// Clear the previous rendering
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(page_element);
$(element).trigger("create");
// XXX RenderJS hack to start sub gadget services
// Only work if this gadget has no parent.
if (page_gadget.startService !== undefined) {
return page_gadget.startService();
}
});
});
})(window, jQuery, rJS, RSVP, Handlebars);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Manage document</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script>
<script src="manage_document.js" type="text/javascript"></script>
</head>
<body>
<a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a>
<form class="delete_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-delete ui-btn-icon-right">Delete</button>
</form>
</body>
</html>
/*global console, rJS, RSVP, initDocumentPageMixin */
(function(window, rJS, RSVP, initDocumentPageMixin) {
"use strict";
function datatouri(data, mime_type) {
var result = "data:";
if (mime_type !== undefined) {
result += mime_type;
}
return result + ";base64," + window.btoa(data);
}
function promiseEventListener(target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function(evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
}
var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass);
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_remove", "jio_remove").declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_get", "jio_get").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayHome", "whoWantToDisplayHome").declareMethod("render", function(options) {
this.props.jio_key = options.id;
var gadget = this;
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.aq_get({
_id: options.id
}), gadget.aq_getAttachment({
_id: options.id,
_attachment: "body.json"
}) ]);
}).push(function(result_list) {
var export_link = gadget.props.element.querySelector(".export_link");
export_link.download = result_list[0].data.title;
export_link.href = datatouri(result_list[1], "application/json");
});
}).declareMethod("startService", function() {
var gadget = this;
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("delete_form")[0], "submit", false);
}).push(function() {
// Prevent double click
gadget.props.element.getElementsByClassName("ui-btn")[0].disabled = true;
// Delete jIO document
return gadget.aq_remove({
_id: gadget.props.jio_key
});
}).push(function(result) {
return gadget.whoWantToDisplayHome();
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
});
})(window, rJS, RSVP, initDocumentPageMixin);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Run Simulation</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script>
<script src="run_simulation.js" type="text/javascript"></script>
</head>
<body>
<form class="run_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-refresh ui-btn-icon-right">Run Simulation</button>
</form>
</body>
</html>
/*global console, rJS, RSVP, initDocumentPageMixin, jQuery */
(function(window, rJS, RSVP, initDocumentPageMixin, $) {
"use strict";
function promiseEventListener(target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function(evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
}
var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass);
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareAcquiredMethod("aq_ajax", "jio_ajax").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayThisDocumentPage", "whoWantToDisplayThisDocumentPage").declareMethod("render", function(options) {
this.props.jio_key = options.id;
}).declareMethod("startService", function() {
var gadget = this;
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("run_form")[0], "submit", false);
}).push(function() {
// Prevent double click
gadget.props.element.getElementsByClassName("ui-btn")[0].disabled = true;
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
});
}).push(function(body_json) {
$.mobile.loading("show");
// XXX Hardcoded relative URL
return gadget.aq_ajax({
url: "../../runSimulation",
type: "POST",
data: body_json,
headers: {
"Content-Type": "application/json"
}
});
}).push(undefined, function(error) {
// Always drop the loader
$.mobile.loading("hide");
throw error;
}).push(function(evt) {
$.mobile.loading("hide");
var json_data = JSON.parse(evt.target.responseText);
if (json_data.success !== true) {
throw new Error(json_data.error);
}
return gadget.aq_putAttachment({
_id: gadget.props.jio_key,
_attachment: "simulation.json",
_data: JSON.stringify(json_data.data, null, 2),
_mimetype: "application/json"
});
}).push(function(result) {
return gadget.whoWantToDisplayThisDocumentPage("debug_json", gadget.props.jio_key);
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
});
})(window, rJS, RSVP, initDocumentPageMixin, jQuery);
\ No newline at end of file
/*global jQuery, rJS, window, JSON, RSVP */
(function(window, $, rJS, JSON, RSVP) {
"use strict";
rJS(window).declareMethod("render", function(content) {
var data = JSON.parse(content);
return this.getElement().push(function(element) {
$(element).find(".table-container").handsontable({
data: data,
minSpareRows: 1,
stretchH: "all"
});
});
}).declareMethod("getData", function() {
return this.getElement().push(function(element) {
var data = $(element).find(".table-container").handsontable("getData");
return JSON.stringify(data);
});
}).declareMethod("startService", function() {
var gadget_element;
return this.getElement().push(function(element) {
gadget_element = element;
$(element).find(".table-container").handsontable("render");
}).push(function() {
// Infinite wait, until cancelled
return new RSVP.defer().promise;
}).push(undefined, function(error) {
$(gadget_element).find(".table-container").handsontable("destroy");
throw error;
});
});
})(window, jQuery, rJS, JSON, RSVP);
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../lib/handsontable.css">
<script src="../lib/jquery.js"></script>
<script src="../lib/rsvp.min.js"></script>
<script src="../lib/renderjs.min.js"></script>
<script src="../lib/handsontable.js"></script>
<script src="handsontable.js"></script>
</head>
<body>
<div class="table-container"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../lib/qunit.css">
<script src="../lib/rsvp.min.js"></script>
<script src="../lib/renderjs.min.js"></script>
<script src="../lib/qunit.js"></script>
<script src="../lib/jquery.js"></script>
<script src="test.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
/*global asyncTest, rJS, JSON, QUnit, jQuery*/
(function(asyncTest, rJS, JSON, QUnit, $) {
"use strict";
var start = QUnit.start, stop = QUnit.stop, test = QUnit.test, equal = QUnit.equal, sample = JSON.stringify([ [ "row1", "data11", "data12", "data13" ], [ "row2", "data21", "data22", "data23" ], [ "row3", "data31", "data32", "data33" ] ]);
QUnit.config.testTimeout = 5e3;
rJS(window).ready(function(g) {
test("data output is equal to input", function() {
var hstable_gadget;
stop();
g.declareGadget("./index.html", {
element: document.querySelector("#qunit-fixture")
}).then(function(new_gadget) {
hstable_gadget = new_gadget;
return hstable_gadget.render(sample);
}).then(function() {
return hstable_gadget.getData();
}).then(function(data) {
equal(data, sample);
}).always(start);
});
test("the table is displayed", function() {
var hstable_gadget;
stop();
g.declareGadget("./index.html", {
element: document.querySelector("#qunit-fixture")
}).then(function(new_gadget) {
hstable_gadget = new_gadget;
return hstable_gadget.render(sample);
}).then(function() {
var rows = $("table tbody tr");
equal(rows.length, 3);
equal(rows[0].childNodes.length, 4);
equal(rows[0].childNodes[2].innerHTML, "data12");
}).always(start);
});
});
})(asyncTest, rJS, JSON, QUnit, jQuery);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Jio Gadget</title>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/URI.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<!-- custom script -->
<script src="jiogadget.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
/*global rJS, jIO, console */
(function(rJS, jIO) {
"use strict";
rJS(window).ready(function(gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
}).declareMethod("createJio", function(jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
}).declareMethod("ajax", function() {
return jIO.util.ajax.apply(this, arguments);
}).declareMethod("allDocs", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.allDocs.apply(storage, arguments);
}).declareMethod("get", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.get.apply(storage, arguments);
}).declareMethod("remove", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.remove.apply(storage, arguments);
}).declareMethod("getAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.getAttachment.apply(storage, arguments).then(function(response) {
return jIO.util.readBlobAsText(response.data);
}).then(function(lala) {
return lala.target.result;
});
}).declareMethod("putAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.putAttachment.apply(storage, arguments);
}).declareMethod("post", function() {
// XXX set modified value
var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments);
});
})(rJS, jIO);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/**
* Handsontable 0.10.5
* Handsontable is a simple jQuery plugin for editable tables with basic copy-paste compatibility with Excel and Google Docs
*
* Copyright 2012, Marcin Warpechowski
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Mon Mar 31 2014 14:19:47 GMT+0200 (CEST)
*/
.handsontable {
position: relative;
}
.handsontable.htAutoColumnSize {
visibility: hidden;
left: 0;
position: absolute;
top: 0;
}
.handsontable table,
.handsontable tbody,
.handsontable thead,
.handsontable td,
.handsontable th,
.handsontable div {
box-sizing: content-box;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
}
.handsontable table.htCore {
border-collapse: separate;
/*it must be separate, otherwise there are offset miscalculations in WebKit: http://stackoverflow.com/questions/2655987/border-collapse-differences-in-ff-and-webkit*/
position: relative;
/*this actually only changes appearance of user selection - does not make text unselectable
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
-ms-user-select: none;
/*user-select: none; /*no browser supports unprefixed version*/
border-spacing: 0;
margin: 0;
border-width: 0;
table-layout: fixed;
width: 0;
outline-width: 0;
/* reset bootstrap table style. for more info see: https://github.com/warpech/jquery-handsontable/issues/224 */
max-width: none;
max-height: none;
}
.handsontable col {
width: 50px;
}
.handsontable col.rowHeader {
width: 50px;
}
.handsontable th,
.handsontable td {
border-right: 1px solid #CCC;
border-bottom: 1px solid #CCC;
height: 22px;
empty-cells: show;
line-height: 21px;
padding: 0 4px 0 4px;
/* top, bottom padding different than 0 is handled poorly by FF with HTML5 doctype */
background-color: #FFF;
vertical-align: top;
overflow: hidden;
outline-width: 0;
white-space: pre-line;
/* preserve new line character in cell */
}
.handsontable td.htInvalid {
-webkit-transition: background 0.75s ease;
transition: background 0.75s ease;
background-color: #ff4c42;
}
.handsontable th:last-child {
/*Foundation framework fix*/
border-right: 1px solid #CCC;
border-bottom: 1px solid #CCC;
}
.handsontable tr:first-child th.htNoFrame,
.handsontable th:first-child.htNoFrame,
.handsontable th.htNoFrame {
border-left-width: 0;
background-color: white;
border-color: #FFF;
}
.handsontable th:first-child,
.handsontable td:first-child,
.handsontable .htNoFrame + th,
.handsontable .htNoFrame + td {
border-left: 1px solid #CCC;
}
.handsontable tr:first-child th,
.handsontable tr:first-child td {
border-top: 1px solid #CCC;
}
.handsontable thead tr:last-child th {
border-bottom-width: 0;
}
.handsontable thead tr.lastChild th {
border-bottom-width: 0;
}
.handsontable th {
background-color: #EEE;
color: #222;
text-align: center;
font-weight: normal;
white-space: nowrap;
}
.handsontable thead th {
padding: 0;
}
.handsontable th.active {
background-color: #CCC;
}
.handsontable thead th .relative {
position: relative;
padding: 2px 4px;
}
/* plugins */
.handsontable .manualColumnMover {
position: absolute;
left: 0;
top: 0;
background-color: transparent;
width: 5px;
height: 25px;
z-index: 999;
cursor: move;
}
.handsontable th .manualColumnMover:hover,
.handsontable th .manualColumnMover.active {
background-color: #88F;
}
.handsontable .manualColumnResizer {
position: absolute;
top: 0;
cursor: col-resize;
}
.handsontable .manualColumnResizerHandle {
background-color: transparent;
width: 5px;
height: 25px;
}
.handsontable .manualColumnResizer:hover .manualColumnResizerHandle,
.handsontable .manualColumnResizer.active .manualColumnResizerHandle {
background-color: #AAB;
}
.handsontable .manualColumnResizerLine {
position: absolute;
right: 0;
top: 0;
background-color: #AAB;
display: none;
width: 0;
border-right: 1px dashed #777;
}
.handsontable .manualColumnResizer.active .manualColumnResizerLine {
display: block;
}
.handsontable .columnSorting:hover {
text-decoration: underline;
cursor: pointer;
}
/* border line */
.handsontable .wtBorder {
position: absolute;
font-size: 0;
}
.handsontable td.area {
background-color: #EEF4FF;
}
/* fill handle */
.handsontable .wtBorder.corner {
font-size: 0;
cursor: crosshair;
}
.handsontable .htBorder.htFillBorder {
background: red;
width: 1px;
height: 1px;
}
.handsontableInput {
border: 2px solid #5292F7;
outline-width: 0;
margin: 0;
padding: 1px 4px 0 2px;
font-family: Arial, Helvetica, sans-serif;
/*repeat from .handsontable (inherit doesn't work with IE<8) */
line-height: 1.3em;
/*repeat from .handsontable (inherit doesn't work with IE<8) */
font-size: inherit;
-webkit-box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
resize: none;
/*below are needed to overwrite stuff added by jQuery UI Bootstrap theme*/
display: inline-block;
color: #000;
border-radius: 0;
background-color: #FFF;
/*overwrite styles potentionally made by a framework*/
}
.handsontableInputHolder {
position: absolute;
top: 0;
left: 0;
z-index: 100;
}
.htSelectEditor {
-webkit-appearance: menulist-button !important;
position: absolute;
}
/*
TextRenderer readOnly cell
*/
.handsontable .htDimmed {
color: #777;
}
/*
TextRenderer placeholder value
*/
.handsontable .htPlaceholder {
color: #999;
}
/*
AutocompleteRenderer down arrow
*/
.handsontable .htAutocompleteArrow {
float: right;
font-size: 10px;
color: #EEE;
cursor: default;
width: 16px;
text-align: center;
}
.handsontable td .htAutocompleteArrow:hover {
color: #777;
}
/*
CheckboxRenderer
*/
.handsontable .htCheckboxRendererInput.noValue {
opacity: 0.5;
}
/*
NumericRenderer
*/
.handsontable .htNumeric {
text-align: right;
}
/*context menu rules*/
ul.context-menu-list {
color: black;
}
ul.context-menu-list li {
margin-bottom: 0;
/*Foundation framework fix*/
}
/**
* dragdealer
*/
.handsontable .dragdealer {
position: relative;
width: 9px;
height: 9px;
background: #F8F8F8;
border: 1px solid #DDD;
}
.handsontable .dragdealer .handle {
position: absolute;
width: 9px;
height: 9px;
background: #C5C5C5;
}
.handsontable .dragdealer .disabled {
background: #898989;
}
/**
* Handsontable in Handsontable
*/
.handsontable .handsontable .wtHider {
padding: 0 0 5px 0;
}
.handsontable .handsontable table {
-webkit-box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
}
/**
* Handsontable listbox theme
*/
.handsontable.listbox {
margin: 0;
}
.handsontable.listbox table {
border: 1px solid #ccc;
border-collapse: separate;
background: white;
}
.handsontable.listbox th,
.handsontable.listbox tr:first-child th,
.handsontable.listbox tr:last-child th,
.handsontable.listbox tr:first-child td,
.handsontable.listbox td {
border-width: 0;
}
.handsontable.listbox th,
.handsontable.listbox td {
white-space: nowrap;
text-overflow: ellipsis;
}
.handsontable.listbox td.htDimmed {
cursor: default;
color: inherit;
font-style: inherit;
}
.handsontable.listbox .wtBorder {
visibility: hidden;
}
.handsontable.listbox tr td.current,
.handsontable.listbox tr:hover td {
background: #eee;
}
.htContextMenu {
display: none;
position: absolute;
}
.htContextMenu table.htCore {
outline: 1px solid #bbb;
}
.htContextMenu .wtBorder {
visibility: hidden;
}
.htContextMenu table tbody tr td {
background: white;
border-width: 0;
padding: 4px 6px 0px 6px;
cursor: pointer;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.htContextMenu table tbody tr td:first-child {
border: 0;
}
.htContextMenu table tbody tr td.htDimmed{
font-style: normal;
color: #323232;
}
.htContextMenu table tbody tr td.current{
background: rgb(233, 233, 233);
}
.htContextMenu table tbody tr td.htSeparator {
border-top: 1px solid #bbb;
height: 0;
padding: 0;
}
.htContextMenu table tbody tr td.htDisabled {
color: #999;
}
.htContextMenu table tbody tr td.htDisabled:hover {
background: white;
color: #999;
cursor: default;
}
.handsontable td.htSearchResult {
background: #fcedd9;
color: #583707;
}
/*WalkontableDebugOverlay*/
.wtDebugHidden {
display: none;
}
.wtDebugVisible {
display: block;
-webkit-animation-duration: 0.5s;
-webkit-animation-name: wtFadeInFromNone;
animation-duration: 0.5s;
animation-name: wtFadeInFromNone;
}
@keyframes wtFadeInFromNone {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
opacity: 0;
}
100% {
display: block;
opacity: 1;
}
}
@-webkit-keyframes wtFadeInFromNone {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
opacity: 0;
}
100% {
display: block;
opacity: 1;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*!
* QUnit 1.14.0
* http://qunitjs.com/
*
* Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2014-01-31T16:40Z
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699A4;
background-color: #0D3349;
font-size: 1.5em;
line-height: 1em;
font-weight: 400;
border-radius: 5px 5px 0 0;
}
#qunit-header a {
text-decoration: none;
color: #C2CCD1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #FFF;
}
#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 0.5em 0 0.1em;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #EEE;
overflow: hidden;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2B81AF;
color: #FFF;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
#qunit-modulefilter-container {
float: right;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #FFF;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #C2CCD1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #FFF;
border-radius: 5px;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: 0.2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 0.5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #E0F2BE;
color: #374E0C;
text-decoration: none;
}
#qunit-tests ins {
background-color: #FFCACA;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: #000; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #FFF;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3C510C;
background-color: #FFF;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #FFF;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
}
#qunit-tests .fail { color: #000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: #008000; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2B81AF;
background-color: #D2E0E6;
border-bottom: 1px solid #FFF;
}
#qunit-testresult .module-name {
font-weight: 700;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
!function(e){"use strict";function t(e){var n;if(null===e||void 0===e)return!1;if(r.isArray(e))return e.length>0;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return!0;for(n in e)if(e.hasOwnProperty(n)&&t(e[n]))return!0;return!1}var n=function(){function e(e){this.options=e}return e.prototype.toString=function(){return JSON&&JSON.stringify?JSON.stringify(this.options):this.options},e}(),r=function(){function e(e){return"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"[object String]"===Object.prototype.toString.apply(e)}function n(e){return"[object Number]"===Object.prototype.toString.apply(e)}function r(e){return"[object Boolean]"===Object.prototype.toString.apply(e)}function i(e,t){var n,r="",i=!0;for(n=0;n<e.length;n+=1)i?i=!1:r+=t,r+=e[n];return r}function o(e,t){for(var n=[],r=0;r<e.length;r+=1)n.push(t(e[r]));return n}function s(e,t){for(var n=[],r=0;r<e.length;r+=1)t(e[r])&&n.push(e[r]);return n}function a(e){if("object"!=typeof e||null===e)return e;Object.freeze(e);var t,n;for(n in e)e.hasOwnProperty(n)&&(t=e[n],"object"==typeof t&&u(t));return e}function u(e){return"function"==typeof Object.freeze?a(e):e}return{isArray:e,isString:t,isNumber:n,isBoolean:r,join:i,map:o,filter:s,deepFreeze:u}}(),i=function(){function e(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e}function t(e){return e>="0"&&"9">=e}function n(e){return t(e)||e>="a"&&"f">=e||e>="A"&&"F">=e}return{isAlpha:e,isDigit:t,isHexDigit:n}}(),o=function(){function e(e){var t,n,r="",i=s.encode(e);for(n=0;n<i.length;n+=1)t=i.charCodeAt(n),r+="%"+(16>t?"0":"")+t.toString(16).toUpperCase();return r}function t(e,t){return"%"===e.charAt(t)&&i.isHexDigit(e.charAt(t+1))&&i.isHexDigit(e.charAt(t+2))}function n(e,t){return parseInt(e.substr(t,2),16)}function r(e){if(!t(e,0))return!1;var r=n(e,1),i=s.numBytes(r);if(0===i)return!1;for(var o=1;i>o;o+=1)if(!t(e,3*o)||!s.isValidFollowingCharCode(n(e,3*o+1)))return!1;return!0}function o(e,r){var i=e.charAt(r);if(!t(e,r))return i;var o=n(e,r+1),a=s.numBytes(o);if(0===a)return i;for(var u=1;a>u;u+=1)if(!t(e,r+3*u)||!s.isValidFollowingCharCode(n(e,r+3*u+1)))return i;return e.substr(r,3*a)}var s={encode:function(e){return unescape(encodeURIComponent(e))},numBytes:function(e){return 127>=e?1:e>=194&&223>=e?2:e>=224&&239>=e?3:e>=240&&244>=e?4:0},isValidFollowingCharCode:function(e){return e>=128&&191>=e}};return{encodeCharacter:e,isPctEncoded:r,pctCharAt:o}}(),s=function(){function e(e){return i.isAlpha(e)||i.isDigit(e)||"_"===e||o.isPctEncoded(e)}function t(e){return i.isAlpha(e)||i.isDigit(e)||"-"===e||"."===e||"_"===e||"~"===e}function n(e){return":"===e||"/"===e||"?"===e||"#"===e||"["===e||"]"===e||"@"===e||"!"===e||"$"===e||"&"===e||"("===e||")"===e||"*"===e||"+"===e||","===e||";"===e||"="===e||"'"===e}return{isVarchar:e,isUnreserved:t,isReserved:n}}(),a=function(){function e(e,t){var n,r="",i="";for(("number"==typeof e||"boolean"==typeof e)&&(e=e.toString()),n=0;n<e.length;n+=i.length)i=e.charAt(n),r+=s.isUnreserved(i)||t&&s.isReserved(i)?i:o.encodeCharacter(i);return r}function t(t){return e(t,!0)}function n(e,t){var n=o.pctCharAt(e,t);return n.length>1?n:s.isReserved(n)||s.isUnreserved(n)?n:o.encodeCharacter(n)}function r(e){var t,n="",r="";for(t=0;t<e.length;t+=r.length)r=o.pctCharAt(e,t),n+=r.length>1?r:s.isReserved(r)||s.isUnreserved(r)?r:o.encodeCharacter(r);return n}return{encode:e,encodePassReserved:t,encodeLiteral:r,encodeLiteralCharacter:n}}(),u=function(){function e(e){t[e]={symbol:e,separator:"?"===e?"&":""===e||"+"===e||"#"===e?",":e,named:";"===e||"&"===e||"?"===e,ifEmpty:"&"===e||"?"===e?"=":"",first:"+"===e?"":e,encode:"+"===e||"#"===e?a.encodePassReserved:a.encode,toString:function(){return this.symbol}}}var t={};return e(""),e("+"),e("#"),e("."),e("/"),e(";"),e("?"),e("&"),{valueOf:function(e){return t[e]?t[e]:"=,!@|".indexOf(e)>=0?null:t[""]}}}(),p=function(){function e(e){this.literal=a.encodeLiteral(e)}return e.prototype.expand=function(){return this.literal},e.prototype.toString=e.prototype.expand,e}(),f=function(){function e(e){function t(){var t=e.substring(h,p);if(0===t.length)throw new n({expressionText:e,message:"a varname must be specified",position:p});c={varname:t,exploded:!1,maxLength:null},h=null}function r(){if(d===p)throw new n({expressionText:e,message:"after a ':' you have to specify the length",position:p});c.maxLength=parseInt(e.substring(d,p),10),d=null}var a,p,f=[],c=null,h=null,d=null,g="";for(a=function(t){var r=u.valueOf(t);if(null===r)throw new n({expressionText:e,message:"illegal use of reserved operator",position:p,operator:t});return r}(e.charAt(0)),p=a.symbol.length,h=p;p<e.length;p+=g.length){if(g=o.pctCharAt(e,p),null!==h){if("."===g){if(h===p)throw new n({expressionText:e,message:"a varname MUST NOT start with a dot",position:p});continue}if(s.isVarchar(g))continue;t()}if(null!==d){if(p===d&&"0"===g)throw new n({expressionText:e,message:"A :prefix must not start with digit 0",position:p});if(i.isDigit(g)){if(p-d>=4)throw new n({expressionText:e,message:"A :prefix must have max 4 digits",position:p});continue}r()}if(":"!==g)if("*"!==g){if(","!==g)throw new n({expressionText:e,message:"illegal character",character:g,position:p});f.push(c),c=null,h=p+1}else{if(null===c)throw new n({expressionText:e,message:"exploded without varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"exploded twice",position:p});if(c.maxLength)throw new n({expressionText:e,message:"an explode (*) MUST NOT follow to a prefix",position:p});c.exploded=!0}else{if(null!==c.maxLength)throw new n({expressionText:e,message:"only one :maxLength is allowed per varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"an exploeded varspec MUST NOT be varspeced",position:p});d=p+1}}return null!==h&&t(),null!==d&&r(),f.push(c),new l(e,a,f)}function t(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(r){var i,o,s,a=[],u=null,f="",l=!0,h=0;for(i=0;i<r.length;i+=1)if(o=r.charAt(i),null===h){if(null===u)throw new Error("reached unreachable code");if("{"===o)throw new n({templateText:r,message:"brace already opened",position:i});if("}"===o){if(u+1===i)throw new n({templateText:r,message:"empty braces",position:u});try{s=e(r.substring(u+1,i))}catch(d){if(d.prototype===n.prototype)throw new n({templateText:r,message:d.options.message,position:u+d.options.position,details:d.options});throw d}a.push(s),0===s.operator.symbol.length?f+="([^/]+)":l=!1,u=null,h=i+1}}else{if("}"===o)throw new n({templateText:r,message:"unopened brace closed",position:i});"{"===o&&(i>h&&(s=new p(r.substring(h,i)),a.push(s),f+=t(s.literal)),h=null,u=i)}if(null!==u)throw new n({templateText:r,message:"unclosed brace",position:u});return h<r.length&&(s=new p(r.substring(h)),a.push(s),f+=t(s.literal)),l===!1&&(f=void 0),new c(r,a,f)}return r}(),l=function(){function e(e){return JSON&&JSON.stringify?JSON.stringify(e):e}function n(e){if(!t(e))return!0;if(r.isString(e))return""===e;if(r.isNumber(e)||r.isBoolean(e))return!1;if(r.isArray(e))return 0===e.length;for(var n in e)if(e.hasOwnProperty(n))return!1;return!0}function i(e){var t,n=[];for(t in e)e.hasOwnProperty(t)&&n.push({name:t,value:e[t]});return n}function o(e,t,n){this.templateText=e,this.operator=t,this.varspecs=n}function s(e,t,n){var r="";if(n=n.toString(),t.named){if(r+=a.encodeLiteral(e.varname),""===n)return r+=t.ifEmpty;r+="="}return null!==e.maxLength&&(n=n.substr(0,e.maxLength)),r+=t.encode(n)}function u(e){return t(e.value)}function p(e,o,s){var p=[],f="";if(o.named){if(f+=a.encodeLiteral(e.varname),n(s))return f+=o.ifEmpty;f+="="}return r.isArray(s)?(p=s,p=r.filter(p,t),p=r.map(p,o.encode),f+=r.join(p,",")):(p=i(s),p=r.filter(p,u),p=r.map(p,function(e){return o.encode(e.name)+","+o.encode(e.value)}),f+=r.join(p,",")),f}function f(e,o,s){var p=r.isArray(s),f=[];return p?(f=s,f=r.filter(f,t),f=r.map(f,function(t){var r=a.encodeLiteral(e.varname);return r+=n(t)?o.ifEmpty:"="+o.encode(t)})):(f=i(s),f=r.filter(f,u),f=r.map(f,function(e){var t=a.encodeLiteral(e.name);return t+=n(e.value)?o.ifEmpty:"="+o.encode(e.value)})),r.join(f,o.separator)}function l(e,n){var o=[],s="";return r.isArray(n)?(o=n,o=r.filter(o,t),o=r.map(o,e.encode),s+=r.join(o,e.separator)):(o=i(n),o=r.filter(o,function(e){return t(e.value)}),o=r.map(o,function(t){return e.encode(t.name)+"="+e.encode(t.value)}),s+=r.join(o,e.separator)),s}return o.prototype.toString=function(){return this.templateText},o.prototype.expand=function(i){var o,a,u,c,h=[],d=!1,g=this.operator;for(o=0;o<this.varspecs.length;o+=1)if(a=this.varspecs[o],u=i[a.varname],null!==u&&void 0!==u)if(a.exploded&&(d=!0),c=r.isArray(u),"string"==typeof u||"number"==typeof u||"boolean"==typeof u)h.push(s(a,g,u));else{if(a.maxLength&&t(u))throw new Error("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+e(u));a.exploded?t(u)&&(g.named?h.push(f(a,g,u)):h.push(l(g,u))):(g.named||!n(u))&&h.push(p(a,g,u))}return 0===h.length?"":g.first+r.join(h,g.separator)},o}(),c=function(){function e(e,t,n){this.templateText=e,this.expressions=t,void 0!==n&&(this.regexp=new RegExp("^"+n+"$")),r.deepFreeze(this)}return e.prototype.toString=function(){return this.templateText},e.prototype.expand=function(e){var t,n="";for(t=0;t<this.expressions.length;t+=1)n+=this.expressions[t].expand(e);return n},e.prototype.extract=function(e){var t,n,r,i,o=1,s=!0,a={};if(void 0!==this.regexp&&this.regexp.test(e)){for(i=this.regexp.exec(e),t=0;t<this.expressions.length;t+=1)n=this.expressions[t],void 0===n.literal&&(void 0!==n.operator&&0===n.operator.symbol.length&&1===n.varspecs.length?(r=n.varspecs[0],r.exploded===!1&&null===r.maxLength?-1===i[o].indexOf(",")?(a[r.varname]=decodeURIComponent(i[o]),o+=1):s=!1:s=!1):s=!1);if(s)return a}return!1},e.parse=f,e.UriTemplateError=n,e}();e(c)}(function(e){"use strict";"undefined"!=typeof module?module.exports=e:"function"==typeof define?define([],function(){return e}):"undefined"!=typeof window?window.UriTemplate=e:global.UriTemplate=e});
\ 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