(function($){ var msMethods = { 'init' : function(options){ this.settings = { disabledClass : 'disabled' }; if(options) { this.settings = $.extend(this.settings, options); } var multiSelects = this; multiSelects.hide(); multiSelects.each(function(){ var ms = $(this); ms.attr('id', ms.attr('id') != undefined ? ms.attr('id') : 'ms-'+Math.ceil(Math.random()*1000)); var container = $('
'), selectableContainer = $('
'), selectedContainer = $('
'), selectableUl = $(''), selectedUl = $(''); ms.data('settings', multiSelects.settings); ms.children('option').each(function(){ var selectableLi = $('
  • '+$(this).text()+'
  • '); // if ($(this).attr('title')) // selectableLi.attr('title', $(this).attr('title')); if ($(this).attr('disabled') || ms.attr('disabled')){ selectableLi.attr('disabled', 'disabled'); selectableLi.addClass(multiSelects.settings.disabledClass) } selectableLi.click(function(){ ms.multiSelect('select', $(this).attr('ms-value')); }); selectableUl.append(selectableLi); }); if (multiSelects.settings.selectableHeader){ selectableContainer.append(multiSelects.settings.selectableHeader); } selectableContainer.append(selectableUl); if (multiSelects.settings.selectedHeader){ selectedContainer.append(multiSelects.settings.selectedHeader); } selectedContainer.append(selectedUl); container.append(selectableContainer); container.append(selectedContainer); ms.after(container); ms.children('option:selected').each(function(){ ms.multiSelect('select', $(this).val(), 'init'); }); }); }, 'select' : function(value, method){ var ms = this, msValues = (ms.val() ? ms.val() : []), alreadyPresent = $.inArray(value, msValues), text = ms.find('option[value="'+value+'"]').text(); title_attr = ms.find('option[value="'+value+'"]').attr('title'); if(alreadyPresent == -1 || method == 'init'){ <<<<<<< HEAD var selectedLi = $('
  • '+text+'
  • '), ======= var selectedLi = $('
  • '+text+'
  • ').detach(), >>>>>>> 46ec109620af198e54c3bbbac2bf60e64618f027 newValues = $.merge(msValues, [value]), selectableUl = $('#ms-'+ms.attr('id')+' .ms-selectable ul'), selectedUl = $('#ms-'+ms.attr('id')+' .ms-selection ul'), selectableLi = selectableUl.children('li[ms-value="'+value+'"]'); <<<<<<< HEAD if (!selectableLi.attr('disabled')){ selectableLi.hide(); ms.val(newValues); selectedLi.click(function(){ ms.multiSelect('deselect', $(this).attr('ms-value')); }); selectedUl.append(selectedLi); if (typeof ms.data('settings').afterSelect == 'function' && method != 'init') { ms.data('settings').afterSelect.call(this, value, text); } ======= selectableLi.hide(); ms.val(newValues); selectedLi.click(function(){ ms.multiSelect('deselect', $(this).attr('ms-value')); }); selectedUl.append(selectedLi); if (typeof ms.data('settings').afterSelect == 'function' && method != 'init') { ms.data('settings').afterSelect.call(this, value, text); >>>>>>> 46ec109620af198e54c3bbbac2bf60e64618f027 } } }, 'deselect' : function(value){ var ms = this, msValues = (ms.val() ? ms.val() : []), present = false, newValues = $.map(msValues, function(e){ if(e != value){ return e; }else{ present = true} return false;}); if(present){ var selectableUl = $('#ms-'+ms.attr('id')+' .ms-selectable ul'), selectedUl = $('#ms-'+ms.attr('id')+' .ms-selection ul'), selectableLi = selectableUl.children('li[ms-value="'+value+'"]'), <<<<<<< HEAD selectedLi = selectedUl.children('li[ms-value="'+value+'"]'); ======= selectedLi = selectedUl.children('li[ms-value="'+value+'"]').detach(); >>>>>>> 46ec109620af198e54c3bbbac2bf60e64618f027 ms.val(newValues); selectableLi.show(); selectedLi.remove(); if (typeof ms.data('settings').afterDeselect == 'function') { ms.data('settings').afterDeselect.call(this, value, selectedLi.text()); } } }, 'select_all' : function(){ var ms = this; ms.children('option').each(function(){ ms.multiSelect('select', $(this).val(), 'select_all'); }); }, 'deselect_all' :function(){ var ms = this; ms.children('option').each(function(){ ms.multiSelect('deselect', $(this).val(), 'deselect_all'); }); } }; $.fn.multiSelect = function(method){ if ( msMethods[method] ) { return msMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return msMethods.init.apply( this, arguments ); } else { if(console.log) console.log( 'Method ' + method + ' does not exist on jquery.multiSelect' ); } return false; }; })(jQuery);