(function(b){var g={init:function(a){this.settings={};if(a)this.settings=b.extend(this.settings,a);var e=this;e.hide();e.each(function(){var a=b(this),c=b('
').detach(),f=b('
').detach(),h=b('
').detach(),i=b("").detach(),g=b("").detach();a.data("settings",e.settings);a.children("option").each(function(){var c=b('
  • '+b(this).text()+ "
  • ").detach();c.click(function(){a.multiSelect("select",b(this).attr("ms-value"))});i.append(c)});f.append(i);h.append(g);c.append(f);c.append(h);a.after(c);a.children("option:selected").each(function(){a.multiSelect("select",b(this).val(),"init")})})},select:function(a,e){var d=this,c=d.val()?d.val():[];if(b.inArray(a,c)==-1||e=="init"){var f=b('
  • '+d.find('option[value="'+a+'"]').text()+"
  • ").detach(),c=b.merge(c,[a]),h=b("#ms-"+d.attr("id")+" .ms-selectable ul"),g=b("#ms-"+ d.attr("id")+" .ms-selection ul");h.children('li[ms-value="'+a+'"]').hide();d.val(c);f.click(function(){d.multiSelect("deselect",b(this).attr("ms-value"))});g.append(f);typeof d.data("settings").afterSelect=="function"&&e!="init"&&d.data("settings").afterSelect.call(this,a,text)}},deselect:function(a){var e=this.val()?this.val():[],d=!1,e=b.map(e,function(b){if(b!=a)return b;else d=!0});if(d){var c=b("#ms-"+this.attr("id")+" .ms-selectable ul"),f=b("#ms-"+this.attr("id")+" .ms-selection ul"),c=c.children('li[ms-value="'+ a+'"]'),f=f.children('li[ms-value="'+a+'"]').detach();this.val(e);c.show();f.remove();typeof this.data("settings").afterDeselect=="function"&&this.data("settings").afterDeselect.call(this,a,f.text())}},select_all:function(){var a=this;a.children("option").each(function(){a.multiSelect("select",b(this).val(),"select_all")})},deselect_all:function(){var a=this;a.children("option").each(function(){a.multiSelect("deselect",b(this).val(),"deselect_all")})}};b.fn.multiSelect=function(a){if(g[a])return g[a].apply(this, Array.prototype.slice.call(arguments,1));else if(typeof a==="object"||!a)return g.init.apply(this,arguments);else console.log&&console.log("Method "+a+" does not exist on jquery.multiSelect")}})(jQuery);