From fefb6aca1a56342d411488296efcf8f84b573bee Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 4 Dec 2012 16:03:02 +0100 Subject: [PATCH] multiSelect: Make sure last added entry is selected and some code cleanup. --- core/js/multiselect.js | 75 +++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/core/js/multiselect.js b/core/js/multiselect.js index 59c18d0f81..d41b5d552a 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -10,7 +10,7 @@ */ (function( $ ){ var multiSelectId=-1; - $.fn.multiSelect=function(options){ + $.fn.multiSelect=function(options) { multiSelectId++; var settings = { 'createCallback':false, @@ -24,14 +24,14 @@ 'minWidth': 'default;', }; $.extend(settings,options); - $.each(this.children(),function(i,option){ + $.each(this.children(),function(i,option) { // If the option is selected, but not in the checked array, add it. - if($(option).attr('selected') && settings.checked.indexOf($(option).val()) == -1){ + if($(option).attr('selected') && settings.checked.indexOf($(option).val()) === -1) { settings.checked.push($(option).val()); settings.labels.push($(option).text().trim()); } // If the option is in the checked array but not selected, select it. - else if(settings.checked.indexOf($(option).val()) !== -1 && !$(option).attr('selected')){ + else if(settings.checked.indexOf($(option).val()) !== -1 && !$(option).attr('selected')) { $(option).attr('selected', 'selected'); settings.labels.push($(option).text().trim()); } @@ -43,15 +43,14 @@ button.selectedItems=[]; this.hide(); this.before(span); - if(settings.minWidth=='default'){ + if(settings.minWidth=='default') { settings.minWidth=button.width(); } button.css('min-width',settings.minWidth); settings.minOuterWidth=button.outerWidth()-2; button.data('settings',settings); - if(!settings.singleSelect && settings.checked.length>0){ - //button.children('span').first().text(settings.checked.join(', ')); + if(!settings.singleSelect && settings.checked.length>0) { button.children('span').first().text(settings.labels.join(', ')); } else if(settings.singleSelect) { button.children('span').first().text(this.find(':selected').text()); @@ -62,14 +61,14 @@ button.click(function(event){ var button=$(this); - if(button.parent().children('ul').length>0){ + if(button.parent().children('ul').length>0) { if(self.menuDirection === 'down') { - button.parent().children('ul').slideUp(400,function(){ + button.parent().children('ul').slideUp(400,function() { button.parent().children('ul').remove(); button.removeClass('active'); }); } else { - button.parent().children('ul').fadeOut(400,function(){ + button.parent().children('ul').fadeOut(400,function() { button.parent().children('ul').remove(); button.removeClass('active').removeClass('up'); }); @@ -87,7 +86,7 @@ var options=$(this).parent().next().children(); var list=$('