From 21b678dbcaed317e9ccfc10a47b62e829af7c512 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Fri, 12 Oct 2012 10:41:33 +0100 Subject: [PATCH] MDL-36023 AJAX Move the instantiation of the dialogue to display time --- lib/yui/chooserdialogue/chooserdialogue.js | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/yui/chooserdialogue/chooserdialogue.js b/lib/yui/chooserdialogue/chooserdialogue.js index f1c45663310..1c877b81056 100644 --- a/lib/yui/chooserdialogue/chooserdialogue.js +++ b/lib/yui/chooserdialogue/chooserdialogue.js @@ -20,30 +20,44 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { // The initial overflow setting initialoverflow : '', + bodycontent : null, + headercontent : null, + instanceconfig : null, + setup_chooser_dialogue : function(bodycontent, headercontent, config) { + this.bodycontent = bodycontent; + this.headercontent = headercontent; + this.instanceconfig = config; + }, + + prepare_chooser : function () { + if (this.overlay) { + return; + } + // Set Default options var params = { - bodyContent : bodycontent.get('innerHTML'), - headerContent : headercontent.get('innerHTML'), + bodyContent : this.bodycontent.get('innerHTML'), + headerContent : this.headercontent.get('innerHTML'), width : '540px', draggable : true, visible : false, // Hide by default zindex : 100, // Display in front of other items lightbox : true, // This dialogue should be modal shim : true - } + }; // Override with additional options - for (paramkey in config) { - params[paramkey] = config[paramkey]; + for (paramkey in this.instanceconfig) { + params[paramkey] = this.instanceconfig[paramkey]; } // Create the overlay this.overlay = new M.core.dialogue(params); // Remove the template for the chooser - bodycontent.remove(); - headercontent.remove(); + this.bodycontent.remove(); + this.headercontent.remove(); // Hide and then render the overlay this.overlay.hide(); @@ -64,6 +78,8 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { * @return void */ display_chooser : function (e) { + this.prepare_chooser(); + // Stop the default event actions before we proceed e.preventDefault();