Commit 76805e06 authored by Romain Courteaud's avatar Romain Courteaud

Declare the method 'declareGadget'.

parent e801e33b
...@@ -293,77 +293,77 @@ ...@@ -293,77 +293,77 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// RenderJSGadget.declareGadget // RenderJSGadget.declareGadget
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
RenderJSGadget.prototype.declareGadget = function (url, options) { RenderJSGadget
var queue, .declareMethod('declareGadget', function (url, options) {
parent_gadget = this, var queue,
previous_loading_gadget_promise = loading_gadget_promise; parent_gadget = this,
previous_loading_gadget_promise = loading_gadget_promise;
if (options === undefined) { if (options === undefined) {
options = {}; options = {};
} }
if (options.sandbox === undefined) { if (options.sandbox === undefined) {
options.sandbox = "public"; options.sandbox = "public";
} }
// Change the global variable to update the loading queue // Change the global variable to update the loading queue
queue = new RSVP.Queue() queue = new RSVP.Queue()
// Wait for previous gadget loading to finish first // Wait for previous gadget loading to finish first
.push(function () { .push(function () {
return previous_loading_gadget_promise; return previous_loading_gadget_promise;
}) })
.push(undefined, function () { .push(undefined, function () {
// Forget previous declareGadget error // Forget previous declareGadget error
return; return;
}) })
.push(function () { .push(function () {
var method; var method;
if (options.sandbox === "public") { if (options.sandbox === "public") {
method = privateDeclarePublicGadget; method = privateDeclarePublicGadget;
} else if (options.sandbox === "iframe") { } else if (options.sandbox === "iframe") {
method = privateDeclareIframeGadget; method = privateDeclareIframeGadget;
} else { } else {
throw new Error("Unsupported sandbox options '" + throw new Error("Unsupported sandbox options '" +
options.sandbox + "'"); options.sandbox + "'");
} }
return method(url, options); return method(url, options);
}) })
// Set the HTML context // Set the HTML context
.push(function (gadget_instance) { .push(function (gadget_instance) {
var i; var i;
// Define aq_parent to reach parent gadget // Define aq_parent to reach parent gadget
gadget_instance.aq_parent = function (method_name, argument_list) { gadget_instance.aq_parent = function (method_name, argument_list) {
return parent_gadget.acquire(method_name, argument_list); return parent_gadget.acquire(method_name, argument_list);
}; };
// Drop the current loading klass info used by selector // Drop the current loading klass info used by selector
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
// Trigger calling of all ready callback // Trigger calling of all ready callback
function ready_wrapper() { function ready_wrapper() {
return gadget_instance; return gadget_instance;
} }
for (i = 0; i < gadget_instance.constructor.ready_list.length; for (i = 0; i < gadget_instance.constructor.ready_list.length;
i += 1) { i += 1) {
// Put a timeout? // Put a timeout?
queue.push(gadget_instance.constructor.ready_list[i]); queue.push(gadget_instance.constructor.ready_list[i]);
// Always return the gadget instance after ready function // Always return the gadget instance after ready function
queue.push(ready_wrapper); queue.push(ready_wrapper);
} }
// Store local reference to the gadget instance // Store local reference to the gadget instance
if (options.scope !== undefined) { if (options.scope !== undefined) {
parent_gadget.sub_gadget_dict[options.scope] = gadget_instance; parent_gadget.sub_gadget_dict[options.scope] = gadget_instance;
} }
return gadget_instance; return gadget_instance;
}) })
.push(undefined, function (e) { .push(undefined, function (e) {
// Drop the current loading klass info used by selector // Drop the current loading klass info used by selector
// even in case of error // even in case of error
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
throw e; throw e;
}); });
loading_gadget_promise = queue; loading_gadget_promise = queue;
return loading_gadget_promise; return loading_gadget_promise;
}; })
RenderJSGadget
.declareMethod('getDeclaredGadget', function (gadget_scope) { .declareMethod('getDeclaredGadget', function (gadget_scope) {
if (!this.sub_gadget_dict.hasOwnProperty(gadget_scope)) { if (!this.sub_gadget_dict.hasOwnProperty(gadget_scope)) {
throw new Error("Gadget scope '" + gadget_scope + "' is not known."); throw new Error("Gadget scope '" + gadget_scope + "' is not known.");
......
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