summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Carver2018-11-29 17:03:14 (GMT)
committerMark Carver2018-11-29 17:03:14 (GMT)
commitbb1ce75781637c20da529d356ba325b317bfed89 (patch)
tree6224d256e67aa892e46d8675c20cd2e31f1ffb89
parent868c53736390333a3f2bde588581c18091575ffa (diff)
Issue #3016254 by markcarver, TomiMikola: Dialog buttons bound with mousedown or mouseup don't work
-rw-r--r--js/drupal.bootstrap.js84
-rw-r--r--js/misc/dialog.ajax.js17
2 files changed, 57 insertions, 44 deletions
diff --git a/js/drupal.bootstrap.js b/js/drupal.bootstrap.js
index 32ddba1..1157a91 100644
--- a/js/drupal.bootstrap.js
+++ b/js/drupal.bootstrap.js
@@ -365,8 +365,8 @@
* A DOM element to dispatch event on. Note: this may be a jQuery object,
* however be aware that this will trigger the same event for each element
* inside the jQuery collection; use with caution.
- * @param {String} type
- * The type of event to simulate.
+ * @param {String|String[]} type
+ * The type(s) of event to simulate.
* @param {Object} [options]
* An object of options to pass to the event constructor. Typically, if
* an event is being proxied, you should just pass the original event
@@ -380,8 +380,8 @@
*/
Bootstrap.simulate = function (element, type, options) {
// Handle jQuery object wrappers so it triggers on each element.
+ var ret = true;
if (element instanceof $) {
- var ret = true;
element.each(function () {
if (!Bootstrap.simulate(this, type, options)) {
ret = false;
@@ -404,42 +404,52 @@
var event;
var ctor;
- for (var name in this.eventMap) {
- if (this.eventMap[name].test(type)) {
- ctor = name;
- break;
+ var types = [].concat(type);
+ for (var i = 0, l = types.length; i < l; i++) {
+ type = types[i];
+ for (var name in this.eventMap) {
+ if (this.eventMap[name].test(type)) {
+ ctor = name;
+ break;
+ }
+ }
+ if (!ctor) {
+ throw new SyntaxError('Only rudimentary HTMLEvents, KeyboardEvents and MouseEvents are supported: ' + type);
+ }
+ var opts = {bubbles: true, cancelable: true};
+ if (ctor === 'KeyboardEvent' || ctor === 'MouseEvent') {
+ $.extend(opts, {ctrlKey: !1, altKey: !1, shiftKey: !1, metaKey: !1});
+ }
+ if (ctor === 'MouseEvent') {
+ $.extend(opts, {button: 0, pointerX: 0, pointerY: 0, view: window});
+ }
+ if (options) {
+ $.extend(opts, options);
+ }
+ if (typeof window[ctor] === 'function') {
+ event = new window[ctor](type, opts);
+ if (!element.dispatchEvent(event)) {
+ ret = false;
+ }
+ }
+ else if (document.createEvent) {
+ event = document.createEvent(ctor);
+ event.initEvent(type, opts.bubbles, opts.cancelable);
+ if (!element.dispatchEvent(event)) {
+ ret = false;
+ }
+ }
+ else if (typeof element.fireEvent === 'function') {
+ event = $.extend(document.createEventObject(), opts);
+ if (!element.fireEvent('on' + type, event)) {
+ ret = false;
+ }
+ }
+ else if (typeof element[type]) {
+ element[type]();
}
}
- if (!ctor) {
- throw new SyntaxError('Only rudimentary HTMLEvents, KeyboardEvents and MouseEvents are supported: ' + type);
- }
- var opts = {bubbles: true, cancelable: true};
- if (ctor === 'KeyboardEvent' || ctor === 'MouseEvent') {
- $.extend(opts, {ctrlKey: !1, altKey: !1, shiftKey: !1, metaKey: !1});
- }
- if (ctor === 'MouseEvent') {
- $.extend(opts, {button: 0, pointerX: 0, pointerY: 0, view: window});
- }
- if (options) {
- $.extend(opts, options);
- }
- if (typeof window[ctor] === 'function') {
- event = new window[ctor](type, opts);
- return element.dispatchEvent(event);
- }
- else if (document.createEvent) {
- event = document.createEvent(ctor);
- event.initEvent(type, opts.bubbles, opts.cancelable);
- return element.dispatchEvent(event);
- }
- else if (typeof element.fireEvent === 'function') {
- event = $.extend(document.createEventObject(), opts);
- return element.fireEvent('on' + type, event);
- }
- else if (typeof element[type]) {
- element[type]();
- return true;
- }
+ return ret;
};
/**
diff --git a/js/misc/dialog.ajax.js b/js/misc/dialog.ajax.js
index 7bfdcd3..1820062 100644
--- a/js/misc/dialog.ajax.js
+++ b/js/misc/dialog.ajax.js
@@ -37,7 +37,7 @@
* {@inheritdoc}
*/
Drupal.behaviors.dialog.prepareDialogButtons = function prepareDialogButtons($dialog) {
- var _that = this;
+ var _this = this;
var buttons = [];
var $buttons = $dialog.find('.form-actions').find('button, input[type=submit], .form-actions a.button');
$buttons.each(function () {
@@ -65,14 +65,17 @@
click: function click(e) {
e.preventDefault();
e.stopPropagation();
- _that.ajaxCurrentButton = $(e.target);
- _that.ajaxOriginalButton = $originalButton;
- Bootstrap.simulate($originalButton, 'click');
+ _this.ajaxCurrentButton = $(e.target);
+ _this.ajaxOriginalButton = $originalButton;
+ // Some core JS binds dialog buttons to the mousedown or mouseup
+ // events instead of click; all three events must be simulated here.
+ // @see https://www.drupal.org/project/bootstrap/issues/3016254
+ Bootstrap.simulate($originalButton, ['mousedown', 'mouseup', 'click']);
},
create: function () {
- _that.ajaxCurrentButton = $(this);
- _that.ajaxOriginalButton = $originalButton;
- _that.ajaxUpdateButtons(true);
+ _this.ajaxCurrentButton = $(this);
+ _this.ajaxOriginalButton = $originalButton;
+ _this.ajaxUpdateButtons(true);
}
});
});