multi-select-rails 0.9.8.1 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd6a695b1c387f2fc70d3ba787aeb6303338e5b1
4
- data.tar.gz: 30652e630b096b3122242912462a7404f6eb5602
3
+ metadata.gz: 6a70e40728dbb139bdada2b45f84de2cedcd05e2
4
+ data.tar.gz: 8737300ca714c1ab8a68f1969723fb543e80fe9d
5
5
  SHA512:
6
- metadata.gz: 7e80700ec17c6b7fec9a0eabcbe83975f3c69838d3ac748d2680db942cabe37b0f3216e8c09f958489af3786646af34c0289c1e2e753c5738ca27160de64e341
7
- data.tar.gz: e77cedbce96dfd161864fb48d69f77a0c3b3343dca34a7594dfaf39dfb4b7590a60f6b9b6417f6b45665e6da41f4d0f2ae00db2a43c43d713a1045d1d686c7ce
6
+ metadata.gz: f33126f4ac398c7d2e74e2bc406d4d0660c7b4919924ca514f70ce8bb048457e2ce9d35cf85c682e1001df609a97010bd747d60ac9058594c119c7a7f35a5f94
7
+ data.tar.gz: 27d1f645f90ac3173c3426c2f10f4fc49994e1cde25a941be0349d33962e54aaa7e7b14d6c0de2f2b984a3dc9554de5e948b3d995f0ee256bfb421201a388f5d
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * MultiSelect v0.9.8
2
+ * MultiSelect v0.9.10
3
3
  * Copyright (c) 2012 Louis Cuny
4
4
  *
5
5
  * This program is free software. It comes without any warranty, to
@@ -20,15 +20,13 @@
20
20
  var MultiSelect = function (element, options) {
21
21
  this.options = options;
22
22
  this.$element = $(element);
23
-
24
23
  this.$container = $('<div/>', { 'class': "ms-container" });
25
24
  this.$selectableContainer = $('<div/>', { 'class': 'ms-selectable' });
26
25
  this.$selectionContainer = $('<div/>', { 'class': 'ms-selection' });
27
26
  this.$selectableUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
28
27
  this.$selectionUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
29
28
  this.scrollTo = 0;
30
- this.sanitizeRegexp = new RegExp("\\W+", 'gi');
31
- this.elemsSelector = 'li:visible:not(.ms-optgroup-label,.ms-optgroup-container)';
29
+ this.elemsSelector = 'li:visible:not(.ms-optgroup-label,.ms-optgroup-container,.'+options.disabledClass+')';
32
30
  };
33
31
 
34
32
  MultiSelect.prototype = {
@@ -42,7 +40,7 @@
42
40
  ms.css({ position: 'absolute', left: '-9999px' });
43
41
  ms.attr('id', ms.attr('id') ? ms.attr('id') : Math.ceil(Math.random()*1000)+'multiselect');
44
42
  this.$container.attr('id', 'ms-'+ms.attr('id'));
45
-
43
+ this.$container.addClass(that.options.cssClass);
46
44
  ms.find('option').each(function(){
47
45
  that.generateLisFromOption(this);
48
46
  });
@@ -97,7 +95,7 @@
97
95
  }
98
96
  },
99
97
 
