-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.multiselect.js
More file actions
143 lines (129 loc) · 3.92 KB
/
jquery.multiselect.js
File metadata and controls
143 lines (129 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
(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=this.offsetWidth;
var rh=this.offsetHeight;
var t=document.createElement('table');
var to_sel=this.parentNode.replaceChild(t,this);
var from_sel=$('<select multiple="multiple"></select>').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=$('<input type="button" value="+">').get(0);
//var tl_filter=$('<input type="text">').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=$('<input type="button" value="»">');
var bb=$('<input type="button" value="«">');
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<os.length;key++) {
if (os[key].selected) {
ol.push(os[key]);
idx[os[key].value]=list_options[os[key].value];
}
}
for (var key=0;key<ol.length;key++) {
var n=from_sel.removeChild(ol[key]);
}
to_sel.innerHTML='';
$('input',o_lc).remove();
for (key in list_options) {
var add=false;
for (i in idx) {
if (list_options[key]==idx[i]) {
add=true;
break;
}
}
if (add) {
to_sel.appendChild($('<option value="'+key+'">'+list_names[list_options[key]]+'</option>').get(0));
o_lc.appendChild($('<input type="hidden" name="'+sel_name+'" value="'+key+'">').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<os.length;key++) {
idx[os[key].value]=list_options[os[key].value];
}
from_sel.innerHTML='';
$('input',o_lc).remove();
for (key in list_options) {
var add=true;
for (i in idx) {
if (list_options[key]==idx[i]) {
add=false;
break;
}
}
if (add) {
from_sel.appendChild($('<option value="'+key+'">'+list_names[list_options[key]]+'</option>').get(0));
} else {
o_lc.appendChild($('<input type="hidden" name="'+sel_name+'" value="'+key+'">').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);