From 649c80e6a449527764a6012c30e168edb4a907b6 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 28 Jan 2014 16:01:59 +0800 Subject: [PATCH] MDL-43885 Javascript: Make the [X] button work like 'No' in relevant dialogues The [X] button on the dialogue is another form of the 'No' button and should behave as such. In some dialogues this matters more than others because the dialogue is destroyed. --- .../moodle-core-notification-alert-debug.js | 18 ++++++++++--- .../moodle-core-notification-alert-min.js | 2 +- .../moodle-core-notification-alert.js | 18 ++++++++++--- .../moodle-core-notification-confirm-debug.js | 25 +++++++++++++------ .../moodle-core-notification-confirm-min.js | 2 +- .../moodle-core-notification-confirm.js | 25 +++++++++++++------ lib/yui/src/notification/js/alert.js | 18 ++++++++++--- lib/yui/src/notification/js/confirm.js | 25 +++++++++++++------ 8 files changed, 95 insertions(+), 38 deletions(-) diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js index 2d90867b424..944cea06772 100644 --- a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js @@ -52,7 +52,7 @@ ALERT = function(config) { ALERT.superclass.constructor.apply(this, [config]); }; Y.extend(ALERT, M.core.dialogue, { - _enterKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); var yes = Y.Node.create(''), @@ -65,11 +65,21 @@ Y.extend(ALERT, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this), + yes.on('click', this.submit, this) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function() { - this._enterKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete'); this.hide(); this.destroy(); diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js index 18a02823ade..c9bacb87e9b 100644 --- a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js @@ -1 +1 @@ -YUI.add("moodle-core-notification-alert",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var l="Moodle alert",c;c=function(e){e.closeButton=!1,c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{_enterKeypress:null,initializer:function(){this.publish("complete");var t=e.Node.create(''),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('
').append(t));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this)},submit:function(){this._enterKeypress.detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:l,CSS_PREFIX:n,ATTRS:{title:{validator:e.Lang.isString,value:"Alert"},message:{validator:e.Lang.isString,value:"Confirm"},yesLabel:{validator:e.Lang.isString,setter:function(e){return e||(e="Ok"),e},value:"Ok"}}}),M.core.alert=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); +YUI.add("moodle-core-notification-alert",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var l="Moodle alert",c;c=function(e){e.closeButton=!1,c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{closeEvents:[],initializer:function(){this.publish("complete");var t=e.Node.create(''),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('
').append(t));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this.closeEvents.push(e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this));var i=this.get("boundingBox").one(".closebutton");i&&this.closeEvents.push(i.on("click",this.submit,this))},submit:function(){(new e.EventHandle(this.closeEvents)).detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:l,CSS_PREFIX:n,ATTRS:{title:{validator:e.Lang.isString,value:"Alert"},message:{validator:e.Lang.isString,value:"Confirm"},yesLabel:{validator:e.Lang.isString,setter:function(e){return e||(e="Ok"),e},value:"Ok"}}}),M.core.alert=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js index 2d90867b424..944cea06772 100644 --- a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js @@ -52,7 +52,7 @@ ALERT = function(config) { ALERT.superclass.constructor.apply(this, [config]); }; Y.extend(ALERT, M.core.dialogue, { - _enterKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); var yes = Y.Node.create(''), @@ -65,11 +65,21 @@ Y.extend(ALERT, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this), + yes.on('click', this.submit, this) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function() { - this._enterKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete'); this.hide(); this.destroy(); diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js index cf8103cccdf..de34749cdcb 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js @@ -51,8 +51,7 @@ CONFIRM = function(config) { CONFIRM.superclass.constructor.apply(this, [config]); }; Y.extend(CONFIRM, M.core.dialogue, { - _enterKeypress : null, - _escKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); this.publish('complete-yes'); @@ -69,14 +68,24 @@ Y.extend(CONFIRM, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); + + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this, true), + Y.on('key', this.submit, window, 'down:27', this, false), + yes.on('click', this.submit, this, true), + no.on('click', this.submit, this, false) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete', outcome); if (outcome) { this.fire('complete-yes'); diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js index cdef098e771..b1006d2e097 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js @@ -1 +1 @@ -YUI.add("moodle-core-notification-confirm",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var l="Moodle confirmation dialogue",c;c=function(e){c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{_enterKeypress:null,_escKeypress:null,initializer:function(){this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create(''),n=e.Node.create(''),i=e.Node.create('
').append(e.Node.create('
'+this.get(a)+"
")).append(e.Node.create('
').append(t).append(n));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,i,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this,!0),this._escKeypress=e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1)},submit:function(e,t){this._enterKeypress.detach(),this._escKeypress.detach(),this.fire("complete",t),t?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:l,CSS_PREFIX:n,ATTRS:{yesLabel:{validator:e.Lang.isString,value:"Yes"},noLabel:{validator:e.Lang.isString,value:"No"},title:{validator:e.Lang.isString,value:"Confirm"},question:{validator:e.Lang.isString,value:"Are you sure?"}}}),e.augment(c,e.EventTarget),M.core.confirm=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); +YUI.add("moodle-core-notification-confirm",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var l="Moodle confirmation dialogue",c;c=function(e){c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{closeEvents:[],initializer:function(){this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create(''),n=e.Node.create(''),i=e.Node.create('
').append(e.Node.create('
'+this.get(a)+"
")).append(e.Node.create('
').append(t).append(n));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,i,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this.closeEvents.push(e.on("key",this.submit,window,"down:13",this,!0),e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1));var f=this.get("boundingBox").one(".closebutton");f&&this.closeEvents.push(f.on("click",this.submit,this))},submit:function(t,n){(new e.EventHandle(this.closeEvents)).detach(),this.fire("complete",n),n?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:l,CSS_PREFIX:n,ATTRS:{yesLabel:{validator:e.Lang.isString,value:"Yes"},noLabel:{validator:e.Lang.isString,value:"No"},title:{validator:e.Lang.isString,value:"Confirm"},question:{validator:e.Lang.isString,value:"Are you sure?"}}}),e.augment(c,e.EventTarget),M.core.confirm=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js index cf8103cccdf..de34749cdcb 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js @@ -51,8 +51,7 @@ CONFIRM = function(config) { CONFIRM.superclass.constructor.apply(this, [config]); }; Y.extend(CONFIRM, M.core.dialogue, { - _enterKeypress : null, - _escKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); this.publish('complete-yes'); @@ -69,14 +68,24 @@ Y.extend(CONFIRM, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); + + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this, true), + Y.on('key', this.submit, window, 'down:27', this, false), + yes.on('click', this.submit, this, true), + no.on('click', this.submit, this, false) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete', outcome); if (outcome) { this.fire('complete-yes'); diff --git a/lib/yui/src/notification/js/alert.js b/lib/yui/src/notification/js/alert.js index f51c20b03ac..45a073224a8 100644 --- a/lib/yui/src/notification/js/alert.js +++ b/lib/yui/src/notification/js/alert.js @@ -21,7 +21,7 @@ ALERT = function(config) { ALERT.superclass.constructor.apply(this, [config]); }; Y.extend(ALERT, M.core.dialogue, { - _enterKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); var yes = Y.Node.create(''), @@ -34,11 +34,21 @@ Y.extend(ALERT, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this), + yes.on('click', this.submit, this) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function() { - this._enterKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete'); this.hide(); this.destroy(); diff --git a/lib/yui/src/notification/js/confirm.js b/lib/yui/src/notification/js/confirm.js index fe80edc7e9e..a0350d63bad 100644 --- a/lib/yui/src/notification/js/confirm.js +++ b/lib/yui/src/notification/js/confirm.js @@ -20,8 +20,7 @@ CONFIRM = function(config) { CONFIRM.superclass.constructor.apply(this, [config]); }; Y.extend(CONFIRM, M.core.dialogue, { - _enterKeypress : null, - _escKeypress : null, + closeEvents: [], initializer : function() { this.publish('complete'); this.publish('complete-yes'); @@ -38,14 +37,24 @@ Y.extend(CONFIRM, M.core.dialogue, { this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); + + this.closeEvents.push( + Y.on('key', this.submit, window, 'down:13', this, true), + Y.on('key', this.submit, window, 'down:27', this, false), + yes.on('click', this.submit, this, true), + no.on('click', this.submit, this, false) + ); + + var closeButton = this.get('boundingBox').one('.closebutton'); + if (closeButton) { + // The close button should act exactly like the 'No' button. + this.closeEvents.push( + closeButton.on('click', this.submit, this) + ); + } }, submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); + new Y.EventHandle(this.closeEvents).detach(); this.fire('complete', outcome); if (outcome) { this.fire('complete-yes');