select2-rails 0.0.3 → 0.0.4
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.
- data/lib/select2-rails/version.rb +1 -1
- data/vendor/assets/javascripts/select2.js +45 -6
- metadata +10 -10
@@ -70,6 +70,10 @@
|
|
70
70
|
function indexOf(value, array) {
|
71
71
|
var i = 0, l = array.length, v;
|
72
72
|
|
73
|
+
if (typeof value == 'undefined') {
|
74
|
+
return -1;
|
75
|
+
}
|
76
|
+
|
73
77
|
if (value.constructor === String) {
|
74
78
|
for (; i < l; i = i + 1) if (value.localeCompare(array[i]) === 0) return i;
|
75
79
|
} else {
|
@@ -262,7 +266,7 @@
|
|
262
266
|
*/
|
263
267
|
function local(options) {
|
264
268
|
var data = options, // data elements
|
265
|
-
text = function (item) { return item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
|
269
|
+
text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
|
266
270
|
|
267
271
|
if (!$.isArray(data)) {
|
268
272
|
text = data.text;
|
@@ -352,7 +356,8 @@
|
|
352
356
|
this.id=opts.id;
|
353
357
|
|
354
358
|
// destroy if called on an existing component
|
355
|
-
if (opts.element.data("select2") !== undefined
|
359
|
+
if (opts.element.data("select2") !== undefined &&
|
360
|
+
opts.element.data("select2") !== null) {
|
356
361
|
this.destroy();
|
357
362
|
}
|
358
363
|
|
@@ -1122,6 +1127,7 @@
|
|
1122
1127
|
killEvent(e);
|
1123
1128
|
return;
|
1124
1129
|
case KEY.ENTER:
|
1130
|
+
case KEY.TAB:
|
1125
1131
|
this.selectHighlighted();
|
1126
1132
|
killEvent(e);
|
1127
1133
|
return;
|
@@ -1374,15 +1380,15 @@
|
|
1374
1380
|
},
|
1375
1381
|
|
1376
1382
|
setVal: function (val) {
|
1377
|
-
var unique
|
1383
|
+
var unique;
|
1378
1384
|
if (this.select) {
|
1379
1385
|
this.select.val(val);
|
1380
1386
|
} else {
|
1387
|
+
unique = [];
|
1381
1388
|
// filter out duplicates
|
1382
1389
|
$(val).each(function () {
|
1383
1390
|
if (indexOf(this, unique) < 0) unique.push(this);
|
1384
1391
|
});
|
1385
|
-
|
1386
1392
|
this.opts.element.val(unique.length === 0 ? "" : unique.join(","));
|
1387
1393
|
}
|
1388
1394
|
},
|
@@ -1414,6 +1420,35 @@
|
|
1414
1420
|
}
|
1415
1421
|
|
1416
1422
|
this.clearSearch();
|
1423
|
+
},
|
1424
|
+
onSortStart: function() {
|
1425
|
+
if (this.select) {
|
1426
|
+
throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.");
|
1427
|
+
}
|
1428
|
+
|
1429
|
+
// collapse search field into 0 width so its container can be collapsed as well
|
1430
|
+
this.search.width(0);
|
1431
|
+
// hide the container
|
1432
|
+
this.searchContainer.hide();
|
1433
|
+
},
|
1434
|
+
onSortEnd:function() {
|
1435
|
+
|
1436
|
+
var val=[], self=this;
|
1437
|
+
|
1438
|
+
// show search and move it to the end of the list
|
1439
|
+
this.searchContainer.show();
|
1440
|
+
// make sure the search container is the last item in the list
|
1441
|
+
this.searchContainer.appendTo(this.searchContainer.parent());
|
1442
|
+
// since we collapsed the width in dragStarteed, we resize it here
|
1443
|
+
this.resizeSearch();
|
1444
|
+
|
1445
|
+
// update selection
|
1446
|
+
|
1447
|
+
this.selection.find(".select2-search-choice").each(function() {
|
1448
|
+
val.push(self.opts.id($(this).data("select2-data")));
|
1449
|
+
});
|
1450
|
+
this.setVal(val);
|
1451
|
+
this.triggerChange();
|
1417
1452
|
}
|
1418
1453
|
});
|
1419
1454
|
|
@@ -1422,7 +1457,7 @@
|
|
1422
1457
|
var args = Array.prototype.slice.call(arguments, 0),
|
1423
1458
|
opts,
|
1424
1459
|
select2,
|
1425
|
-
value, multiple, allowedMethods = ["val", "destroy", "open", "close", "focus", "isFocused"];
|
1460
|
+
value, multiple, allowedMethods = ["val", "destroy", "open", "close", "focus", "isFocused", "container", "onSortStart", "onSortEnd"];
|
1426
1461
|
|
1427
1462
|
this.each(function () {
|
1428
1463
|
if (args.length === 0 || typeof(args[0]) === "object") {
|
@@ -1447,7 +1482,11 @@
|
|
1447
1482
|
value = undefined;
|
1448
1483
|
select2 = $(this).data("select2");
|
1449
1484
|
if (select2 === undefined) return;
|
1450
|
-
|
1485
|
+
if (args[0] === "container") {
|
1486
|
+
value=select2.container;
|
1487
|
+
} else {
|
1488
|
+
value = select2[args[0]].apply(select2, args.slice(1));
|
1489
|
+
}
|
1451
1490
|
if (value !== undefined) {return false;}
|
1452
1491
|
} else {
|
1453
1492
|
throw "Invalid arguments to select2 plugin: " + args;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: select2-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &84270160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.14'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *84270160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &84269910 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *84269910
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &84269680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *84269680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sass
|
49
|
-
requirement: &
|
49
|
+
requirement: &84269450 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '3.1'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *84269450
|
58
58
|
description: Select2 is a jQuery based replacement for select boxes. It supports searching,
|
59
59
|
remote data sets, and infinite scrolling of results. This gem integrates Select2
|
60
60
|
with Rails asset pipeline for easy of use.
|