Commit 914cbd3d authored by Romain Courteaud's avatar Romain Courteaud

Release version 0.7.5

parent eb32a211
This diff is collapsed.
This diff is collapsed.
...@@ -673,16 +673,70 @@ if (typeof document.contains !== 'function') { ...@@ -673,16 +673,70 @@ if (typeof document.contains !== 'function') {
* http://www.renderjs.org/documentation * http://www.renderjs.org/documentation
*/ */
(function (document, window, RSVP, DOMParser, Channel, MutationObserver, (function (document, window, RSVP, DOMParser, Channel, MutationObserver,
Node) { Node, FileReader, Blob) {
"use strict"; "use strict";
function readBlobAsDataURL(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject) {
fr.addEventListener("load", function (evt) {
resolve(evt.target.result);
});
fr.addEventListener("error", reject);
fr.readAsDataURL(blob);
}, function () {
fr.abort();
});
}
function ajax(url) {
var xhr;
function resolver(resolve, reject) {
function handler() {
try {
if (xhr.readyState === 0) {
// UNSENT
reject(xhr);
} else if (xhr.readyState === 4) {
// DONE
if ((xhr.status < 200) || (xhr.status >= 300) ||
(!/^text\/html[;]?/.test(
xhr.getResponseHeader("Content-Type") || ""
))) {
reject(xhr);
} else {
resolve(xhr);
}
}
} catch (e) {
reject(e);
}
}
xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = handler;
xhr.setRequestHeader('Accept', 'text/html');
xhr.withCredentials = true;
xhr.send();
}
function canceller() {
if ((xhr !== undefined) && (xhr.readyState !== xhr.DONE)) {
xhr.abort();
}
}
return new RSVP.Promise(resolver, canceller);
}
var gadget_model_dict = {}, var gadget_model_dict = {},
javascript_registration_dict = {}, javascript_registration_dict = {},
stylesheet_registration_dict = {}, stylesheet_registration_dict = {},
gadget_loading_klass, gadget_loading_klass,
loading_klass_promise, loading_klass_promise,
renderJS, renderJS,
Monitor; Monitor,
isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i');
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Helper functions // Helper functions
...@@ -1222,6 +1276,33 @@ if (typeof document.contains !== 'function') { ...@@ -1222,6 +1276,33 @@ if (typeof document.contains !== 'function') {
]); ]);
} }
/////////////////////////////////////////////////////////////////
// privateDeclareDataUrlGadget
/////////////////////////////////////////////////////////////////
function privateDeclareDataUrlGadget(url, options, parent_gadget) {
return new RSVP.Queue()
.push(function () {
return ajax(url);
})
.push(function (xhr) {
// Insert a "base" element, in order to resolve all relative links
// which could get broken with a data url
var doc = (new DOMParser()).parseFromString(xhr.responseText,
'text/html'),
base = doc.createElement('base'),
blob;
base.href = url;
doc.head.insertBefore(base, doc.head.firstChild);
blob = new Blob([doc.documentElement.outerHTML],
{type: "text/html;charset=UTF-8"});
return readBlobAsDataURL(blob);
})
.push(function (data_url) {
return privateDeclareIframeGadget(data_url, options, parent_gadget);
});
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// RenderJSGadget.declareGadget // RenderJSGadget.declareGadget
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -1257,6 +1338,8 @@ if (typeof document.contains !== 'function') { ...@@ -1257,6 +1338,8 @@ if (typeof document.contains !== 'function') {
method = privateDeclarePublicGadget; method = privateDeclarePublicGadget;
} else if (options.sandbox === "iframe") { } else if (options.sandbox === "iframe") {
method = privateDeclareIframeGadget; method = privateDeclareIframeGadget;
} else if (options.sandbox === "dataurl") {
method = privateDeclareDataUrlGadget;
} else { } else {
throw new Error("Unsupported sandbox options '" + throw new Error("Unsupported sandbox options '" +
options.sandbox + "'"); options.sandbox + "'");
...@@ -1369,8 +1452,7 @@ if (typeof document.contains !== 'function') { ...@@ -1369,8 +1452,7 @@ if (typeof document.contains !== 'function') {
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
renderJS.getAbsoluteURL = function (url, base_url) { renderJS.getAbsoluteURL = function (url, base_url) {
var doc, base, link, var doc, base, link,
html = "<!doctype><html><head></head></html>", html = "<!doctype><html><head></head></html>";
isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i');
if (url && base_url && !isAbsoluteOrDataURL.test(url)) { if (url && base_url && !isAbsoluteOrDataURL.test(url)) {
doc = (new DOMParser()).parseFromString(html, 'text/html'); doc = (new DOMParser()).parseFromString(html, 'text/html');
...@@ -1448,10 +1530,9 @@ if (typeof document.contains !== 'function') { ...@@ -1448,10 +1530,9 @@ if (typeof document.contains !== 'function') {
// renderJS.declareGadgetKlass // renderJS.declareGadgetKlass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
renderJS.declareGadgetKlass = function (url) { renderJS.declareGadgetKlass = function (url) {
var result, var result;
xhr;
function parse() { function parse(xhr) {
var tmp_constructor, var tmp_constructor,
key, key,
parsed_html; parsed_html;
...@@ -1497,50 +1578,18 @@ if (typeof document.contains !== 'function') { ...@@ -1497,50 +1578,18 @@ if (typeof document.contains !== 'function') {
return gadget_model_dict[url]; return gadget_model_dict[url];
} }
function resolver(resolve, reject) {
function handler() {
var tmp_result;
try {
if (xhr.readyState === 0) {
// UNSENT
reject(xhr);
} else if (xhr.readyState === 4) {
// DONE
if ((xhr.status < 200) || (xhr.status >= 300) ||
(!/^text\/html[;]?/.test(
xhr.getResponseHeader("Content-Type") || ""
))) {
reject(xhr);
} else {
tmp_result = parse();
resolve(tmp_result);
}
}
} catch (e) {
reject(e);
}
}
xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = handler;
xhr.setRequestHeader('Accept', 'text/html');
xhr.withCredentials = true;
xhr.send();
}
function canceller() {
if ((xhr !== undefined) && (xhr.readyState !== xhr.DONE)) {
xhr.abort();
}
}
if (gadget_model_dict.hasOwnProperty(url)) { if (gadget_model_dict.hasOwnProperty(url)) {
// Return klass object if it already exists // Return klass object if it already exists
result = RSVP.resolve(gadget_model_dict[url]); result = RSVP.resolve(gadget_model_dict[url]);
} else { } else {
// Fetch the HTML page and parse it // Fetch the HTML page and parse it
result = new RSVP.Promise(resolver, canceller); result = new RSVP.Queue()
.push(function () {
return ajax(url);
})
.push(function (xhr) {
return parse(xhr);
});
} }
return result; return result;
}; };
...@@ -1566,10 +1615,9 @@ if (typeof document.contains !== 'function') { ...@@ -1566,10 +1615,9 @@ if (typeof document.contains !== 'function') {
required_js_list: [] required_js_list: []
}, },
i, i,
element, element;
isAbsoluteURL = new RegExp('^(?:[a-z]+:)?//', 'i');
if (!url || !isAbsoluteURL.test(url)) { if (!url || !isAbsoluteOrDataURL.test(url)) {
throw new Error("The url should be absolute: " + url); throw new Error("The url should be absolute: " + url);
} }
...@@ -1972,4 +2020,5 @@ if (typeof document.contains !== 'function') { ...@@ -1972,4 +2020,5 @@ if (typeof document.contains !== 'function') {
} }
bootstrap(); bootstrap();
}(document, window, RSVP, DOMParser, Channel, MutationObserver, Node)); }(document, window, RSVP, DOMParser, Channel, MutationObserver, Node,
FileReader, Blob));
This diff is collapsed.
{ {
"name": "renderjs", "name": "renderjs",
"version": "0.7.4", "version": "0.7.5",
"description": "RenderJs provides HTML5 gadgets", "description": "RenderJs provides HTML5 gadgets",
"main": "dist/renderjs-latest.js", "main": "dist/renderjs-latest.js",
"dependencies": { "dependencies": {
......
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