-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.multiselects-0.3.min.js
1 lines (1 loc) · 1.53 KB
/
jquery.multiselects-0.3.min.js
1
(function(a){a.fn.multiSelect=function(h,k){k=a.extend({keepSelected:false,autoSubmit:true,button_select:null,button_select_all:null,button_deselect:null,button_deselect_all:null,autoSort:true,sortType:"value",sortDesc:false,beforeMove:null,afterMove:null},k);var f=this;var g=a(h);if(k.autoSubmit){this.parents("form").submit(function(){b(g)})}var d=function(o,q,p){var l=p?-1:1;if(typeof q=="function"){var n=q}else{if(q=="key"){var n=function(s,r){return l*((r.value<s.value)-(s.value<r.value))}}else{var n=function(s,r){return l*((a(r).text()<a(s).text())-(a(s).text()<a(r).text()))}}}var m=a.makeArray(a("option",o).detach()).sort(n);a(o).append(m)};var j=function(l){if(!k.autoSort){return}d(l,k.sortType,k.sortDesc)};j(f);j(g);var i=function(n,m,l){e(n,m,l,k.beforeMove,k.afterMove,j)};var c=function(m,l){if(k.beforeMove&&!k.beforeMove(m,h,"all")){return}a("option",m).attr("selected","selected");i(m,l);j(h);k.afterMove&&k.afterMove(m,h,"all")};f.dblclick(function(){i(f,g,"select")});if(k.button_select){a(k.button_select).click(function(){i(f,g,"select")})}if(k.button_select_all){a(k.button_select_all).click(function(){c(f,g)})}g.dblclick(function(){i(g,f,"deselect")});if(k.button_deselect){a(k.button_deselect).click(function(){i(g,f,"deselect")})}if(k.button_deselect_all){a(k.button_deselect_all).click(function(){c(g,f)})}return this;function e(q,p,n,o,m,l){if(o&&!o(q,p,n)){return}a("option:selected",q).each(function(){a(this).appendTo(p)});l(p);m&&m(q,p,n)}function b(l){l.children("option").each(function(){this.selected=true})}}})(jQuery);