Only initialise chosen elements when visible.

This commit is contained in:
Andrew Short 2012-07-31 01:14:02 +10:00 committed by Ingo Schommer
parent b38735d536
commit 2503e481ff

View File

@ -20,16 +20,20 @@ jQuery.noConflict();
// apply an select element only when it is ready, ie. when it is rendered into a template
// with css applied and got a width value.
var applyChosen = function(el){
if(el.outerWidth()){
el.chosen({
'disable_search_threshold' : 20,
'allow_single_deselect': true
}).addClass("has-chzn");
// Copy over title attribute if required
if(el.attr('title')) el.siblings('.chzn-container').attr('title', el.attr('title'));
var applyChosen = function(el) {
if(el.is(':visible')) {
el.addClass('has-chzn').chosen({
allow_single_deselect: true,
disable_search_threshold: 20
});
var title = el.prop('title')
if(title) {
el.siblings('.chzn-container').prop('title', title);
}
} else {
setTimeout(function() {applyChosen(el);},500);
setTimeout(function() { applyChosen(el); }, 500);
}
};