Skip to content

Instantly share code, notes, and snippets.

@wellic
Created September 26, 2019 13:14
Show Gist options
  • Save wellic/fba20cb6041d2ffa8d390b36b25a7654 to your computer and use it in GitHub Desktop.
Save wellic/fba20cb6041d2ffa8d390b36b25a7654 to your computer and use it in GitHub Desktop.
Fix old jquery dialog with select2
//Case 1:.
// https://github.com/select2/select2/issues/1246#issuecomment-71710835
// https://stackoverflow.com/questions/19787982/select2-plugin-and-jquery-ui-modal-dialogs/32099212#32099212
// For select2 v4.+
(function ($) {
if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) {
var own_allowInteraction = $.ui.dialog.prototype._allowInteraction;
$.ui.dialog.prototype._allowInteraction = function (e) {
if ($(e.target).closest('.select2-dropdown').length) return true;
return own_allowInteraction.apply(this, arguments);
};
}
// for version jQuery < 1.10
// else {
// $.error("You must upgrade jQuery UI or else.");
// }
})(jQuery);
//Case 2:.
// https://github.com/select2/select2/issues/1246#issuecomment-71710835
// https://stackoverflow.com/questions/19787982/select2-plugin-and-jquery-ui-modal-dialogs/20031495#20031495
//
//$.ui.dialog.prototype._allowInteraction = function(e) {
// return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-drop').length;
//};
//Case 3:
// https://github.com/ivaynberg/select2/issues/1246
// https://stackoverflow.com/questions/19787982/select2-plugin-and-jquery-ui-modal-dialogs/19788419#19788419
//.
//$('.dialog').dialog({
// modal: true,
// open: function () {
// if ($.ui && $.ui.dialog && !$.ui.dialog.prototype._allowInteractionRemapped && $(this).closest(".ui-dialog").length)
// if ($.ui.dialog.prototype._allowInteraction) {
// $.ui.dialog.prototype._allowInteraction = function (e) {
// if ($(e.target).closest('.select2-drop').length) return true;
// return ui_dialog_interaction.apply(this, arguments);
// };
// $.ui.dialog.prototype._allowInteractionRemapped = true;
// }
// else {
// $.error("You must upgrade jQuery UI or else.");
// }
// }
// },
// _allowInteraction: function (event) {
// return !!$(event.target).is(".select2-input") || this._super(event);
// }
//});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment