|
1 | 1 | /* jshint forin:true, noarg:true, noempty:true, eqeqeq:true, boss:true, undef:true, curly:true, browser:true, jquery:true */
|
2 | 2 | /*
|
3 |
| - * jQuery MultiSelect UI Widget Filtering Plugin 3.0.0 |
| 3 | + * jQuery MultiSelect UI Widget Filtering Plugin 2.0.0 |
4 | 4 | * Copyright (c) 2012 Eric Hynds
|
5 | 5 | *
|
6 | 6 | * http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
|
7 | 7 | *
|
8 | 8 | * Depends:
|
9 |
| - * - jQuery 1.7+ |
10 | 9 | * - jQuery UI MultiSelect widget
|
11 | 10 | *
|
12 | 11 | * Dual licensed under the MIT and GPL licenses:
|
|
49 | 48 |
|
50 | 49 | _create: function() {
|
51 | 50 | var opts = this.options;
|
52 |
| - var $elem = this.element; |
| 51 | + var $element = this.element; |
53 | 52 |
|
54 | 53 | // get the multiselect instance
|
55 |
| - this.instance = $elem.multiselect('instance'); |
| 54 | + this.instance = $element.multiselect('instance'); |
56 | 55 |
|
57 | 56 | // store header; add filter class so the close/check all/uncheck all links can be positioned correctly
|
58 | 57 | this.$header = this.instance.$menu.find('.ui-multiselect-header').addClass('ui-multiselect-hasfilter');
|
59 | 58 |
|
60 |
| - // wrapper $elem |
61 |
| - this.$input = $("<input/>").attr({ |
| 59 | + // wrapper $element |
| 60 | + this.$input = $(document.createElement('input')) |
| 61 | + .attr({ |
62 | 62 | placeholder: opts.placeholder,
|
63 | 63 | type: "search"
|
64 |
| - }).css({ |
65 |
| - width: (/\d/.test(opts.width) ? opts.width + 'px' : null) |
66 |
| - }).on({ |
| 64 | + }) |
| 65 | + .css({ width: (/\d/.test(opts.width) ? opts.width + 'px' : null) }) |
| 66 | + .on({ |
67 | 67 | keydown: function(e) {
|
68 | 68 | // prevent the enter key from submitting the form / closing the widget
|
69 |
| - if(e.which === 13) { |
| 69 | + if(e.which === 13) |
70 | 70 | e.preventDefault();
|
71 |
| - } else if(e.which === 27) { |
72 |
| - $elem.multiselect('close'); |
| 71 | + else if(e.which === 27) { |
| 72 | + $element.multiselect('close'); |
73 | 73 | e.preventDefault();
|
74 |
| - } else if(e.which === 9 && e.shiftKey) { |
75 |
| - $elem.multiselect('close'); |
| 74 | + } |
| 75 | + else if(e.which === 9 && e.shiftKey) { |
| 76 | + $element.multiselect('close'); |
76 | 77 | e.preventDefault();
|
77 |
| - } else if(e.altKey) { |
| 78 | + } |
| 79 | + else if(e.altKey) { |
78 | 80 | switch(e.which) {
|
79 | 81 | case 82:
|
80 | 82 | e.preventDefault();
|
81 | 83 | $(this).val('').trigger('input', '');
|
82 | 84 | break;
|
83 | 85 | case 65:
|
84 |
| - $elem.multiselect('checkAll'); |
| 86 | + $element.multiselect('checkAll'); |
85 | 87 | break;
|
86 | 88 | case 85:
|
87 |
| - $elem.multiselect('uncheckAll'); |
| 89 | + $element.multiselect('uncheckAll'); |
88 | 90 | break;
|
89 | 91 | case 76:
|
90 |
| - $elem.multiselect('instance').$labels.first().trigger("mouseenter"); |
| 92 | + $element.multiselect('instance').$labels.first().trigger("mouseenter"); |
91 | 93 | break;
|
92 | 94 | }
|
93 | 95 | }
|
|
96 | 98 | search: $.proxy(this._handler, this)
|
97 | 99 | });
|
98 | 100 | // automatically reset the widget on close?
|
99 |
| - if(this.options.autoReset) { |
100 |
| - $elem.on('multiselectclose', $.proxy(this._reset, this)); |
101 |
| - } |
| 101 | + if (this.options.autoReset) |
| 102 | + $element.on('multiselectclose', $.proxy(this._reset, this)); |
| 103 | + |
102 | 104 | // rebuild cache when multiselect is updated
|
103 |
| - $elem.on('multiselectrefresh', $.proxy(function() { |
| 105 | + $element.on('multiselectrefresh', $.proxy(function() { |
104 | 106 | this.updateCache();
|
105 | 107 | this._handler();
|
106 | 108 | }, this));
|
107 |
| - this.$wrapper = $("<div/>").addClass("ui-multiselect-filter").text(opts.label).append(this.$input).prependTo(this.$header); |
| 109 | + this.$wrapper = $(document.createElement('div')) |
| 110 | + .addClass(' ui-multiselect-filter') |
| 111 | + .text(opts.label) |
| 112 | + .append(this.$input) |
| 113 | + .prependTo(this.$header); |
108 | 114 |
|
109 | 115 | // reference to the actual inputs
|
110 | 116 | this.$inputs = this.instance.$menu.find('input[type="checkbox"], input[type="radio"]');
|
|
116 | 122 | // only the currently filtered $elements are checked
|
117 | 123 | this.instance._toggleChecked = function(flag, group) {
|
118 | 124 | var $inputs = (group && group.length) ? group : this.$labels.find('input');
|
119 |
| - var _self = this; |
| 125 | + var self = this; |
| 126 | + var $element = this.element; |
120 | 127 |
|
121 | 128 | // do not include hidden elems if the menu isn't open.
|
122 |
| - var selector = _self._isOpen ? ':disabled, :hidden' : ':disabled'; |
| 129 | + var selector = self._isOpen ? ':disabled, :hidden' : ':disabled'; |
123 | 130 |
|
124 | 131 | $inputs = $inputs
|
125 | 132 | .not(selector)
|
|
135 | 142 | });
|
136 | 143 |
|
137 | 144 | // select option tags
|
138 |
| - this.element.find('option').filter(function() { |
| 145 | + $element.find('option').filter(function() { |
139 | 146 | if(!this.disabled && values[this.value]) {
|
140 |
| - _self._toggleState('selected', flag).call(this); |
| 147 | + self._toggleState('selected', flag).call(this); |
141 | 148 | }
|
142 | 149 | });
|
143 | 150 |
|
144 | 151 | // trigger the change event on the select
|
145 |
| - if($inputs.length) { |
146 |
| - this.element.trigger('change'); |
147 |
| - } |
| 152 | + if($inputs.length) |
| 153 | + $element.trigger('change'); |
| 154 | + |
148 | 155 | };
|
149 | 156 | },
|
150 | 157 |
|
|
153 | 160 | var term = $.trim(this.$input[0].value.toLowerCase()),
|
154 | 161 |
|
155 | 162 | // speed up lookups
|
156 |
| - rows = this.rows, $inputs = this.$inputs, $cache = this.$cache; |
| 163 | + $rows = this.$rows, $inputs = this.$inputs, $cache = this.$cache; |
157 | 164 | var $groups = this.instance.$menu.find(".ui-multiselect-optgroup");
|
158 | 165 | $groups.show();
|
159 | 166 | if(!term) {
|
160 |
| - rows.show(); |
| 167 | + $rows.show(); |
161 | 168 | } else {
|
162 |
| - rows.hide(); |
| 169 | + $rows.hide(); |
163 | 170 |
|
164 | 171 | var regex = new RegExp(term.replace(rEscape, "\\$&"), 'gi');
|
165 | 172 |
|
166 | 173 | this._trigger("filter", e, $.map($cache, function(v, i) {
|
167 | 174 | if(v.search(regex) !== -1) {
|
168 |
| - rows.eq(i).show(); |
| 175 | + $rows.eq(i).show(); |
169 | 176 | return $inputs.get(i);
|
170 | 177 | }
|
171 | 178 |
|
|
176 | 183 | // show/hide optgroups
|
177 | 184 | $groups.each(function() {
|
178 | 185 | var $this = $(this);
|
179 |
| - if(!$this.children("li:visible").length) { |
| 186 | + if (!$this.children("li:visible").length) |
180 | 187 | $this.hide();
|
181 |
| - } |
182 | 188 | });
|
183 | 189 | this.instance._setMenuHeight();
|
184 | 190 | },
|
|
189 | 195 |
|
190 | 196 | updateCache: function() {
|
191 | 197 | // each list item
|
192 |
| - this.rows = this.instance.$labels.parent(); |
| 198 | + this.$rows = this.instance.$labels.parent(); |
193 | 199 |
|
194 | 200 | // cache
|
195 | 201 | this.$cache = this.element.children().map(function() {
|
196 |
| - var $elem = $(this); |
| 202 | + var $element = $(this); |
197 | 203 |
|
198 | 204 | // account for optgroups
|
199 | 205 | if(this.tagName.toLowerCase() === "optgroup") {
|
200 |
| - $elem = $elem.children(); |
| 206 | + $element = $element.children(); |
201 | 207 | }
|
202 | 208 |
|
203 |
| - return $elem.map(function() { |
| 209 | + return $element.map(function() { |
204 | 210 | return this.innerHTML.toLowerCase();
|
205 | 211 | }).get();
|
206 | 212 | }).get();
|
|
0 commit comments