100
- 'generateLisFromOption' : function(option){
98
+ 'generateLisFromOption' : function(option, index, $container){
101
99
  var that = this,
102
100
  ms = that.$element,
103
101
  attributes = "",
@@ -106,14 +104,14 @@
106
104
  for (var cpt = 0; cpt < option.attributes.length; cpt++){
107
105
  var attr = option.attributes[cpt];
108
106
 
109
- if(attr.name !== 'value'){
107
+ if(attr.name !== 'value' && attr.name !== 'disabled'){
110
108
  attributes += attr.name+'="'+attr.value+'" ';
111
109
  }
112
110
  }
113
- var selectableLi = $('<li '+attributes+'><span>'+$option.text()+'</span></li>'),
111
+ var selectableLi = $('<li '+attributes+'><span>'+that.escapeHTML($option.text())+'</span></li>'),
114
112
  selectedLi = selectableLi.clone(),
115
113
  value = $option.val(),
116
- elementId = that.sanitize(value, that.sanitizeRegexp);
114
+ elementId = that.sanitize(value);
117
115
 
118
116
  selectableLi
119
117
  .data('ms-value', value)
@@ -135,14 +133,14 @@
135
133
 
136
134
  if ($optgroup.length > 0){
137
135
  var optgroupLabel = $optgroup.attr('label'),
138
- optgroupId = that.sanitize(optgroupLabel, that.sanitizeRegexp),
136
+ optgroupId = that.sanitize(optgroupLabel),
139
137
  $selectableOptgroup = that.$selectableUl.find('#optgroup-selectable-'+optgroupId),
140
138
  $selectionOptgroup = that.$selectionUl.find('#optgroup-selection-'+optgroupId);
141
-
139
+
142
140
  if ($selectableOptgroup.length === 0){
143
141
  var optgroupContainerTpl = '<li class="ms-optgroup-container"></li>',
144
142
  optgroupTpl = '<ul class="ms-optgroup"><li class="ms-optgroup-label"><span>'+optgroupLabel+'</span></li></ul>';
145
-
143
+
146
144
  $selectableOptgroup = $(optgroupContainerTpl);
147
145
  $selectionOptgroup = $(optgroupContainerTpl);
148
146
  $selectableOptgroup.attr('id', 'optgroup-selectable-'+optgroupId);
@@ -162,14 +160,37 @@
162
160
  that.$selectableUl.append($selectableOptgroup);
163
161
  that.$selectionUl.append($selectionOptgroup);
164
162
  }
165
- $selectableOptgroup.children().append(selectableLi);
166
- $selectionOptgroup.children().append(selectedLi);
163
+ index = index == undefined ? $selectableOptgroup.children().length : index + 1;
164
+ selectableLi.insertAt(index, $selectableOptgroup.children());
165
+ selectedLi.insertAt(index, $selectionOptgroup.children());
167
166
  } else {
168
- that.$selectableUl.append(selectableLi);
169
- that.$selectionUl.append(selectedLi);
167
+ index = index == undefined ? that.$selectableUl.children().length : index;
168
+
169
+ selectableLi.insertAt(index, that.$selectableUl);
170
+ selectedLi.insertAt(index, that.$selectionUl);
170
171
  }
171
172
  },
172
173
 
174
+ 'addOption' : function(options){
175
+ var that = this;
176
+
177
+ if (options.value) options = [options];
178
+ $.each(options, function(index, option){
179
+ if (option.value && that.$element.find("option[value='"+option.value+"']").length === 0){
180
+ var $option = $('<option value="'+option.value+'">'+option.text+'</option>'),
181
+ index = parseInt((typeof option.index === 'undefined' ? that.$element.children().length : option.index)),
182
+ $container = option.nested == undefined ? that.$element : $("optgroup[label='"+option.nested+"']")
183
+
184
+ $option.insertAt(index, $container);
185
+ that.generateLisFromOption($option.get(0), index, option.nested);
186
+ }
187
+ })
188
+ },
189
+
190
+ 'escapeHTML' : function(text){
191
+ return $("<div>").text(text).html();
192
+ },
193
+
173
194
  'activeKeyboard' : function($list){
174
195
  var that = this;
175
196
 
@@ -187,17 +208,30 @@
187
208
  e.stopPropagation();
188
209
  that.moveHighlight($(this), (e.which === 38) ? -1 : 1);
189
210
  return;
190
- case 32:
191
- e.preventDefault();
192
- e.stopPropagation();
193
- that.selectHighlighted($list);
194
- return;
195
211
  case 37:
196
212
  case 39:
197
213
  e.preventDefault();
198
214
  e.stopPropagation();
199
215
  that.switchList($list);
200
216
  return;
217
+ case 9:
218
+ if(that.$element.is('[tabindex]')){
219
+ e.preventDefault();
220
+ var tabindex = parseInt(that.$element.attr('tabindex'), 10);
221
+ tabindex = (e.shiftKey) ? tabindex-1 : tabindex+1;
222
+ $('[tabindex="'+(tabindex)+'"]').focus();
223
+ return;
224
+ }else{
225
+ if(e.shiftKey){
226
+ that.$element.trigger('focus');
227
+ }
228
+ }
229
+ }
230
+ if($.inArray(e.which, that.options.keySelect) > -1){
231
+ e.preventDefault();
232
+ e.stopPropagation();
233
+ that.selectHighlighted($list);
234
+ return;
201
235
  }
202
236
  });
203
237
  },
@@ -288,9 +322,11 @@
288
322
 
289
323
  'activeMouse' : function($list){
290
324
  var that = this;
291
-
325
+ var lastMovedDom = false;
292
326
  $list.on('mousemove', function(){
293
- var elems = $list.find(that.elemsSelector);
327
+ if (lastMovedDom === this) return;
328
+ lastMovedDom = this;
329
+ var elems = $list.find(that.elemsSelector);
294
330
 
295
331
  elems.on('mouseenter', function(){
296
332
  elems.removeClass('ms-hover');
@@ -314,11 +350,16 @@
314
350
 
315
351
  var that = this,
316
352
  ms = this.$element,
317
- msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }),
353
+ msIds = $.map(value, function(val){ return(that.sanitize(val)); }),
318
354
  selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'),
319
355
  selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection').filter(':not(.'+that.options.disabledClass+')'),
320
356
  options = ms.find('option:not(:disabled)').filter(function(){ return($.inArray(this.value, value) > -1); });
321
357
 
358
+ if (method === 'init'){
359
+ selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'),
360
+ selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection');
361
+ }
362
+
322
363
  if (selectables.length > 0){
323
364
  selectables.addClass('ms-selected').hide();
324
365
  selections.addClass('ms-selected').show();
@@ -342,7 +383,10 @@
342
383
  });
343
384
  } else {
344
385
  if (that.options.keepOrder){
345
- selections.insertAfter(that.$selectionUl.find('.ms-selected').last());
386
+ var selectionLiLast = that.$selectionUl.find('.ms-selected');
387
+ if((selectionLiLast.length > 1) && (selectionLiLast.last().get(0) != selections.get(0))) {
388
+ selections.insertAfter(selectionLiLast.last());
389
+ }
346
390
  }
347
391
  }
348
392
  if (method !== 'init'){
@@ -359,9 +403,9 @@
359
403
 
360
404
  var that = this,
361
405
  ms = this.$element,
362
- msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }),
406
+ msIds = $.map(value, function(val){ return(that.sanitize(val)); }),
363
407
  selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'),
