diff --git a/datamodels/2.x/itop-portal-base/portal/web/js/bootstrap-patches.js b/datamodels/2.x/itop-portal-base/portal/web/js/bootstrap-patches.js index 576995eb5..2e47532fb 100644 --- a/datamodels/2.x/itop-portal-base/portal/web/js/bootstrap-patches.js +++ b/datamodels/2.x/itop-portal-base/portal/web/js/bootstrap-patches.js @@ -2,18 +2,20 @@ * Patches for bootstrap 3 as it is no longer maintained by its editor */ -//N°2166: Fix a boostrap/CKeditor incompatibility with their respective modals (source: https://stackoverflow.com/a/23667151) -$.fn.modal.Constructor.prototype.enforceFocus = function () { - var $modalElement = this.$element; - $(document).on('focusin.modal', function (e) { - var $parent = $(e.target.parentNode); - if ($modalElement[0] !== e.target && !$modalElement.has(e.target).length - // add whatever conditions you need here: - && - !$parent.hasClass('cke_dialog_ui_input_select') && !$parent.hasClass('cke_dialog_ui_input_text')) { - $modalElement.focus() - } - }) +//N°2166: Fix a boostrap/CKeditor incompatibility with their respective modals (source: https://stackoverflow.com/a/31679096) +$.fn.modal.Constructor.prototype.enforceFocus = function() { + $( document ) + .off( 'focusin.bs.modal' ) // guard against infinite focus loop + .on( 'focusin.bs.modal', $.proxy( function( e ) { + if ( + this.$element[ 0 ] !== e.target && !this.$element.has( e.target ).length + // CKEditor compatibility fix start. + && !$( e.target ).closest( '.cke_dialog, .cke' ).length + // CKEditor compatibility fix end. + ) { + this.$element.trigger( 'focus' ); + } + }, this ) ); }; // Hack to enable multiple modals by making sure the .modal-open class is set to the when there is at least one modal open left