Commit 9b2a662b authored by Romain Courteaud's avatar Romain Courteaud

Temporary hack to make AMD require(['renderjs']) work.

Thanks to Caleb James DeLisle.

A better fix in this case would be to cleanly allow RenderJS gadget
instanciation to wait for some events (require and any other JS code)
before deciding that a gadget is ready. Currently, RenderJS ready
function is triggered when all JS scripts defined in the HTML page are
loaded. One idea would be to extend the API to allow the gadget to
explicitely trigger the ready callback (but it will block the full
system if one gadget failed to load).
parent 2a83acbd
......@@ -754,35 +754,40 @@
$(document).ready(function () {
// XXX HTML properties can only be set when the DOM is fully loaded
var settings = renderJS.parseGadgetHTML($('html')[0].outerHTML),
promise,
key;
for (key in settings) {
if (settings.hasOwnProperty(key)) {
tmp_constructor.prototype[key] = settings[key];
// run on next tick so that if this was pulled in with requirejs,
// rJS.ready() can still be used.
// XXX: doesn't work with require(['renderjs', 'somethingElse'], ...
setTimeout(function () {
$(document).ready(function () {
// XXX HTML properties can only be set when the DOM is fully loaded
var settings = renderJS.parseGadgetHTML($('html')[0].outerHTML),
promise,
key;
for (key in settings) {
if (settings.hasOwnProperty(key)) {
tmp_constructor.prototype[key] = settings[key];
}
}
}
root_gadget.context = $('body');
promise = $.when(root_gadget.getRequiredJSList(),
root_gadget.getRequiredCSSList())
.done(function (js_list, css_list) {
$.each(js_list, function (i, required_url) {
javascript_registration_dict[required_url] = null;
});
$.each(css_list, function (i, required_url) {
stylesheet_registration_dict[url] = null;
});
$.each(tmp_constructor.ready_list, function (i, callback) {
callback.apply(root_gadget);
root_gadget.context = $('body');
promise = $.when(root_gadget.getRequiredJSList(),
root_gadget.getRequiredCSSList())
.done(function (js_list, css_list) {
$.each(js_list, function (i, required_url) {
javascript_registration_dict[required_url] = null;
});
$.each(css_list, function (i, required_url) {
stylesheet_registration_dict[url] = null;
});
$.each(tmp_constructor.ready_list, function (i, callback) {
callback.apply(root_gadget);
});
gadget_loading_klass = undefined;
loading_gadget_deferred.resolve();
}).fail(function () {
loading_gadget_deferred.reject.apply(loading_gadget_deferred,
arguments);
});
gadget_loading_klass = undefined;
loading_gadget_deferred.resolve();
}).fail(function () {
loading_gadget_deferred.reject.apply(loading_gadget_deferred,
arguments);
});
});
});
}
bootstrap();
......
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