public
Description: MooTools based multiple select widget
Homepage: http://www.wollzelle.com/os/multiple-select-widget/
Clone URL: git://github.com/michael/multiple_select.git
multiple_select / multiple_select.js
100755 99 lines (77 sloc) 2.175 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
/*
Script:
multiple_select.js
 
License:
MIT-style license
Group: HTML Widgets
provides customizable multiple select widgets
 
Based on:
comboBoo.js by Bruno Torrinha, <http://www.torrinha.com>
 
Credits:
wollzelle GmbH, <http://www.wollzelle.com>
Michael Aufreiter
*/
 
 
 
/*
Class: MultipleSelect
collects functions for multiple select widgets
 
Note:
static class
*/
 
var MultipleSelect = new Class({
options: {
className: 'multiple_select'
},
 
  /*
Property: initialize
initializes a new multiple select widget
*/
  
initialize: function(el, options) {
this.setOptions(options);
this.oldSelect = $(el);
var pos = el.getCoordinates();
 
this.oldSelect.setStyle('display', 'none');
 
// selectList
this.selectList = new Element('ul', {
'class': this.options.className + '_list', 'id': el.name+'_choices'
}).setStyles({
width: pos.width +'px', height: pos.height+'px'
}).injectAfter(this.oldSelect);
 
this.build(el);
},
 
  /*
Property: build
builds the HTML that is needed for displaying the multiple select
widget instead of the normal select box
*/
 
build: function(el) {
for(i = 0; i < el.length; i++) {
var el2 = new Element('li', {'id': el.name+'_'+i}).setHTML(el.options[i].text);
      if (this.oldSelect.options[i].selected)
       el2.addClass('choice_selected');
this.addChoiceEvents(el2);
el2.injectInside(this.selectList);
};
},
 
  /*
Property: choiceSelect
selects or deselects the clicked list items
*/
 
choiceSelect: function(el) {
el.toggleClass('choice_selected');
var id = el.id.substring(el.id.lastIndexOf('_')+1).toInt();
this.oldSelect.options[id].selected ? this.oldSelect.options[id].selected = '' : this.oldSelect.options[id].selected = 'selected';
el.fireEvent('change');
},
 
  /*
Property: addChoiceEvents
registers the mouse events
*/
 
addChoiceEvents: function(el) {
return el.addEvents({
mouseover: function() { el.addClass('choice_hover'); },
mouseout: function() { el.removeClass('choice_hover'); },
mousedown: this.choiceSelect.bind(this, [el])
});
}
});
 
MultipleSelect.implement(new Events, new Options);