(function($) { var options = {}; $.fn.gs_multiselect = function(params) { options = $.extend({}, $.fn.gs_multiselect.defaults, params); return this.each(function() { var list_options={}; var list_names={}; var idx={}; var rw=Math.min(400,this.offsetWidth); var rh=this.offsetHeight; var t=document.createElement('table'); var to_sel=this.parentNode.replaceChild(t,this); var from_sel=$('').get(0); var r=t.insertRow(0); if (options.buttons) { var c1=r.insertCell(0); var c2=r.insertCell(1); var c3=r.insertCell(2); var btl_all=$('').get(0); //var tl_filter=$('').get(0); //c1.appendChild(tl_filter); c1.appendChild(btl_all); var btr_all=btl_all.cloneNode(true); c3.appendChild(btr_all); btl_all.onclick=function () { $('option',from_sel).each(function() {this.selected=!this.selected;}); $('option',to_sel).attr('selected',false); } btr_all.onclick=function () { $('option',from_sel).attr('selected',false); $('option',to_sel).each(function() {this.selected=!this.selected;}); } r=t.insertRow(1); } var fc=r.insertCell(0); var mc=r.insertCell(1); var lc=r.insertCell(2); var o_lc=lc; lc.appendChild(to_sel); $(fc).append($(from_sel)); //var from_sel=fc.firstChild; var sel_name=to_sel.getAttribute('name'); to_sel.setAttribute('name',''); $(from_sel).html($(to_sel).html()); $(this).html(''); from_sel.style.height=to_sel.style.height=rh+'px'; from_sel.style.width=to_sel.style.width=rw+'px'; var fb=$(''); var bb=$(''); mc.appendChild(fb.get(0)); mc.appendChild(document.createElement('br')); mc.appendChild(bb.get(0)); var list=from_sel.cloneNode(true); //if (list.innerHTML!='') $(list).filter('option').each(function (i) { if (list.innerHTML!='') $('option',list).each(function (i) { list_options[this.value]=i; list_names[i]=this.innerHTML; }) // start of functions fbutton=function (){ var ol=[]; var os=from_sel.getElementsByTagName('option'); for (var key=0;key'+list_names[list_options[key]]+'').get(0)); o_lc.appendChild($('').get(0)); } } } bbutton=function (){ var ol=[]; var os=to_sel.getElementsByTagName('option'); for (var key=os.length-1;key>=0;key--) { if (os[key].selected) { ol.push(os[key]); to_sel.removeChild(os[key]); } } idx={}; var os=to_sel.getElementsByTagName('option'); for (var key=0;key'+list_names[list_options[key]]+'').get(0)); } else { o_lc.appendChild($('').get(0)); } } } // end of functions fb.click(fbutton); bb.click(bbutton); $(from_sel).dblclick(fbutton); $(to_sel).dblclick(bbutton); fbutton(); }); }; $.fn.gs_multiselect.defaults = { }; })(jQuery);