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.
This commit is contained in:
Andrew Nicols
2014-01-29 11:20:31 +08:00
parent 953239d6b5
commit 2f2ccf4b81
4 changed files with 95 additions and 38 deletions
@@ -145,7 +145,7 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, DIALOGUE, {
_enterKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.COUNT + '" value="'+this.get(CONFIRMYES)+'" />'),
@@ -158,11 +158,21 @@ Y.extend(ALERT, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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();
@@ -196,8 +206,7 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, DIALOGUE, {
_enterKeypress : null,
_escKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
this.publish('complete-yes');
@@ -214,14 +223,24 @@ Y.extend(CONFIRM, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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');
File diff suppressed because one or more lines are too long
@@ -145,7 +145,7 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, DIALOGUE, {
_enterKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.COUNT + '" value="'+this.get(CONFIRMYES)+'" />'),
@@ -158,11 +158,21 @@ Y.extend(ALERT, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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();
@@ -196,8 +206,7 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, DIALOGUE, {
_enterKeypress : null,
_escKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
this.publish('complete-yes');
@@ -214,14 +223,24 @@ Y.extend(CONFIRM, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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');
+31 -12
View File
@@ -143,7 +143,7 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, DIALOGUE, {
_enterKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.COUNT + '" value="'+this.get(CONFIRMYES)+'" />'),
@@ -156,11 +156,21 @@ Y.extend(ALERT, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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();
@@ -194,8 +204,7 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, DIALOGUE, {
_enterKeypress : null,
_escKeypress : null,
closeEvents: [],
initializer : function() {
this.publish('complete');
this.publish('complete-yes');
@@ -212,14 +221,24 @@ Y.extend(CONFIRM, DIALOGUE, {
this.setStdModContent(Y.WidgetStdMod.HEADER, '<h1 id="moodle-dialogue-'+COUNT+'-header-text">'
+ this.get(TITLE) + '</h1>', 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');