1/** 2 * @file 3 * JavaScript behaviors to fix jQuery UI dialogs. 4 */ 5 6(function ($, Drupal, once, tabbable) { 7 /** 8 * Ensure that ckeditor has focus when displayed inside of jquery-ui dialog widget 9 * 10 * @see http://stackoverflow.com/questions/20533487/how-to-ensure-that-ckeditor-has-focus-when-displayed-inside-of-jquery-ui-dialog 11 */ 12 if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) { 13 var _allowInteraction = $.ui.dialog.prototype._allowInteraction; 14 $.ui.dialog.prototype._allowInteraction = function (event) { 15 if ($(event.target).closest('.cke_dialog').length) { 16 return true; 17 } 18 return _allowInteraction.apply(this, arguments); 19 }; 20 } 21 22 /** 23 * Attaches webform dialog behaviors. 24 * 25 * @type {Drupal~behavior} 26 * 27 * @prop {Drupal~behaviorAttach} attach 28 * Attaches event listeners for webform dialogs. 29 */ 30 Drupal.behaviors.webformDialogEvents = { 31 attach: function () { 32 if (once('webform-dialog', 'html').length) { 33 $(window).on({ 34 'dialog:aftercreate': function (event, dialog, $element, settings) { 35 setTimeout(function () { 36 const tabbableElements = tabbable.tabbable($element.get(0)); 37 var hasFocus = $element.find("[autofocus]"); 38 if (!hasFocus.length) { 39 // Move focus to first input which is not a button. 40 hasFocus = tabbableElements.filter((element) => { 41 // Check if the element is an <input> tag and not a <button> tag 42 return ( 43 element.tagName.toLowerCase() === "input" && 44 element.type !== "button" 45 ); 46 }); 47 hasFocus = $(hasFocus); 48 } 49 if (!hasFocus.length) { 50 // Move focus to close dialog button. 51 hasFocus = $element.parent().find('.ui-dialog-titlebar-close'); 52 } 53 hasFocus.eq(0).trigger('focus'); 54 }); 55 } 56 }); 57 } 58 } 59 }; 60 61})(jQuery, Drupal, once, tabbable);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.