Commit bb1ce757 authored by markcarver's avatar markcarver

Issue #3016254 by markcarver, TomiMikola: Dialog buttons bound with mousedown or mouseup don't work

parent 868c5373
......@@ -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;
};
/**
......
......@@ -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);
}
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment