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 @@ ...@@ -754,35 +754,40 @@
$(document).ready(function () { // run on next tick so that if this was pulled in with requirejs,
// XXX HTML properties can only be set when the DOM is fully loaded // rJS.ready() can still be used.
var settings = renderJS.parseGadgetHTML($('html')[0].outerHTML), // XXX: doesn't work with require(['renderjs', 'somethingElse'], ...
promise, setTimeout(function () {
key; $(document).ready(function () {
for (key in settings) { // XXX HTML properties can only be set when the DOM is fully loaded
if (settings.hasOwnProperty(key)) { var settings = renderJS.parseGadgetHTML($('html')[0].outerHTML),
tmp_constructor.prototype[key] = settings[key]; promise,
key;
for (key in settings) {
if (settings.hasOwnProperty(key)) {
tmp_constructor.prototype[key] = settings[key];
}
} }
} root_gadget.context = $('body');
root_gadget.context = $('body'); promise = $.when(root_gadget.getRequiredJSList(),
promise = $.when(root_gadget.getRequiredJSList(), root_gadget.getRequiredCSSList())
root_gadget.getRequiredCSSList()) .done(function (js_list, css_list) {
.done(function (js_list, css_list) { $.each(js_list, function (i, required_url) {
$.each(js_list, function (i, required_url) { javascript_registration_dict[required_url] = null;
javascript_registration_dict[required_url] = null; });
}); $.each(css_list, function (i, required_url) {
$.each(css_list, function (i, required_url) { stylesheet_registration_dict[url] = null;
stylesheet_registration_dict[url] = null; });
}); $.each(tmp_constructor.ready_list, function (i, callback) {
$.each(tmp_constructor.ready_list, function (i, callback) { callback.apply(root_gadget);
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(); 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