X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fthemes%2Fcontrib%2Fbootstrap%2Fjs%2Fmisc%2Fdialog.ajax.js;fp=web%2Fthemes%2Fcontrib%2Fbootstrap%2Fjs%2Fmisc%2Fdialog.ajax.js;h=7bfdcd33a63032d28f768d219ab6883069432db8;hp=f5c853cb41b383ad4cbdcb9cb5ca3efc18f2626f;hb=dd08b95e4e519a02d45a50fb504bf5d685eaa9e3;hpb=0bf8d09d2542548982e81a441b1f16e75873a04f diff --git a/web/themes/contrib/bootstrap/js/misc/dialog.ajax.js b/web/themes/contrib/bootstrap/js/misc/dialog.ajax.js index f5c853cb4..7bfdcd33a 100644 --- a/web/themes/contrib/bootstrap/js/misc/dialog.ajax.js +++ b/web/themes/contrib/bootstrap/js/misc/dialog.ajax.js @@ -2,25 +2,34 @@ * @file * dialog.ajax.js */ -(function ($, Drupal) { +(function ($, Drupal, Bootstrap) { - var dialogAjaxCurrentButton; - var dialogAjaxOriginalButton; + Drupal.behaviors.dialog.ajaxCurrentButton = null; + Drupal.behaviors.dialog.ajaxOriginalButton = null; + + /** + * Synchronizes a faux button with its original counterpart. + * + * @param {Boolean} [reset = false] + * Whether to reset the current and original buttons after synchronizing. + */ + Drupal.behaviors.dialog.ajaxUpdateButtons = function (reset) { + if (this.ajaxCurrentButton && this.ajaxOriginalButton) { + this.ajaxCurrentButton.html(this.ajaxOriginalButton.html()); + this.ajaxCurrentButton.prop('disabled', this.ajaxOriginalButton.prop('disabled')); + } + if (reset) { + this.ajaxCurrentButton = null; + this.ajaxOriginalButton = null; + } + }; $(document) .ajaxSend(function () { - if (dialogAjaxCurrentButton && dialogAjaxOriginalButton) { - dialogAjaxCurrentButton.html(dialogAjaxOriginalButton.html()); - dialogAjaxCurrentButton.prop('disabled', dialogAjaxOriginalButton.prop('disabled')); - } + Drupal.behaviors.dialog.ajaxUpdateButtons(); }) .ajaxComplete(function () { - if (dialogAjaxCurrentButton && dialogAjaxOriginalButton) { - dialogAjaxCurrentButton.html(dialogAjaxOriginalButton.html()); - dialogAjaxCurrentButton.prop('disabled', dialogAjaxOriginalButton.prop('disabled')); - } - dialogAjaxCurrentButton = null; - dialogAjaxOriginalButton = null; + Drupal.behaviors.dialog.ajaxUpdateButtons(true); }) ; @@ -28,34 +37,46 @@ * {@inheritdoc} */ Drupal.behaviors.dialog.prepareDialogButtons = function prepareDialogButtons($dialog) { + var _that = this; var buttons = []; var $buttons = $dialog.find('.form-actions').find('button, input[type=submit], .form-actions a.button'); $buttons.each(function () { - var $originalButton = $(this).css({ - display: 'block', - width: 0, - height: 0, - padding: 0, - border: 0, - overflow: 'hidden' - }); - var classes = $originalButton.attr('class').replace('use-ajax-submit', ''); + var $originalButton = $(this) + // Prevent original button from being tabbed to. + .attr('tabindex', -1) + // Visually make the original button invisible, but don't actually hide + // or remove it from the DOM because the click needs to be proxied from + // the faux button created in the footer to its original counterpart. + .css({ + display: 'block', + width: 0, + height: 0, + padding: 0, + border: 0, + overflow: 'hidden' + }); + buttons.push({ - text: $originalButton.html() || $originalButton.attr('value'), - class: classes, + // Strip all HTML from the actual text value. This value is escaped. + // It actual HTML value will be synced with the original button's HTML + // below in the "create" method. + text: Bootstrap.stripHtml($originalButton), + class: $originalButton.attr('class').replace('use-ajax-submit', ''), click: function click(e) { - dialogAjaxCurrentButton = $(e.target); - dialogAjaxOriginalButton = $originalButton; - if ($originalButton.is('a')) { - $originalButton[0].click(); - } - else { - $originalButton.trigger('mousedown').trigger('mouseup').trigger('click'); - e.preventDefault(); - } + e.preventDefault(); + e.stopPropagation(); + _that.ajaxCurrentButton = $(e.target); + _that.ajaxOriginalButton = $originalButton; + Bootstrap.simulate($originalButton, 'click'); + }, + create: function () { + _that.ajaxCurrentButton = $(this); + _that.ajaxOriginalButton = $originalButton; + _that.ajaxUpdateButtons(true); } }); }); + return buttons; };