multi-select-rails 0.9.6 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/javascripts/multi-select.js +92 -116
- data/lib/multi-select-rails/version.rb +1 -1
- metadata +13 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce1746de30de157c063b380380a603c7752c899a
|
4
|
+
data.tar.gz: c4d68ad0201876282644fff2de93e0418f0a85cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd3f383319e607ff296a582e4fab90e416161754c0e0a0c90765477db0d04fbdcd66841e5cab0f9ac2149adcec2dddb5f6e94be6b5c28a12d39586aa60adbb37
|
7
|
+
data.tar.gz: b6a9a3dc4ee0a4deef114aa29f5e8fbeb11e42411bcda6ac0d50ac24ec9f56ff5b987a0455167349a63c21f630eed075a11be00965f3037f2616499d98449f80
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* MultiSelect v0.9.
|
2
|
+
* MultiSelect v0.9.8
|
3
3
|
* Copyright (c) 2012 Louis Cuny
|
4
4
|
*
|
5
5
|
* This program is free software. It comes without any warranty, to
|
@@ -21,9 +21,7 @@
|
|
21
21
|
this.options = options;
|
22
22
|
this.$element = $(element);
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
this.$container = $('<div/>', { 'id': "ms-"+id, 'class': "ms-container" });
|
24
|
+
this.$container = $('<div/>', { 'class': "ms-container" });
|
27
25
|
this.$selectableContainer = $('<div/>', { 'class': 'ms-selectable' });
|
28
26
|
this.$selectionContainer = $('<div/>', { 'class': 'ms-selection' });
|
29
27
|
this.$selectableUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
|
@@ -42,106 +40,15 @@
|
|
42
40
|
|
43
41
|
if (ms.next('.ms-container').length === 0){
|
44
42
|
ms.css({ position: 'absolute', left: '-9999px' });
|
45
|
-
ms.attr('id', ms.attr('id') ? ms.attr('id') :
|
46
|
-
|
47
|
-
var optgroupLabel = null,
|
48
|
-
optgroupId = null,
|
49
|
-
optgroupCpt = 0,
|
50
|
-
optgroupContainerTemplate = '<li class="ms-optgroup-container"></li>',
|
51
|
-
optgroupUlTemplate = '<ul class="ms-optgroup"></ul>',
|
52
|
-
optgroupLiTemplate = '<li class="ms-optgroup-label"><span></span></li>';
|
53
|
-
|
54
|
-
ms.find('optgroup, option').each(function(){
|
55
|
-
if ($(this).is('optgroup')){
|
56
|
-
optgroupLabel = '<span>'+$(this).attr('label')+'</span>';
|
57
|
-
optgroupId = 'ms-'+ms.attr('id')+'-optgroup-'+optgroupCpt;
|
58
|
-
|
59
|
-
var optgroup = $(this),
|
60
|
-
optgroupSelectable = $(optgroupContainerTemplate),
|
61
|
-
optgroupSelection = $(optgroupContainerTemplate),
|
62
|
-
optgroupSelectionLi = $(optgroupLiTemplate),
|
63
|
-
optgroupSelectableLi = $(optgroupLiTemplate);
|
64
|
-
|
65
|
-
if (that.options.selectableOptgroup){
|
66
|
-
optgroupSelectableLi.on('click', function(){
|
67
|
-
var values = optgroup.children(':not(:selected)').map(function(){ return $(this).val(); }).get();
|
68
|
-
that.select(values);
|
69
|
-
});
|
70
|
-
|
71
|
-
optgroupSelectionLi.on('click', function(){
|
72
|
-
var values = optgroup.children(':selected').map(function(){ return $(this).val(); }).get();
|
73
|
-
that.deselect(values);
|
74
|
-
});
|
75
|
-
}
|
76
|
-
|
77
|
-
optgroupSelectableLi.html(optgroupLabel);
|
78
|
-
|
79
|
-
optgroupSelectable.attr('id', optgroupId+'-selectable')
|
80
|
-
.append($(optgroupUlTemplate)
|
81
|
-
.append(optgroupSelectableLi));
|
82
|
-
|
83
|
-
that.$selectableUl.append(optgroupSelectable);
|
43
|
+
ms.attr('id', ms.attr('id') ? ms.attr('id') : Math.ceil(Math.random()*1000)+'multiselect');
|
44
|
+
this.$container.attr('id', 'ms-'+ms.attr('id'));
|
84
45
|
|
85
|
-
|
86
|
-
|
87
|
-
optgroupSelection.attr('id', optgroupId+'-selection')
|
88
|
-
.append($(optgroupUlTemplate)
|
89
|
-
.append(optgroupSelectionLi));
|
90
|
-
|
91
|
-
that.$selectionUl.append(optgroupSelection);
|
92
|
-
|
93
|
-
optgroupCpt++;
|
94
|
-
|
95
|
-
} else {
|
96
|
-
|
97
|
-
var attributes = "";
|
98
|
-
|
99
|
-
for (var cpt = 0; cpt < this.attributes.length; cpt++){
|
100
|
-
var attr = this.attributes[cpt];
|
101
|
-
|
102
|
-
if(that.isDomNode(attr.name)){
|
103
|
-
attributes += attr.name+'="'+attr.value+'" ';
|
104
|
-
}
|
105
|
-
}
|
106
|
-
var selectableLi = $('<li '+attributes+'><span>'+$(this).text()+'</span></li>'),
|
107
|
-
selectedLi = selectableLi.clone();
|
108
|
-
|
109
|
-
var value = $(this).val(),
|
110
|
-
msId = that.sanitize(value, that.sanitizeRegexp);
|
111
|
-
|
112
|
-
selectableLi
|
113
|
-
.data('ms-value', value)
|
114
|
-
.addClass('ms-elem-selectable')
|
115
|
-
.attr('id', msId+'-selectable');
|
116
|
-
|
117
|
-
selectedLi
|
118
|
-
.data('ms-value', value)
|
119
|
-
.addClass('ms-elem-selection')
|
120
|
-
.attr('id', msId+'-selection')
|
121
|
-
.hide();
|
122
|
-
|
123
|
-
that.$selectionUl.find('.ms-optgroup-label').hide();
|
124
|
-
|
125
|
-
if ($(this).prop('disabled') || ms.prop('disabled')){
|
126
|
-
if (this.selected) {
|
127
|
-
selectedLi.prop('disabled', true);
|
128
|
-
selectedLi.addClass(that.options.disabledClass);
|
129
|
-
} else {
|
130
|
-
selectableLi.prop('disabled', true);
|
131
|
-
selectableLi.addClass(that.options.disabledClass);
|
132
|
-
}
|
133
|
-
}
|
134
|
-
|
135
|
-
if (optgroupId){
|
136
|
-
that.$selectableUl.children('#'+optgroupId+'-selectable').find('ul').first().append(selectableLi);
|
137
|
-
that.$selectionUl.children('#'+optgroupId+'-selection').find('ul').first().append(selectedLi);
|
138
|
-
} else {
|
139
|
-
that.$selectableUl.append(selectableLi);
|
140
|
-
that.$selectionUl.append(selectedLi);
|
141
|
-
}
|
142
|
-
}
|
46
|
+
ms.find('option').each(function(){
|
47
|
+
that.generateLisFromOption(this);
|
143
48
|
});
|
144
49
|
|
50
|
+
this.$selectionUl.find('.ms-optgroup-label').hide();
|
51
|
+
|
145
52
|
if (that.options.selectableHeader){
|
146
53
|
that.$selectableContainer.append(that.options.selectableHeader);
|
147
54
|
}
|
@@ -190,6 +97,79 @@
|
|
190
97
|
}
|
191
98
|
},
|
192
99
|
|
100
|
+
'generateLisFromOption' : function(option){
|
101
|
+
var that = this,
|
102
|
+
ms = that.$element,
|
103
|
+
attributes = "",
|
104
|
+
$option = $(option);
|
105
|
+
|
106
|
+
for (var cpt = 0; cpt < option.attributes.length; cpt++){
|
107
|
+
var attr = option.attributes[cpt];
|
108
|
+
|
109
|
+
if(attr.name !== 'value'){
|
110
|
+
attributes += attr.name+'="'+attr.value+'" ';
|
111
|
+
}
|
112
|
+
}
|
113
|
+
var selectableLi = $('<li '+attributes+'><span>'+$option.text()+'</span></li>'),
|
114
|
+
selectedLi = selectableLi.clone(),
|
115
|
+
value = $option.val(),
|
116
|
+
elementId = that.sanitize(value, that.sanitizeRegexp);
|
117
|
+
|
118
|
+
selectableLi
|
119
|
+
.data('ms-value', value)
|
120
|
+
.addClass('ms-elem-selectable')
|
121
|
+
.attr('id', elementId+'-selectable');
|
122
|
+
|
123
|
+
selectedLi
|
124
|
+
.data('ms-value', value)
|
125
|
+
.addClass('ms-elem-selection')
|
126
|
+
.attr('id', elementId+'-selection')
|
127
|
+
.hide();
|
128
|
+
|
129
|
+
if ($option.prop('disabled') || ms.prop('disabled')){
|
130
|
+
selectedLi.addClass(that.options.disabledClass);
|
131
|
+
selectableLi.addClass(that.options.disabledClass);
|
132
|
+
}
|
133
|
+
|
134
|
+
var $optgroup = $option.parent('optgroup');
|
135
|
+
|
136
|
+
if ($optgroup.length > 0){
|
137
|
+
var optgroupLabel = $optgroup.attr('label'),
|
138
|
+
optgroupId = that.sanitize(optgroupLabel, that.sanitizeRegexp),
|
139
|
+
$selectableOptgroup = that.$selectableUl.find('#optgroup-selectable-'+optgroupId),
|
140
|
+
$selectionOptgroup = that.$selectionUl.find('#optgroup-selection-'+optgroupId);
|
141
|
+
|
142
|
+
if ($selectableOptgroup.length === 0){
|
143
|
+
var optgroupContainerTpl = '<li class="ms-optgroup-container"></li>',
|
144
|
+
optgroupTpl = '<ul class="ms-optgroup"><li class="ms-optgroup-label"><span>'+optgroupLabel+'</span></li></ul>';
|
145
|
+
|
146
|
+
$selectableOptgroup = $(optgroupContainerTpl);
|
147
|
+
$selectionOptgroup = $(optgroupContainerTpl);
|
148
|
+
$selectableOptgroup.attr('id', 'optgroup-selectable-'+optgroupId);
|
149
|
+
$selectionOptgroup.attr('id', 'optgroup-selection-'+optgroupId);
|
150
|
+
$selectableOptgroup.append($(optgroupTpl));
|
151
|
+
$selectionOptgroup.append($(optgroupTpl));
|
152
|
+
if (that.options.selectableOptgroup){
|
153
|
+
$selectableOptgroup.find('.ms-optgroup-label').on('click', function(){
|
154
|
+
var values = $optgroup.children(':not(:selected)').map(function(){ return $(this).val() }).get();
|
155
|
+
that.select(values);
|
156
|
+
});
|
157
|
+
$selectionOptgroup.find('.ms-optgroup-label').on('click', function(){
|
158
|
+
var values = $optgroup.children(':selected').map(function(){ return $(this).val() }).get();
|
159
|
+
that.deselect(values);
|
160
|
+
});
|
161
|
+
}
|
162
|
+
that.$selectableUl.append($selectableOptgroup);
|
163
|
+
that.$selectionUl.append($selectionOptgroup);
|
164
|
+
}
|
165
|
+
$selectableOptgroup.children().append(selectableLi);
|
166
|
+
$selectionOptgroup.children().append(selectedLi);
|
167
|
+
} else {
|
168
|
+
that.$selectableUl.append(selectableLi);
|
169
|
+
that.$selectionUl.append(selectedLi);
|
170
|
+
}
|
171
|
+
},
|
172
|
+
|
193
173
|
'activeKeyboard' : function($list){
|
194
174
|
var that = this;
|
195
175
|
|
@@ -336,8 +316,8 @@
|
|
336
316
|
ms = this.$element,
|
337
317
|
msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }),
|
338
318
|
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'),
|
339
|
-
selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection'),
|
340
|
-
options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); });
|
319
|
+
selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection').filter(':not(.'+that.options.disabledClass+')'),
|
320
|
+
options = ms.find('option:not(:disabled)').filter(function(){ return($.inArray(this.value, value) > -1); });
|
341
321
|
|
342
322
|
if (selectables.length > 0){
|
343
323
|
selectables.addClass('ms-selected').hide();
|
@@ -360,6 +340,10 @@
|
|
360
340
|
$(this).find('.ms-optgroup-label').show();
|
361
341
|
}
|
362
342
|
});
|
343
|
+
} else {
|
344
|
+
if (that.options.keepOrder){
|
345
|
+
selections.insertAfter(that.$selectionUl.find('.ms-selected').last());
|
346
|
+
}
|
363
347
|
}
|
364
348
|
if (method !== 'init'){
|
365
349
|
ms.trigger('change');
|
@@ -413,11 +397,11 @@
|
|
413
397
|
var ms = this.$element,
|
414
398
|
values = ms.val();
|
415
399
|
|
416
|
-
ms.find('option').prop('selected', true);
|
417
|
-
this.$selectableUl.find('.ms-elem-selectable').addClass('ms-selected').hide();
|
400
|
+
ms.find('option:not(":disabled")').prop('selected', true);
|
401
|
+
this.$selectableUl.find('.ms-elem-selectable').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').hide();
|
418
402
|
this.$selectionUl.find('.ms-optgroup-label').show();
|
419
403
|
this.$selectableUl.find('.ms-optgroup-label').hide();
|
420
|
-
this.$selectionUl.find('.ms-elem-selection').addClass('ms-selected').show();
|
404
|
+
this.$selectionUl.find('.ms-elem-selection').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').show();
|
421
405
|
this.$selectionUl.focus();
|
422
406
|
ms.trigger('change');
|
423
407
|
if (typeof this.options.afterSelect === 'function') {
|
@@ -444,15 +428,6 @@
|
|
444
428
|
}
|
445
429
|
},
|
446
430
|
|
447
|
-
isDomNode: function (attr){
|
448
|
-
return (
|
449
|
-
attr &&
|
450
|
-
typeof attr === "object" &&
|
451
|
-
typeof attr.nodeType === "number" &&
|
452
|
-
typeof attr.nodeName === "string"
|
453
|
-
);
|
454
|
-
},
|
455
|
-
|
456
431
|
sanitize: function(value, reg){
|
457
432
|
return(value.replace(reg, '_'));
|
458
433
|
}
|
@@ -483,7 +458,8 @@
|
|
483
458
|
$.fn.multiSelect.defaults = {
|
484
459
|
selectableOptgroup: false,
|
485
460
|
disabledClass : 'disabled',
|
486
|
-
dblClick : false
|
461
|
+
dblClick : false,
|
462
|
+
keepOrder: false
|
487
463
|
};
|
488
464
|
|
489
465
|
$.fn.multiSelect.Constructor = MultiSelect;
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi-select-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Per Andersson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: railties
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Multiselect jQuery plugin for Rails asset pipeline
|
@@ -81,26 +74,25 @@ files:
|
|
81
74
|
- multi-select.sublime-project
|
82
75
|
homepage: https://github.com/klenis/multi-select-rails
|
83
76
|
licenses: []
|
77
|
+
metadata: {}
|
84
78
|
post_install_message:
|
85
79
|
rdoc_options: []
|
86
80
|
require_paths:
|
87
81
|
- lib
|
88
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
83
|
requirements:
|
91
|
-
- -
|
84
|
+
- - '>='
|
92
85
|
- !ruby/object:Gem::Version
|
93
86
|
version: '0'
|
94
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
88
|
requirements:
|
97
|
-
- -
|
89
|
+
- - '>='
|
98
90
|
- !ruby/object:Gem::Version
|
99
91
|
version: '0'
|
100
92
|
requirements: []
|
101
93
|
rubyforge_project:
|
102
|
-
rubygems_version:
|
94
|
+
rubygems_version: 2.0.3
|
103
95
|
signing_key:
|
104
|
-
specification_version:
|
96
|
+
specification_version: 4
|
105
97
|
summary: Multiselect jQuery plugin for Rails asset pipeline
|
106
98
|
test_files: []
|