diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index 5c25713..dc00ad0 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -99,7 +99,8 @@ var that = this, ms = that.$element, attributes = "", - $option = $(option); + $option = $(option), + selected = false; for (var cpt = 0; cpt < option.attributes.length; cpt++){ var attr = option.attributes[cpt]; @@ -107,6 +108,10 @@ if(attr.name !== 'value' && attr.name !== 'disabled'){ attributes += attr.name+'="'+attr.value+'" '; } + + if(attr.name == 'selected'){ + selected = true; + } } var selectableLi = $('
  • '+that.escapeHTML($option.text())+'
  • '), selectedLi = selectableLi.clone(), @@ -169,6 +174,10 @@ selectableLi.insertAt(index, that.$selectableUl); selectedLi.insertAt(index, that.$selectionUl); } + + if(selected){ + that.select($option.val(),'init'); + } }, 'addOption' : function(options){ @@ -180,12 +189,14 @@ $.each(options, function(index, option){ if (option.value !== undefined && option.value !== null && that.$element.find("option[value='"+option.value+"']").length === 0){ - var $option = $(''), + var selected = option.selected ? 'selected':'a'; + var $option = $(''), index = parseInt((typeof option.index === 'undefined' ? that.$element.children().length : option.index)), $container = option.nested == undefined ? that.$element : $("optgroup[label='"+option.nested+"']") $option.insertAt(index, $container); that.generateLisFromOption($option.get(0), index, option.nested); + that.$element.find('option').eq(index).before($option); } }) },