multi-select-rails 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Multiselect
|
1
|
+
# Multiselect for Rails [![Gem Version](https://badge.fury.io/rb/multi-select-rails.png)](http://badge.fury.io/rb/multi-select-rails)
|
2
2
|
|
3
3
|
[multi-select](https://github.com/lou/multi-select) is a tiny jQuery plugin to customize selects with the multiple attribute.
|
4
4
|
|
data/Rakefile
CHANGED
@@ -3,9 +3,9 @@ task :update do
|
|
3
3
|
system("rm -rf multi-select-src")
|
4
4
|
|
5
5
|
system("git clone https://github.com/lou/multi-select.git multi-select-src")
|
6
|
-
system("cp multi-select-src/img/switch.png
|
7
|
-
system("cp multi-select-src/css/multi-select.css
|
8
|
-
system("cp multi-select-src/js/jquery.multi-select.js
|
6
|
+
system("cp multi-select-src/img/switch.png app/assets/images/switch.png")
|
7
|
+
system("cp multi-select-src/css/multi-select.css app/assets/stylesheets/multi-select.scss")
|
8
|
+
system("cp multi-select-src/js/jquery.multi-select.js app/assets/javascripts/multi-select.js")
|
9
9
|
|
10
10
|
fixes
|
11
11
|
|
@@ -13,7 +13,7 @@ task :update do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def fixes
|
16
|
-
replace_string_in_file("
|
16
|
+
replace_string_in_file("app/assets/stylesheets/multi-select.scss", "url('../img/switch.png')", "image-url('switch.png')")
|
17
17
|
end
|
18
18
|
|
19
19
|
def replace_string_in_file(file, find, replace)
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* MultiSelect v0.9.
|
2
|
+
* MultiSelect v0.9.6
|
3
3
|
* Copyright (c) 2012 Louis Cuny
|
4
4
|
*
|
5
5
|
* This program is free software. It comes without any warranty, to
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
!function ($) {
|
13
13
|
|
14
|
-
"use strict";
|
14
|
+
"use strict";
|
15
15
|
|
16
16
|
|
17
17
|
/* MULTISELECT CLASS DEFINITION
|
@@ -20,13 +20,18 @@
|
|
20
20
|
var MultiSelect = function (element, options) {
|
21
21
|
this.options = options;
|
22
22
|
this.$element = $(element);
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
this.$
|
27
|
-
this.$
|
23
|
+
|
24
|
+
var id = this.$element.attr('id');
|
25
|
+
|
26
|
+
this.$container = $('<div/>', { 'id': "ms-"+id, 'class': "ms-container" });
|
27
|
+
this.$selectableContainer = $('<div/>', { 'class': 'ms-selectable' });
|
28
|
+
this.$selectionContainer = $('<div/>', { 'class': 'ms-selection' });
|
29
|
+
this.$selectableUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
|
30
|
+
this.$selectionUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
|
28
31
|
this.scrollTo = 0;
|
29
|
-
|
32
|
+
this.sanitizeRegexp = new RegExp("\\W+", 'gi');
|
33
|
+
this.elemsSelector = 'li:visible:not(.ms-optgroup-label,.ms-optgroup-container)';
|
34
|
+
};
|
30
35
|
|
31
36
|
MultiSelect.prototype = {
|
32
37
|
constructor: MultiSelect,
|
@@ -35,16 +40,13 @@
|
|
35
40
|
var that = this,
|
36
41
|
ms = this.$element;
|
37
42
|
|
38
|
-
if (ms.next('.ms-container').length
|
43
|
+
if (ms.next('.ms-container').length === 0){
|
39
44
|
ms.css({ position: 'absolute', left: '-9999px' });
|
40
45
|
ms.attr('id', ms.attr('id') ? ms.attr('id') : 'ms-'+Math.ceil(Math.random()*1000));
|
41
46
|
|
42
|
-
|
43
|
-
|
44
47
|
var optgroupLabel = null,
|
45
48
|
optgroupId = null,
|
46
49
|
optgroupCpt = 0,
|
47
|
-
scroll = 0,
|
48
50
|
optgroupContainerTemplate = '<li class="ms-optgroup-container"></li>',
|
49
51
|
optgroupUlTemplate = '<ul class="ms-optgroup"></ul>',
|
50
52
|
optgroupLiTemplate = '<li class="ms-optgroup-label"><span></span></li>';
|
@@ -62,12 +64,12 @@
|
|
62
64
|
|
63
65
|
if (that.options.selectableOptgroup){
|
64
66
|
optgroupSelectableLi.on('click', function(){
|
65
|
-
var values = optgroup.children(':not(:selected)').map(function(){ return $(this).val() }).get();
|
67
|
+
var values = optgroup.children(':not(:selected)').map(function(){ return $(this).val(); }).get();
|
66
68
|
that.select(values);
|
67
69
|
});
|
68
70
|
|
69
71
|
optgroupSelectionLi.on('click', function(){
|
70
|
-
var values = optgroup.children(':selected').map(function(){ return $(this).val() }).get();
|
72
|
+
var values = optgroup.children(':selected').map(function(){ return $(this).val(); }).get();
|
71
73
|
that.deselect(values);
|
72
74
|
});
|
73
75
|
}
|
@@ -105,7 +107,7 @@
|
|
105
107
|
selectedLi = selectableLi.clone();
|
106
108
|
|
107
109
|
var value = $(this).val(),
|
108
|
-
msId = that.sanitize(value);
|
110
|
+
msId = that.sanitize(value, that.sanitizeRegexp);
|
109
111
|
|
110
112
|
selectableLi
|
111
113
|
.data('ms-value', value)
|
@@ -140,171 +142,202 @@
|
|
140
142
|
}
|
141
143
|
});
|
142
144
|
|
143
|
-
if (that.options.selectableHeader)
|
145
|
+
if (that.options.selectableHeader){
|
144
146
|
that.$selectableContainer.append(that.options.selectableHeader);
|
147
|
+
}
|
145
148
|
that.$selectableContainer.append(that.$selectableUl);
|
146
|
-
if (that.options.selectableFooter)
|
149
|
+
if (that.options.selectableFooter){
|
147
150
|
that.$selectableContainer.append(that.options.selectableFooter);
|
151
|
+
}
|
148
152
|
|
149
|
-
if (that.options.selectionHeader)
|
153
|
+
if (that.options.selectionHeader){
|
150
154
|
that.$selectionContainer.append(that.options.selectionHeader);
|
155
|
+
}
|
151
156
|
that.$selectionContainer.append(that.$selectionUl);
|
152
|
-
if (that.options.selectionFooter)
|
157
|
+
if (that.options.selectionFooter){
|
153
158
|
that.$selectionContainer.append(that.options.selectionFooter);
|
159
|
+
}
|
154
160
|
|
155
161
|
that.$container.append(that.$selectableContainer);
|
156
162
|
that.$container.append(that.$selectionContainer);
|
157
163
|
ms.after(that.$container);
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
|
165
|
+
that.activeMouse(that.$selectableUl);
|
166
|
+
that.activeKeyboard(that.$selectableUl);
|
167
|
+
|
168
|
+
var action = that.options.dblClick ? 'dblclick' : 'click';
|
169
|
+
|
170
|
+
that.$selectableUl.on(action, '.ms-elem-selectable', function(){
|
171
|
+
that.select($(this).data('ms-value'));
|
172
|
+
});
|
173
|
+
that.$selectionUl.on(action, '.ms-elem-selection', function(){
|
174
|
+
that.deselect($(this).data('ms-value'));
|
163
175
|
});
|
164
176
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
that.$
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
177
|
+
that.activeMouse(that.$selectionUl);
|
178
|
+
that.activeKeyboard(that.$selectionUl);
|
179
|
+
|
180
|
+
ms.on('focus', function(){
|
181
|
+
that.$selectableUl.focus();
|
182
|
+
})
|
183
|
+
}
|
184
|
+
|
185
|
+
var selectedValues = ms.find('option:selected').map(function(){ return $(this).val(); }).get();
|
186
|
+
that.select(selectedValues, 'init');
|
187
|
+
|
188
|
+
if (typeof that.options.afterInit === 'function') {
|
189
|
+
that.options.afterInit.call(this, this.$container);
|
190
|
+
}
|
191
|
+
},
|
192
|
+
|
193
|
+
'activeKeyboard' : function($list){
|
194
|
+
var that = this;
|
195
|
+
|
196
|
+
$list.on('focus', function(){
|
197
|
+
$(this).addClass('ms-focus');
|
198
|
+
})
|
199
|
+
.on('blur', function(){
|
200
|
+
$(this).removeClass('ms-focus');
|
201
|
+
})
|
202
|
+
.on('keydown', function(e){
|
203
|
+
switch (e.which) {
|
204
|
+
case 40:
|
205
|
+
case 38:
|
206
|
+
e.preventDefault();
|
207
|
+
e.stopPropagation();
|
208
|
+
that.moveHighlight($(this), (e.which === 38) ? -1 : 1);
|
209
|
+
return;
|
210
|
+
case 32:
|
211
|
+
e.preventDefault();
|
212
|
+
e.stopPropagation();
|
213
|
+
that.selectHighlighted($list);
|
214
|
+
return;
|
215
|
+
case 37:
|
216
|
+
case 39:
|
217
|
+
e.preventDefault();
|
218
|
+
e.stopPropagation();
|
219
|
+
that.switchList($list);
|
220
|
+
return;
|
179
221
|
}
|
222
|
+
});
|
223
|
+
},
|
180
224
|
|
225
|
+
'moveHighlight': function($list, direction){
|
226
|
+
var $elems = $list.find(this.elemsSelector),
|
227
|
+
$currElem = $elems.filter('.ms-hover'),
|
228
|
+
$nextElem = null,
|
229
|
+
elemHeight = $elems.first().outerHeight(),
|
230
|
+
containerHeight = $list.height(),
|
231
|
+
containerSelector = '#'+this.$container.prop('id');
|
181
232
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
}).on('mouseleave', function(){
|
186
|
-
$('li', that.$selectionUl).removeClass('ms-hover');
|
187
|
-
});
|
233
|
+
// Deactive mouseenter event when move is active
|
234
|
+
// It fixes a bug when mouse is over the list
|
235
|
+
$elems.off('mouseenter');
|
188
236
|
|
189
|
-
|
190
|
-
|
191
|
-
that.$selectionUl.focusout();
|
192
|
-
}).on('focusout', function(){
|
193
|
-
$(this).removeClass('ms-focus');
|
194
|
-
$('li', that.$container).removeClass('ms-hover');
|
195
|
-
});
|
237
|
+
$elems.removeClass('ms-hover');
|
238
|
+
if (direction === 1){ // DOWN
|
196
239
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
$(this).removeClass('ms-focus');
|
201
|
-
$('li', that.$container).removeClass('ms-hover');
|
202
|
-
});
|
240
|
+
$nextElem = $currElem.nextAll(this.elemsSelector).first();
|
241
|
+
if ($nextElem.length === 0){
|
242
|
+
var $optgroupUl = $currElem.parent();
|
203
243
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
}).on('focusout', function(){
|
208
|
-
that.$selectableUl.removeClass('ms-focus');
|
209
|
-
that.$selectionUl.removeClass('ms-focus');
|
210
|
-
});
|
244
|
+
if ($optgroupUl.hasClass('ms-optgroup')){
|
245
|
+
var $optgroupLi = $optgroupUl.parent(),
|
246
|
+
$nextOptgroupLi = $optgroupLi.next(':visible');
|
211
247
|
|
212
|
-
|
213
|
-
|
214
|
-
lis = ul.find('li:visible:not(.ms-optgroup-label, .ms-optgroup-container)'),
|
215
|
-
lisNumber = lis.length,
|
216
|
-
liFocused = ul.find('li.ms-hover'),
|
217
|
-
liFocusedIndex = liFocused.length > 0 ? lis.index(liFocused) : -1,
|
218
|
-
ulHeight = ul.innerHeight(),
|
219
|
-
liHeight = lis.first().outerHeight(true),
|
220
|
-
numberOfLisDisplayed = Math.floor(ulHeight / liHeight);
|
221
|
-
|
222
|
-
if (e.keyCode == 32){ // space
|
223
|
-
if (liFocused.length >0){
|
224
|
-
var method = keyContainer == 'ms-selectable' ? 'select' : 'deselect';
|
225
|
-
if (keyContainer == 'ms-selectable'){
|
226
|
-
that.select(liFocused.data('ms-value'));
|
227
|
-
} else {
|
228
|
-
that.deselect(liFocused.data('ms-value'));
|
229
|
-
}
|
230
|
-
lis.removeClass('ms-hover');
|
231
|
-
that.scrollTo = 0;
|
232
|
-
ul.scrollTop(that.scrollTo);
|
233
|
-
}
|
234
|
-
} else if (e.keyCode == 40){ // Down
|
235
|
-
if (lis.length > 0){
|
236
|
-
var nextLiIndex = liFocusedIndex+1,
|
237
|
-
nextLi = (lisNumber != nextLiIndex) ? lis.eq(nextLiIndex) : lis.first(),
|
238
|
-
ulPosition = ul.position().top,
|
239
|
-
nextLiPosition = nextLi.position().top;
|
240
|
-
|
241
|
-
lis.removeClass('ms-hover');
|
242
|
-
nextLi.addClass('ms-hover');
|
243
|
-
|
244
|
-
if (lisNumber == nextLiIndex){
|
245
|
-
that.scrollTo = 0;
|
246
|
-
} else if (nextLiPosition >= (ulPosition + (numberOfLisDisplayed * liHeight))){
|
247
|
-
that.scrollTo += liHeight;
|
248
|
-
}
|
249
|
-
ul.scrollTop(that.scrollTo);
|
250
|
-
}
|
251
|
-
} else if (e.keyCode == 38){ // Up
|
252
|
-
if (lis.length > 0){
|
253
|
-
var prevLiIndex = Math.max(liFocusedIndex-1, -1),
|
254
|
-
prevLi = lis.eq(prevLiIndex),
|
255
|
-
ulPosition = ul.position().top,
|
256
|
-
prevLiPosition = prevLi.position().top;
|
257
|
-
|
258
|
-
lis.removeClass('ms-hover');
|
259
|
-
prevLi.addClass('ms-hover');
|
260
|
-
if (prevLiPosition <= ulPosition){
|
261
|
-
that.scrollTo -= liHeight;
|
262
|
-
} else if (prevLiIndex < 0){
|
263
|
-
that.scrollTo = (lisNumber - numberOfLisDisplayed) * liHeight;
|
264
|
-
}
|
265
|
-
ul.scrollTop(that.scrollTo);
|
266
|
-
}
|
267
|
-
} else if (e.keyCode == 37 || e.keyCode == 39){
|
268
|
-
if (that.$selectableUl.hasClass('ms-focus')){
|
269
|
-
that.$selectableUl.focusout();
|
270
|
-
that.$selectionUl.focusin();
|
248
|
+
if ($nextOptgroupLi.length > 0){
|
249
|
+
$nextElem = $nextOptgroupLi.find(this.elemsSelector).first();
|
271
250
|
} else {
|
272
|
-
|
273
|
-
that.$selectionUl.focusout();
|
251
|
+
$nextElem = $elems.first();
|
274
252
|
}
|
253
|
+
} else {
|
254
|
+
$nextElem = $elems.first();
|
275
255
|
}
|
276
256
|
}
|
257
|
+
} else if (direction === -1){ // UP
|
258
|
+
|
259
|
+
$nextElem = $currElem.prevAll(this.elemsSelector).first();
|
260
|
+
if ($nextElem.length === 0){
|
261
|
+
var $optgroupUl = $currElem.parent();
|
277
262
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
263
|
+
if ($optgroupUl.hasClass('ms-optgroup')){
|
264
|
+
var $optgroupLi = $optgroupUl.parent(),
|
265
|
+
$prevOptgroupLi = $optgroupLi.prev(':visible');
|
266
|
+
|
267
|
+
if ($prevOptgroupLi.length > 0){
|
268
|
+
$nextElem = $prevOptgroupLi.find(this.elemsSelector).last();
|
269
|
+
} else {
|
270
|
+
$nextElem = $elems.last();
|
271
|
+
}
|
272
|
+
} else {
|
273
|
+
$nextElem = $elems.last();
|
282
274
|
}
|
283
|
-
}
|
275
|
+
}
|
284
276
|
}
|
277
|
+
if ($nextElem.length > 0){
|
278
|
+
$nextElem.addClass('ms-hover');
|
279
|
+
var scrollTo = $list.scrollTop() + $nextElem.position().top -
|
280
|
+
containerHeight / 2 + elemHeight / 2;
|
285
281
|
|
286
|
-
|
287
|
-
|
282
|
+
$list.scrollTop(scrollTo);
|
283
|
+
}
|
284
|
+
},
|
288
285
|
|
289
|
-
|
290
|
-
|
286
|
+
'selectHighlighted' : function($list){
|
287
|
+
var $elems = $list.find(this.elemsSelector),
|
288
|
+
$highlightedElem = $elems.filter('.ms-hover').first();
|
289
|
+
|
290
|
+
if ($highlightedElem.length > 0){
|
291
|
+
if ($list.parent().hasClass('ms-selectable')){
|
292
|
+
this.select($highlightedElem.data('ms-value'));
|
293
|
+
} else {
|
294
|
+
this.deselect($highlightedElem.data('ms-value'));
|
295
|
+
}
|
296
|
+
$elems.removeClass('ms-hover');
|
297
|
+
}
|
298
|
+
},
|
299
|
+
|
300
|
+
'switchList' : function($list){
|
301
|
+
$list.blur();
|
302
|
+
if ($list.parent().hasClass('ms-selectable')){
|
303
|
+
this.$selectionUl.focus();
|
304
|
+
} else {
|
305
|
+
this.$selectableUl.focus();
|
291
306
|
}
|
292
307
|
},
|
293
308
|
|
309
|
+
'activeMouse' : function($list){
|
310
|
+
var that = this;
|
311
|
+
|
312
|
+
$list.on('mousemove', function(){
|
313
|
+
var elems = $list.find(that.elemsSelector);
|
314
|
+
|
315
|
+
elems.on('mouseenter', function(){
|
316
|
+
elems.removeClass('ms-hover');
|
317
|
+
$(this).addClass('ms-hover');
|
318
|
+
});
|
319
|
+
});
|
320
|
+
},
|
321
|
+
|
294
322
|
'refresh' : function() {
|
323
|
+
this.destroy();
|
324
|
+
this.$element.multiSelect(this.options);
|
325
|
+
},
|
326
|
+
|
327
|
+
'destroy' : function(){
|
295
328
|
$("#ms-"+this.$element.attr("id")).remove();
|
296
|
-
this.
|
329
|
+
this.$element.removeData('multiselect');
|
297
330
|
},
|
298
331
|
|
299
332
|
'select' : function(value, method){
|
300
|
-
if (typeof value
|
301
|
-
|
333
|
+
if (typeof value === 'string'){ value = [value]; }
|
334
|
+
|
302
335
|
var that = this,
|
303
336
|
ms = this.$element,
|
304
|
-
msIds = $.map(value, function(val
|
337
|
+
msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }),
|
305
338
|
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'),
|
306
339
|
selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection'),
|
307
|
-
options = ms.find('option').filter(function(
|
340
|
+
options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); });
|
308
341
|
|
309
342
|
if (selectables.length > 0){
|
310
343
|
selectables.addClass('ms-selected').hide();
|
@@ -315,7 +348,7 @@
|
|
315
348
|
if (selectableOptgroups.length > 0){
|
316
349
|
selectableOptgroups.each(function(){
|
317
350
|
var selectablesLi = $(this).find('.ms-elem-selectable');
|
318
|
-
if (selectablesLi.length
|
351
|
+
if (selectablesLi.length === selectablesLi.filter('.ms-selected').length){
|
319
352
|
$(this).find('.ms-optgroup-label').hide();
|
320
353
|
}
|
321
354
|
});
|
@@ -328,11 +361,9 @@
|
|
328
361
|
}
|
329
362
|
});
|
330
363
|
}
|
331
|
-
if (method
|
332
|
-
that.$selectionUl.focusout();
|
333
|
-
that.$selectableUl.focusin();
|
364
|
+
if (method !== 'init'){
|
334
365
|
ms.trigger('change');
|
335
|
-
if (typeof that.options.afterSelect
|
366
|
+
if (typeof that.options.afterSelect === 'function') {
|
336
367
|
that.options.afterSelect.call(this, value);
|
337
368
|
}
|
338
369
|
}
|
@@ -340,14 +371,14 @@
|
|
340
371
|
},
|
341
372
|
|
342
373
|
'deselect' : function(value){
|
343
|
-
if (typeof value
|
344
|
-
|
374
|
+
if (typeof value === 'string'){ value = [value]; }
|
375
|
+
|
345
376
|
var that = this,
|
346
377
|
ms = this.$element,
|
347
|
-
msIds = $.map(value, function(val
|
378
|
+
msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }),
|
348
379
|
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'),
|
349
380
|
selections = this.$selectionUl.find('#' + msIds.join('-selection, #')+'-selection').filter('.ms-selected'),
|
350
|
-
options = ms.find('option').filter(function(
|
381
|
+
options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); });
|
351
382
|
|
352
383
|
if (selections.length > 0){
|
353
384
|
selectables.removeClass('ms-selected').show();
|
@@ -366,15 +397,13 @@
|
|
366
397
|
var selectionOptgroups = that.$selectionUl.children('.ms-optgroup-container');
|
367
398
|
selectionOptgroups.each(function(){
|
368
399
|
var selectionsLi = $(this).find('.ms-elem-selection');
|
369
|
-
if (selectionsLi.filter('.ms-selected').length
|
400
|
+
if (selectionsLi.filter('.ms-selected').length === 0){
|
370
401
|
$(this).find('.ms-optgroup-label').hide();
|
371
402
|
}
|
372
403
|
});
|
373
404
|
}
|
374
|
-
this.$selectableUl.focusout();
|
375
|
-
this.$selectionUl.focusin();
|
376
405
|
ms.trigger('change');
|
377
|
-
if (typeof that.options.afterDeselect
|
406
|
+
if (typeof that.options.afterDeselect === 'function') {
|
378
407
|
that.options.afterDeselect.call(this, value);
|
379
408
|
}
|
380
409
|
}
|
@@ -389,10 +418,9 @@
|
|
389
418
|
this.$selectionUl.find('.ms-optgroup-label').show();
|
390
419
|
this.$selectableUl.find('.ms-optgroup-label').hide();
|
391
420
|
this.$selectionUl.find('.ms-elem-selection').addClass('ms-selected').show();
|
392
|
-
this.$selectionUl.
|
393
|
-
this.$selectableUl.focusout();
|
421
|
+
this.$selectionUl.focus();
|
394
422
|
ms.trigger('change');
|
395
|
-
if (typeof this.options.afterSelect
|
423
|
+
if (typeof this.options.afterSelect === 'function') {
|
396
424
|
var selectedValues = $.grep(ms.val(), function(item){
|
397
425
|
return $.inArray(item, values) < 0;
|
398
426
|
});
|
@@ -409,10 +437,9 @@
|
|
409
437
|
this.$selectionUl.find('.ms-optgroup-label').hide();
|
410
438
|
this.$selectableUl.find('.ms-optgroup-label').show();
|
411
439
|
this.$selectionUl.find('.ms-elem-selection').removeClass('ms-selected').hide();
|
412
|
-
this.$selectableUl.
|
413
|
-
this.$selectionUl.focusout();
|
440
|
+
this.$selectableUl.focus();
|
414
441
|
ms.trigger('change');
|
415
|
-
if (typeof this.options.afterDeselect
|
442
|
+
if (typeof this.options.afterDeselect === 'function') {
|
416
443
|
this.options.afterDeselect.call(this, values);
|
417
444
|
}
|
418
445
|
},
|
@@ -426,10 +453,10 @@
|
|
426
453
|
);
|
427
454
|
},
|
428
455
|
|
429
|
-
sanitize: function(value){
|
430
|
-
return(value.replace(
|
456
|
+
sanitize: function(value, reg){
|
457
|
+
return(value.replace(reg, '_'));
|
431
458
|
}
|
432
|
-
}
|
459
|
+
};
|
433
460
|
|
434
461
|
/* MULTISELECT PLUGIN DEFINITION
|
435
462
|
* ======================= */
|
@@ -441,24 +468,24 @@
|
|
441
468
|
return this.each(function () {
|
442
469
|
var $this = $(this),
|
443
470
|
data = $this.data('multiselect'),
|
444
|
-
options = $.extend({}, $.fn.multiSelect.defaults, $this.data(), typeof option
|
471
|
+
options = $.extend({}, $.fn.multiSelect.defaults, $this.data(), typeof option === 'object' && option);
|
445
472
|
|
446
|
-
if (!data) $this.data('multiselect', (data = new MultiSelect(this, options)))
|
473
|
+
if (!data){ $this.data('multiselect', (data = new MultiSelect(this, options))); }
|
447
474
|
|
448
|
-
if (typeof option
|
449
|
-
data[option](args[1])
|
475
|
+
if (typeof option === 'string'){
|
476
|
+
data[option](args[1]);
|
450
477
|
} else {
|
451
478
|
data.init();
|
452
479
|
}
|
453
|
-
})
|
454
|
-
}
|
480
|
+
});
|
481
|
+
};
|
455
482
|
|
456
483
|
$.fn.multiSelect.defaults = {
|
457
484
|
selectableOptgroup: false,
|
458
485
|
disabledClass : 'disabled',
|
459
486
|
dblClick : false
|
460
|
-
}
|
487
|
+
};
|
461
488
|
|
462
|
-
$.fn.multiSelect.Constructor = MultiSelect
|
489
|
+
$.fn.multiSelect.Constructor = MultiSelect;
|
463
490
|
|
464
491
|
}(window.jQuery);
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi-select-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -70,15 +70,15 @@ files:
|
|
70
70
|
- Gemfile
|
71
71
|
- README.md
|
72
72
|
- Rakefile
|
73
|
+
- app/assets/images/switch.png
|
74
|
+
- app/assets/javascripts/multi-select.js
|
75
|
+
- app/assets/stylesheets/multi-select.scss
|
73
76
|
- lib/multi-select-rails.rb
|
74
77
|
- lib/multi-select-rails/engine.rb
|
75
78
|
- lib/multi-select-rails/railtie.rb
|
76
79
|
- lib/multi-select-rails/version.rb
|
77
80
|
- multi-select-rails.gemspec
|
78
81
|
- multi-select.sublime-project
|
79
|
-
- vendor/assets/images/switch.png
|
80
|
-
- vendor/assets/javascripts/multi-select.js
|
81
|
-
- vendor/assets/stylesheets/multi-select.scss
|
82
82
|
homepage: https://github.com/klenis/multi-select-rails
|
83
83
|
licenses: []
|
84
84
|
post_install_message:
|
@@ -91,21 +91,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
segments:
|
95
|
-
- 0
|
96
|
-
hash: -981162216703867007
|
97
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
95
|
none: false
|
99
96
|
requirements:
|
100
97
|
- - ! '>='
|
101
98
|
- !ruby/object:Gem::Version
|
102
99
|
version: '0'
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
hash: -981162216703867007
|
106
100
|
requirements: []
|
107
101
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.23
|
109
103
|
signing_key:
|
110
104
|
specification_version: 3
|
111
105
|
summary: Multiselect jQuery plugin for Rails asset pipeline
|