364
- selections = this.$selectionUl.find('#' + msIds.join('-selection, #')+'-selection').filter('.ms-selected'),
408
+ selections = this.$selectionUl.find('#' + msIds.join('-selection, #')+'-selection').filter('.ms-selected').filter(':not(.'+that.options.disabledClass+')'),
365
409
  options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); });
366
410
 
367
411
  if (selections.length > 0){
@@ -428,8 +472,16 @@
428
472
  }
429
473
  },
430
474
 
431
- sanitize: function(value, reg){
432
- return(value.replace(reg, '_'));
475
+ sanitize: function(value){
476
+ var hash = 0, i, char;
477
+ if (value.length == 0) return hash;
478
+ var ls = 0;
479
+ for (i = 0, ls = value.length; i < ls; i++) {
480
+ char = value.charCodeAt(i);
481
+ hash = ((hash<<5)-hash)+char;
482
+ hash |= 0; // Convert to 32bit integer
483
+ }
484
+ return hash;
433
485
  }
434
486
  };
435
487
 
@@ -456,12 +508,24 @@
456
508
  };
457
509
 
458
510
  $.fn.multiSelect.defaults = {
511
+ keySelect: [32],
459
512
  selectableOptgroup: false,
460
513
  disabledClass : 'disabled',
461
514
  dblClick : false,
462
- keepOrder: false
515
+ keepOrder: false,
516
+ cssClass: ''
463
517
  };
464
518
 
465
519
  $.fn.multiSelect.Constructor = MultiSelect;
466
520
 
467
- }(window.jQuery);
521
+ $.fn.insertAt = function(index, $parent) {
522
+ return this.each(function() {
523
+ if (index === 0) {
524
+ $parent.prepend(this);
525
+ } else {
526
+ $parent.children().eq(index - 1).after(this);
527
+ }
528
+ });
529
+ }
530
+
531
+ }(window.jQuery);
@@ -1,16 +1,27 @@
1
1
  .ms-container{
2
- background: transparent image-url('switch.png') no-repeat 170px 80px;
2
+ background: transparent image-url('switch.png') no-repeat 50% 50%;
3
+ width: 370px;
3
4
  }
4
5
 
5
6
  .ms-container:after{
6
- content: "."; display: block; height: 0; line-height: 0; font-size: 0; clear: both; min-height: 0; visibility: hidden;
7
+ content: ".";
8
+ display: block;
9
+ height: 0;
10
+ line-height: 0;
11
+ font-size: 0;
12
+ clear: both;
13
+ min-height: 0;
14
+ visibility: hidden;
7
15
  }
8
16
 
9
17
  .ms-container .ms-selectable, .ms-container .ms-selection{
10
-
11
18
  background: #fff;
12
19
  color: #555555;
13
20
  float: left;
21
+ width: 45%;
22
+ }
23
+ .ms-container .ms-selection{
24
+ float: right;
14
25
  }
15
26
 
16
27
  .ms-container .ms-list{
@@ -26,14 +37,10 @@
26
37
  -webkit-border-radius: 3px;
27
38
  -moz-border-radius: 3px;
28
39
  border-radius: 3px;
29
- }
30
-
31
-
32
- .ms-selected{
33
- display:none;
34
- }
35
- .ms-container .ms-selectable{
36
- margin-right: 40px;
40
+ position: relative;
41
+ height: 200px;
42
+ padding: 0;
43
+ overflow-y: auto;
37
44
  }
38
45
 
39
46
  .ms-container .ms-list.ms-focus{
@@ -55,13 +62,6 @@
55
62
  width: 100%;
56
63
  }
57
64
 
58
- .ms-container ul.ms-list{
59
- width: 160px;
60
- height: 200px;
61
- padding: 0;
62
- overflow-y: auto;
63
- }
64
-
65
65
  .ms-container .ms-optgroup-label{
66
66
  margin: 0;
67
67
  padding: 5px 0px 0px 5px;
@@ -90,4 +90,4 @@
90
90
  background-color: #eee;
91
91
  color: #aaa;
92
92
  cursor: text;
93
- }
93
+ }
@@ -1,5 +1,5 @@
1
1
  module MultiSelectRails
2
2
  module Rails
3
- VERSION = "0.9.8.1"
3
+ VERSION = "0.9.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi-select-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.1
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Per Andersson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
63
  - Gemfile
64
+ - LICENSE.txt
64
65
  - README.md
65
66
  - Rakefile
66
67
  - app/assets/images/switch.png