Elastic: Fix pretty select so it works after being cloned

pull/5578/merge
Aleksander Machniak 7 years ago
parent 03af7e47e3
commit bbb0b5b5b0

@ -3042,6 +3042,10 @@ function rcube_elastic_ui()
select = $(select); select = $(select);
if (select.is('.pretty-select')) {
return;
}
var select_ident = 'select' + select.attr('id') + select.attr('name'); var select_ident = 'select' + select.attr('id') + select.attr('name');
var is_menu_open = function() { var is_menu_open = function() {
// Use proper window in cases when the select element intialized // Use proper window in cases when the select element intialized
@ -3161,40 +3165,44 @@ function rcube_elastic_ui()
.popover('show'); .popover('show');
}; };
select.on('mousedown keydown', function(e) { select.addClass('pretty-select')
// Do nothing on disabled select or on TAB key .on('mousedown keydown', function(e) {
if (select.prop('disabled')) { select = $(e.target); // so it works after clone
return;
}
if (e.which == 9) { // Do nothing on disabled select or on TAB key
close_func(); if (select.prop('disabled')) {
return true; return;
} }
// Close popup on ESC key or on click if already open if (e.which == 9) {
if (e.which == 27 || (e.type == 'mousedown' && is_menu_open())) { close_func();
return close_func(); return true;
} }
// Close popup on ESC key or on click if already open
if (e.which == 27 || (e.type == 'mousedown' && is_menu_open())) {
return close_func();
}
select.focus(); select.focus();
// prevent displaying browser-default select dropdown // prevent displaying browser-default select dropdown
select.prop('disabled', true); select.prop('disabled', true);
setTimeout(function() { select.prop('disabled', false); }, 0); setTimeout(function() { select.prop('disabled', false); }, 0);
e.stopPropagation(); e.stopPropagation();
// display options in our way (on SPACE, ENTER, ARROW-DOWN or mousedown) // display options in our way (on SPACE, ENTER, ARROW-DOWN or mousedown)
if (e.type == 'mousedown' || e.which == 13 || e.which == 32 || e.which == 40 || e.which == 63233) { if (e.type == 'mousedown' || e.which == 13 || e.which == 32 || e.which == 40 || e.which == 63233) {
open_func(e); open_func(e);
return false;
}
})
.on('click', function(e) {
// Stop propagation of click event to prevent from
// disposing the menu by general popover closing handler (popups_close())
e.stopPropagation();
return false; return false;
} });
}).on('click', function(e) {
// Stop propagation of click event to prevent from
// disposing the menu by general popover closing handler (popups_close())
e.stopPropagation();
return false;
});
}; };
/** /**

Loading…
Cancel
Save