From ce4da4612e7c468181d2a557402791dfcf2ada54 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 11 Dec 2013 10:01:49 +0800 Subject: [PATCH] MDL-43323 JavaScript: Lazily load exception dependencies for tooltip Only load the exception-related dependencies for tooltip when required. In normal situations they should not be required at all. --- .../moodle-core-tooltip/moodle-core-tooltip-debug.js | 12 +++++++++--- .../moodle-core-tooltip/moodle-core-tooltip-min.js | 2 +- .../build/moodle-core-tooltip/moodle-core-tooltip.js | 12 +++++++++--- lib/yui/src/tooltip/js/tooltip.js | 10 ++++++++-- lib/yui/src/tooltip/meta/tooltip.json | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js index 31d81fcd77a..03408fe4ac4 100644 --- a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js +++ b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js @@ -379,11 +379,17 @@ Y.extend(TOOLTIP, M.core.dialogue, { responseobject = Y.JSON.parse(response); if (responseobject.error) { this.close_panel(); - return new M.core.ajaxException(responseobject); + Y.use('moodle-core-notification-ajaxexception', function() { + return new M.core.ajaxException(responseobject).show(); + }); + return this; } } catch (error) { this.close_panel(); - return new M.core.exception(error); + Y.use('moodle-core-notification-exception', function() { + return new M.core.exception(error).show(); + }); + return this; } // Set the contents using various handlers. @@ -463,7 +469,7 @@ M.core.tooltip = M.core.tooltip = TOOLTIP; "base", "node", "io-base", - "moodle-core-notification", + "moodle-core-notification-dialogue", "json-parse", "widget-position", "widget-position-align", diff --git a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js index e99b50a3d4a..c31276bb747 100644 --- a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js +++ b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js @@ -1 +1 @@ -YUI.add("moodle-core-tooltip",function(e,t){function n(e){e||(e={}),typeof e.draggable=="undefined"&&(e.draggable=!0),typeof e.constrain=="undefined"&&(e.constrain=!0),n.superclass.constructor.apply(this,[e])}var r={CLOSEBUTTON:".closebutton"},i={PANELTEXT:"tooltiptext"},s={WAITICON:{pix:"i/loading_small",component:"moodle"}},o={};n.NAME="moodle-core-tooltip",n.CSS_PREFIX="moodle-dialogue",n.ATTRS=o,o.initialheadertext={value:""},o.initialbodytext={value:"",setter:function(t){var n,r;return n=e.Node.create("
").addClass(i.PANELTEXT),r=e.Node.create("").setAttribute("src",M.util.image_url(s.WAITICON.pix,s.WAITICON.component)).addClass("spinner"),t?(n.set("text",t),r.addClass("iconsmall")):n.addClass("content-lightbox"),n.append(r),n}},o.initialfootertext={value:null,setter:function(t){if(t)return e.Node.create("
").set("text",t)}},o.headerhandler={value:"set_header_content"},o.bodyhandler={value:"set_body_content"},o.footerhandler={value:null},o.urlmodifier={value:null},o.textcache={value:null},o.textcachesize={value:10},e.extend(n,M.core.dialogue,{bb:null,listenevents:[],textcache:null,alignpoints:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.RC],initializer:function(){return this.get("headerhandler")||this.set("headerhandler",this.set_header_content),this.get("bodyhandler")||this.set("bodyhandler",this.set_body_content),this.get("footerhandler")||this.set("footerhandler",function(){}),this.get("urlmodifier")||this.set("urlmodifier",this.modify_url),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext")}),this.hide(),this.render(),this.bb=this.get("boundingBox"),this.bb.addClass("moodle-dialogue-tooltip"),right_to_left()&&(this.alignpoints=[e.WidgetPositionAlign.TR,e.WidgetPositionAlign.LC]),this.get("textcache")||this.set("textcache",new e.Cache({max:this.get("textcachesize")})),M.cfg.developerdebug&&this.get("textcache").set("max",0),this},display_panel:function(t){var n,i,s,o,u;t.preventDefault(),t.stopPropagation(),this.cancel_events(),n=t.target.ancestor("a",!0),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext")}),this.show(),this.align(n,this.alignpoints),i=this.bb.delegate("click",this.close_panel,r.CLOSEBUTTON,this),this.listenevents.push(i),i=e.one("body").on("key",this.close_panel,"esc",this),this.listenevents.push(i),i=this.bb.on("mousedownoutside",this.close_panel,this),this.listenevents.push(i),s=e.bind(this.get("urlmodifier"),this,n.get("href"))(),u=this.get("textcache").retrieve(s),u?this._set_panel_contents(u.response):(o={method:"get",context:this,sync:!1,on:{complete:function(e,t){this._set_panel_contents(t.responseText,s)}}},e.io(s,o))},_set_panel_contents:function(t,n){var r;try{r=e.JSON.parse(t);if(r.error)return this.close_panel(),new M.core.ajaxException(r)}catch(i){return this.close_panel(),new M.core.exception(i)}e.bind(this.get("headerhandler"),this,r)(),e.bind(this.get("bodyhandler"),this,r)(),e.bind(this.get("footerhandler"),this,r)(),n&&this.get("textcache").add(n,t),this.get("buttons").header[0].focus()},set_header_content:function(e){this.set("headerContent",e.heading)},set_body_content:function(t){var n=e.Node.create("
").set("innerHTML",t.text).setAttribute("role","alert").addClass(i.PANELTEXT);this.set("bodyContent",n)},modify_url:function(e){return e.replace(/\.php\?/,"_ajax.php?")},close_panel:function(e){this.hide(),this.cancel_events(),e&&e.preventDefault()},cancel_events:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()}}),e.Base.modifyAttrs(n,{modal:{value:!1}}),M.core=M.core||{},M.core.tooltip=M.core.tooltip=n},"@VERSION@",{requires:["base","node","io-base","moodle-core-notification","json-parse","widget-position","widget-position-align","event-outside","cache-base"]}); +YUI.add("moodle-core-tooltip",function(e,t){function n(e){e||(e={}),typeof e.draggable=="undefined"&&(e.draggable=!0),typeof e.constrain=="undefined"&&(e.constrain=!0),n.superclass.constructor.apply(this,[e])}var r={CLOSEBUTTON:".closebutton"},i={PANELTEXT:"tooltiptext"},s={WAITICON:{pix:"i/loading_small",component:"moodle"}},o={};n.NAME="moodle-core-tooltip",n.CSS_PREFIX="moodle-dialogue",n.ATTRS=o,o.initialheadertext={value:""},o.initialbodytext={value:"",setter:function(t){var n,r;return n=e.Node.create("
").addClass(i.PANELTEXT),r=e.Node.create("").setAttribute("src",M.util.image_url(s.WAITICON.pix,s.WAITICON.component)).addClass("spinner"),t?(n.set("text",t),r.addClass("iconsmall")):n.addClass("content-lightbox"),n.append(r),n}},o.initialfootertext={value:null,setter:function(t){if(t)return e.Node.create("
").set("text",t)}},o.headerhandler={value:"set_header_content"},o.bodyhandler={value:"set_body_content"},o.footerhandler={value:null},o.urlmodifier={value:null},o.textcache={value:null},o.textcachesize={value:10},e.extend(n,M.core.dialogue,{bb:null,listenevents:[],textcache:null,alignpoints:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.RC],initializer:function(){return this.get("headerhandler")||this.set("headerhandler",this.set_header_content),this.get("bodyhandler")||this.set("bodyhandler",this.set_body_content),this.get("footerhandler")||this.set("footerhandler",function(){}),this.get("urlmodifier")||this.set("urlmodifier",this.modify_url),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext")}),this.hide(),this.render(),this.bb=this.get("boundingBox"),this.bb.addClass("moodle-dialogue-tooltip"),right_to_left()&&(this.alignpoints=[e.WidgetPositionAlign.TR,e.WidgetPositionAlign.LC]),this.get("textcache")||this.set("textcache",new e.Cache({max:this.get("textcachesize")})),M.cfg.developerdebug&&this.get("textcache").set("max",0),this},display_panel:function(t){var n,i,s,o,u;t.preventDefault(),t.stopPropagation(),this.cancel_events(),n=t.target.ancestor("a",!0),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext")}),this.show(),this.align(n,this.alignpoints),i=this.bb.delegate("click",this.close_panel,r.CLOSEBUTTON,this),this.listenevents.push(i),i=e.one("body").on("key",this.close_panel,"esc",this),this.listenevents.push(i),i=this.bb.on("mousedownoutside",this.close_panel,this),this.listenevents.push(i),s=e.bind(this.get("urlmodifier"),this,n.get("href"))(),u=this.get("textcache").retrieve(s),u?this._set_panel_contents(u.response):(o={method:"get",context:this,sync:!1,on:{complete:function(e,t){this._set_panel_contents(t.responseText,s)}}},e.io(s,o))},_set_panel_contents:function(t,n){var r;try{r=e.JSON.parse(t);if(r.error)return this.close_panel(),e.use("moodle-core-notification-ajaxexception",function(){return(new M.core.ajaxException(r)).show()}),this}catch(i){return this.close_panel(),e.use("moodle-core-notification-exception",function(){return(new M.core.exception(i)).show()}),this}e.bind(this.get("headerhandler"),this,r)(),e.bind(this.get("bodyhandler"),this,r)(),e.bind(this.get("footerhandler"),this,r)(),n&&this.get("textcache").add(n,t),this.get("buttons").header[0].focus()},set_header_content:function(e){this.set("headerContent",e.heading)},set_body_content:function(t){var n=e.Node.create("
").set("innerHTML",t.text).setAttribute("role","alert").addClass(i.PANELTEXT);this.set("bodyContent",n)},modify_url:function(e){return e.replace(/\.php\?/,"_ajax.php?")},close_panel:function(e){this.hide(),this.cancel_events(),e&&e.preventDefault()},cancel_events:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()}}),e.Base.modifyAttrs(n,{modal:{value:!1}}),M.core=M.core||{},M.core.tooltip=M.core.tooltip=n},"@VERSION@",{requires:["base","node","io-base","moodle-core-notification-dialogue","json-parse","widget-position","widget-position-align","event-outside","cache-base"]}); diff --git a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js index 31d81fcd77a..03408fe4ac4 100644 --- a/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js +++ b/lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js @@ -379,11 +379,17 @@ Y.extend(TOOLTIP, M.core.dialogue, { responseobject = Y.JSON.parse(response); if (responseobject.error) { this.close_panel(); - return new M.core.ajaxException(responseobject); + Y.use('moodle-core-notification-ajaxexception', function() { + return new M.core.ajaxException(responseobject).show(); + }); + return this; } } catch (error) { this.close_panel(); - return new M.core.exception(error); + Y.use('moodle-core-notification-exception', function() { + return new M.core.exception(error).show(); + }); + return this; } // Set the contents using various handlers. @@ -463,7 +469,7 @@ M.core.tooltip = M.core.tooltip = TOOLTIP; "base", "node", "io-base", - "moodle-core-notification", + "moodle-core-notification-dialogue", "json-parse", "widget-position", "widget-position-align", diff --git a/lib/yui/src/tooltip/js/tooltip.js b/lib/yui/src/tooltip/js/tooltip.js index 2f19a8c58dd..1812cb4174a 100644 --- a/lib/yui/src/tooltip/js/tooltip.js +++ b/lib/yui/src/tooltip/js/tooltip.js @@ -377,11 +377,17 @@ Y.extend(TOOLTIP, M.core.dialogue, { responseobject = Y.JSON.parse(response); if (responseobject.error) { this.close_panel(); - return new M.core.ajaxException(responseobject); + Y.use('moodle-core-notification-ajaxexception', function() { + return new M.core.ajaxException(responseobject).show(); + }); + return this; } } catch (error) { this.close_panel(); - return new M.core.exception(error); + Y.use('moodle-core-notification-exception', function() { + return new M.core.exception(error).show(); + }); + return this; } // Set the contents using various handlers. diff --git a/lib/yui/src/tooltip/meta/tooltip.json b/lib/yui/src/tooltip/meta/tooltip.json index 97bf15275c9..5e3f97737d1 100644 --- a/lib/yui/src/tooltip/meta/tooltip.json +++ b/lib/yui/src/tooltip/meta/tooltip.json @@ -4,7 +4,7 @@ "base", "node", "io-base", - "moodle-core-notification", + "moodle-core-notification-dialogue", "json-parse", "widget-position", "widget-position-align",