select2-rails 0.0.6 → 0.0.7
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.
@@ -29,7 +29,7 @@
|
|
29
29
|
return this;
|
30
30
|
}
|
31
31
|
});
|
32
|
-
}
|
32
|
+
}
|
33
33
|
})(jQuery);
|
34
34
|
|
35
35
|
(function ($, undefined) {
|
@@ -79,6 +79,9 @@
|
|
79
79
|
case KEY.ALT:
|
80
80
|
return true;
|
81
81
|
}
|
82
|
+
|
83
|
+
if (k.metaKey) return true;
|
84
|
+
|
82
85
|
return false;
|
83
86
|
},
|
84
87
|
isFunctionKey: function (k) {
|
@@ -163,7 +166,7 @@
|
|
163
166
|
*
|
164
167
|
* filters out mouse events that occur when mouse is stationary but
|
165
168
|
* the elements under the pointer are scrolled.
|
166
|
-
*/
|
169
|
+
*/
|
167
170
|
function installFilteredMouseMove(element) {
|
168
171
|
element.bind("mousemove", function (e) {
|
169
172
|
var lastpos = $(document).data("select2-lastpos");
|
@@ -201,7 +204,7 @@
|
|
201
204
|
event.stopPropagation();
|
202
205
|
}
|
203
206
|
|
204
|
-
function measureTextWidth(e) {
|
207
|
+
function measureTextWidth(e) {
|
205
208
|
if (!sizer){
|
206
209
|
var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
|
207
210
|
sizer = $("<div></div>").css({
|
@@ -216,10 +219,10 @@
|
|
216
219
|
letterSpacing: style.letterSpacing,
|
217
220
|
textTransform: style.textTransform,
|
218
221
|
whiteSpace: "nowrap"
|
219
|
-
});
|
222
|
+
});
|
220
223
|
$("body").append(sizer);
|
221
224
|
}
|
222
|
-
sizer.text(e.val());
|
225
|
+
sizer.text(e.val());
|
223
226
|
return sizer.width();
|
224
227
|
}
|
225
228
|
|
@@ -268,11 +271,11 @@
|
|
268
271
|
data = options.data, // ajax data function
|
269
272
|
transport = options.transport || $.ajax,
|
270
273
|
type = options.type || 'GET'; // set type of request (GET or POST)
|
271
|
-
|
274
|
+
|
272
275
|
data = data.call(this, query.term, query.page, query.context);
|
273
276
|
|
274
277
|
if( null !== handler) { handler.abort(); }
|
275
|
-
|
278
|
+
|
276
279
|
handler = transport.call(null, {
|
277
280
|
url: options.url,
|
278
281
|
dataType: options.dataType,
|
@@ -473,11 +476,11 @@
|
|
473
476
|
|
474
477
|
installKeyUpChangeEvent(search);
|
475
478
|
search.bind("keyup-change", this.bind(this.updateResults));
|
476
|
-
search.bind("focus", function () { search.addClass("select2-focused");});
|
479
|
+
search.bind("focus", function () { search.addClass("select2-focused"); if (search.val() === " ") search.val(""); });
|
477
480
|
search.bind("blur", function () { search.removeClass("select2-focused");});
|
478
481
|
|
479
482
|
this.dropdown.delegate(resultsSelector, "click", this.bind(function (e) {
|
480
|
-
if ($(e.target).closest(".select2-result:not(.select2-disabled)").length > 0) {
|
483
|
+
if ($(e.target).closest(".select2-result-selectable:not(.select2-disabled)").length > 0) {
|
481
484
|
this.highlightUnderEvent(e);
|
482
485
|
this.selectHighlighted(e);
|
483
486
|
} else {
|
@@ -507,14 +510,14 @@
|
|
507
510
|
select2.opts.element
|
508
511
|
.removeData("select2")
|
509
512
|
.unbind(".select2")
|
510
|
-
.show();
|
513
|
+
.show();
|
511
514
|
}
|
512
515
|
},
|
513
516
|
|
514
517
|
// abstract
|
515
518
|
prepareOpts: function (opts) {
|
516
519
|
var element, select, idKey;
|
517
|
-
|
520
|
+
|
518
521
|
element = opts.element;
|
519
522
|
|
520
523
|
if (element.get(0).tagName.toLowerCase() === "select") {
|
@@ -536,7 +539,7 @@
|
|
536
539
|
containerCssClass: "",
|
537
540
|
dropdownCssClass: "",
|
538
541
|
populateResults: function(container, results, query) {
|
539
|
-
var uidToData={}, populate, markup=[], uid, data, result, children, formatted;
|
542
|
+
var uidToData={}, populate, markup=[], uid, data, result, children, formatted, id=this.opts.id;
|
540
543
|
|
541
544
|
populate=function(results, depth) {
|
542
545
|
|
@@ -544,20 +547,19 @@
|
|
544
547
|
for (i = 0, l = results.length; i < l; i = i + 1) {
|
545
548
|
|
546
549
|
result=results[i];
|
547
|
-
selectable=(
|
550
|
+
selectable=id(result) !== undefined;
|
548
551
|
compound=("children" in result) && result.children.length > 0;
|
549
552
|
|
550
|
-
markup.push("<li class='select2-result-depth-"+depth);
|
551
|
-
|
553
|
+
markup.push("<li class='select2-result-depth-" + depth);
|
554
|
+
markup.push(" select2-result");
|
555
|
+
markup.push(selectable ? " select2-result-selectable" : " select2-result-unselectable");
|
552
556
|
if (compound) { markup.push(" select2-result-with-children"); }
|
553
557
|
|
554
558
|
markup.push("'");
|
555
559
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
uidToData[uid]=result;
|
560
|
-
}
|
560
|
+
uid=nextUid();
|
561
|
+
markup.push(" id='select2-result-"+uid+"'");
|
562
|
+
uidToData[uid]=result;
|
561
563
|
|
562
564
|
markup.push("><div class='select2-result-label'>");
|
563
565
|
formatted=opts.formatResult(result, query, markup);
|
@@ -579,12 +581,7 @@
|
|
579
581
|
|
580
582
|
populate(results, 0);
|
581
583
|
|
582
|
-
|
583
|
-
if (children.length===0) {
|
584
|
-
container.html(markup.join(""));
|
585
|
-
} else {
|
586
|
-
$(children[children.length-1]).append(markup.join(""));
|
587
|
-
}
|
584
|
+
container.append(markup.join(""));
|
588
585
|
|
589
586
|
for (uid in uidToData) {
|
590
587
|
$("#select2-result-"+uid, container).data("select2-data", uidToData[uid]);
|
@@ -623,10 +620,10 @@
|
|
623
620
|
var group;
|
624
621
|
if (element.is("option")) {
|
625
622
|
if (query.matcher(term, element.text())) {
|
626
|
-
collection.push({id:element.attr("value"), text:element.text()});
|
623
|
+
collection.push({id:element.attr("value"), text:element.text(), element: element.get()});
|
627
624
|
}
|
628
625
|
} else if (element.is("optgroup")) {
|
629
|
-
group={text:element.attr("label"), children:[]};
|
626
|
+
group={text:element.attr("label"), children:[], element: element.get()};
|
630
627
|
element.children().each2(function(i, elm) { process(elm, group.children); });
|
631
628
|
if (group.children.length>0) {
|
632
629
|
collection.push(group);
|
@@ -659,12 +656,13 @@
|
|
659
656
|
} else if ("tags" in opts) {
|
660
657
|
opts.query = tags(opts.tags);
|
661
658
|
opts.createSearchChoice = function (term) { return {id: term, text: term}; };
|
662
|
-
opts.initSelection = function (element) {
|
659
|
+
opts.initSelection = function (element, callback) {
|
663
660
|
var data = [];
|
664
661
|
$(splitVal(element.val(), ",")).each(function () {
|
665
662
|
data.push({id: this, text: this});
|
666
663
|
});
|
667
|
-
|
664
|
+
|
665
|
+
callback(data);
|
668
666
|
};
|
669
667
|
}
|
670
668
|
}
|
@@ -739,16 +737,36 @@
|
|
739
737
|
this.dropdown.css(css);
|
740
738
|
},
|
741
739
|
|
740
|
+
// abstract
|
741
|
+
shouldOpen: function() {
|
742
|
+
var event;
|
743
|
+
|
744
|
+
if (this.opened()) return false;
|
745
|
+
|
746
|
+
event = jQuery.Event("open");
|
747
|
+
this.opts.element.trigger(event);
|
748
|
+
return !event.isDefaultPrevented();
|
749
|
+
},
|
750
|
+
|
751
|
+
/**
|
752
|
+
* Opens the dropdown
|
753
|
+
*
|
754
|
+
* @return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
|
755
|
+
* the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
|
756
|
+
*/
|
742
757
|
// abstract
|
743
758
|
open: function () {
|
744
|
-
|
759
|
+
|
760
|
+
if (!this.shouldOpen()) return false;
|
761
|
+
|
762
|
+
if (this.search.val() === " ") { this.search.val(""); }
|
745
763
|
|
746
764
|
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
|
747
|
-
if(this.dropdown[0] !== this.body.children().last()[0]) {
|
765
|
+
if(this.dropdown[0] !== this.body.children().last()[0]) {
|
748
766
|
// ensure the dropdown is the last child of body, so the z-index is always respected correctly
|
749
767
|
this.dropdown.detach().appendTo(this.body);
|
750
768
|
}
|
751
|
-
|
769
|
+
|
752
770
|
this.dropdown.addClass("select2-drop-active");
|
753
771
|
|
754
772
|
this.positionDropdown();
|
@@ -757,6 +775,8 @@
|
|
757
775
|
this.dropdown.show();
|
758
776
|
this.ensureHighlightVisible();
|
759
777
|
this.focusSearch();
|
778
|
+
|
779
|
+
return true;
|
760
780
|
},
|
761
781
|
|
762
782
|
// abstract
|
@@ -777,12 +797,22 @@
|
|
777
797
|
// abstract
|
778
798
|
ensureHighlightVisible: function () {
|
779
799
|
var results = this.results, children, index, child, hb, rb, y, more;
|
780
|
-
|
800
|
+
|
781
801
|
index = this.highlight();
|
782
802
|
|
783
803
|
if (index < 0) return;
|
784
|
-
|
785
|
-
|
804
|
+
|
805
|
+
if (index == 0) {
|
806
|
+
|
807
|
+
// if the first element is highlighted scroll all the way to the top,
|
808
|
+
// that way any unselectable headers above it will also be scrolled
|
809
|
+
// into view
|
810
|
+
|
811
|
+
results.scrollTop(0);
|
812
|
+
return;
|
813
|
+
}
|
814
|
+
|
815
|
+
children = results.find(".select2-result-selectable");
|
786
816
|
|
787
817
|
child = $(children[index]);
|
788
818
|
|
@@ -810,12 +840,13 @@
|
|
810
840
|
|
811
841
|
// abstract
|
812
842
|
moveHighlight: function (delta) {
|
813
|
-
var choices = this.results.find(".select2-result"),
|
843
|
+
var choices = this.results.find(".select2-result-selectable"),
|
814
844
|
index = this.highlight();
|
815
845
|
|
816
846
|
while (index > -1 && index < choices.length) {
|
817
847
|
index += delta;
|
818
|
-
|
848
|
+
var choice = $(choices[index]);
|
849
|
+
if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled")) {
|
819
850
|
this.highlight(index);
|
820
851
|
break;
|
821
852
|
}
|
@@ -824,7 +855,7 @@
|
|
824
855
|
|
825
856
|
// abstract
|
826
857
|
highlight: function (index) {
|
827
|
-
var choices = this.results.find(".select2-result
|
858
|
+
var choices = this.results.find(".select2-result-selectable");
|
828
859
|
|
829
860
|
if (arguments.length === 0) {
|
830
861
|
return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
|
@@ -833,10 +864,6 @@
|
|
833
864
|
if (index >= choices.length) index = choices.length - 1;
|
834
865
|
if (index < 0) index = 0;
|
835
866
|
|
836
|
-
if ($(choices[index]).parent().is('.select2-result-unselectable')) {
|
837
|
-
return;
|
838
|
-
}
|
839
|
-
|
840
867
|
choices.removeClass("select2-highlighted");
|
841
868
|
|
842
869
|
$(choices[index]).addClass("select2-highlighted");
|
@@ -847,10 +874,13 @@
|
|
847
874
|
|
848
875
|
// abstract
|
849
876
|
highlightUnderEvent: function (event) {
|
850
|
-
var el = $(event.target).closest(".select2-result");
|
877
|
+
var el = $(event.target).closest(".select2-result-selectable");
|
851
878
|
if (el.length > 0 && !el.is(".select2-highlighted")) {
|
852
|
-
var choices = this.results.find('.select2-result');
|
879
|
+
var choices = this.results.find('.select2-result-selectable');
|
853
880
|
this.highlight(choices.index(el));
|
881
|
+
} else if (el.length == 0) {
|
882
|
+
// if we are over an unselectable item remove al highlights
|
883
|
+
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
|
854
884
|
}
|
855
885
|
},
|
856
886
|
|
@@ -877,12 +907,11 @@
|
|
877
907
|
matcher: this.opts.matcher,
|
878
908
|
callback: this.bind(function (data) {
|
879
909
|
|
880
|
-
self.opts.populateResults(results, data.results, {term: term, page: page, context:context});
|
910
|
+
self.opts.populateResults.call(this, results, data.results, {term: term, page: page, context:context});
|
881
911
|
|
882
912
|
if (data.more===true) {
|
883
|
-
more.detach();
|
884
|
-
|
885
|
-
more.removeClass("select2-active");
|
913
|
+
more.detach().appendTo(results.children(":last")).text(self.opts.formatLoadMore(page+1));
|
914
|
+
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
|
886
915
|
} else {
|
887
916
|
more.remove();
|
888
917
|
}
|
@@ -951,11 +980,12 @@
|
|
951
980
|
}
|
952
981
|
|
953
982
|
results.empty();
|
954
|
-
self.opts.populateResults(results, data.results, {term: search.val(), page: this.resultsPage, context:null});
|
983
|
+
self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null});
|
955
984
|
postRender();
|
956
985
|
|
957
986
|
if (data.more === true) {
|
958
987
|
results.children().filter(":last").append("<li class='select2-more-results'>" + opts.formatLoadMore(this.resultsPage) + "</li>");
|
988
|
+
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
|
959
989
|
}
|
960
990
|
|
961
991
|
this.postprocessResults(data, initial);
|
@@ -972,7 +1002,8 @@
|
|
972
1002
|
this.close();
|
973
1003
|
this.container.removeClass("select2-container-active");
|
974
1004
|
this.dropdown.removeClass("select2-drop-active");
|
975
|
-
|
1005
|
+
// synonymous to .is(':focus'), which is available in jquery >= 1.6
|
1006
|
+
if (this.search[0] === document.activeElement) { this.search.blur(); }
|
976
1007
|
this.clearSearch();
|
977
1008
|
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
|
978
1009
|
},
|
@@ -988,7 +1019,7 @@
|
|
988
1019
|
|
989
1020
|
// abstract
|
990
1021
|
selectHighlighted: function () {
|
991
|
-
var data = this.results.find(".select2-highlighted").not(".select2-disabled").closest('.select2-result
|
1022
|
+
var data = this.results.find(".select2-highlighted").not(".select2-disabled").closest('.select2-result-selectable').data("select2-data");
|
992
1023
|
if (data) {
|
993
1024
|
this.onSelect(data);
|
994
1025
|
}
|
@@ -996,7 +1027,10 @@
|
|
996
1027
|
|
997
1028
|
// abstract
|
998
1029
|
getPlaceholder: function () {
|
999
|
-
return this.opts.element.attr("placeholder") ||
|
1030
|
+
return this.opts.element.attr("placeholder") ||
|
1031
|
+
this.opts.element.attr("data-placeholder") || // jquery 1.4 compat
|
1032
|
+
this.opts.element.data("placeholder") ||
|
1033
|
+
this.opts.placeholder;
|
1000
1034
|
},
|
1001
1035
|
|
1002
1036
|
/**
|
@@ -1023,7 +1057,7 @@
|
|
1023
1057
|
return matches[1];
|
1024
1058
|
}
|
1025
1059
|
}
|
1026
|
-
return this.opts.element.width() + 'px';
|
1060
|
+
return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.width() + 'px');
|
1027
1061
|
}
|
1028
1062
|
});
|
1029
1063
|
|
@@ -1048,15 +1082,6 @@
|
|
1048
1082
|
"</div>"].join(""));
|
1049
1083
|
},
|
1050
1084
|
|
1051
|
-
// single
|
1052
|
-
open: function () {
|
1053
|
-
|
1054
|
-
if (this.opened()) return;
|
1055
|
-
|
1056
|
-
this.parent.open.apply(this, arguments);
|
1057
|
-
|
1058
|
-
},
|
1059
|
-
|
1060
1085
|
// single
|
1061
1086
|
close: function () {
|
1062
1087
|
if (!this.opened()) return;
|
@@ -1071,7 +1096,7 @@
|
|
1071
1096
|
|
1072
1097
|
// single
|
1073
1098
|
isFocused: function () {
|
1074
|
-
return this.selection.
|
1099
|
+
return this.selection[0] === document.activeElement;
|
1075
1100
|
},
|
1076
1101
|
|
1077
1102
|
// single
|
@@ -1148,7 +1173,7 @@
|
|
1148
1173
|
|
1149
1174
|
selection.delegate("abbr", "click", this.bind(function (e) {
|
1150
1175
|
if (!this.enabled) return;
|
1151
|
-
this.
|
1176
|
+
this.clear();
|
1152
1177
|
killEvent(e);
|
1153
1178
|
this.close();
|
1154
1179
|
this.triggerChange();
|
@@ -1166,6 +1191,13 @@
|
|
1166
1191
|
this.opts.element.bind("open", function() { focusser.hide(); });
|
1167
1192
|
},
|
1168
1193
|
|
1194
|
+
clear: function() {
|
1195
|
+
this.opts.element.val("");
|
1196
|
+
this.selection.find("span").empty();
|
1197
|
+
this.selection.removeData("select2-data");
|
1198
|
+
this.setPlaceholder();
|
1199
|
+
},
|
1200
|
+
|
1169
1201
|
/**
|
1170
1202
|
* Sets selection based on source element's value
|
1171
1203
|
*/
|
@@ -1174,15 +1206,18 @@
|
|
1174
1206
|
var selected;
|
1175
1207
|
if (this.opts.element.val() === "") {
|
1176
1208
|
this.updateSelection({id: "", text: ""});
|
1209
|
+
this.close();
|
1210
|
+
this.setPlaceholder();
|
1177
1211
|
} else {
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1212
|
+
var self = this;
|
1213
|
+
this.opts.initSelection.call(null, this.opts.element, function(selected){
|
1214
|
+
if (selected !== undefined && selected !== null) {
|
1215
|
+
self.updateSelection(selected);
|
1216
|
+
self.close();
|
1217
|
+
self.setPlaceholder();
|
1218
|
+
}
|
1219
|
+
});
|
1182
1220
|
}
|
1183
|
-
|
1184
|
-
this.close();
|
1185
|
-
this.setPlaceholder();
|
1186
1221
|
},
|
1187
1222
|
|
1188
1223
|
// single
|
@@ -1190,11 +1225,12 @@
|
|
1190
1225
|
var opts = this.parent.prepareOpts.apply(this, arguments);
|
1191
1226
|
|
1192
1227
|
if (opts.element.get(0).tagName.toLowerCase() === "select") {
|
1193
|
-
// install
|
1194
|
-
opts.initSelection = function (element) {
|
1228
|
+
// install the selection initializer
|
1229
|
+
opts.initSelection = function (element, callback) {
|
1195
1230
|
var selected = element.find(":selected");
|
1196
1231
|
// a single select box always has a value, no need to null check 'selected'
|
1197
|
-
|
1232
|
+
if ($.isFunction(callback))
|
1233
|
+
callback({id: selected.attr("value"), text: selected.text()});
|
1198
1234
|
};
|
1199
1235
|
}
|
1200
1236
|
|
@@ -1227,7 +1263,7 @@
|
|
1227
1263
|
|
1228
1264
|
// find the selected element in the result list
|
1229
1265
|
|
1230
|
-
this.results.find(".select2-result").each2(function (i, elm) {
|
1266
|
+
this.results.find(".select2-result-selectable").each2(function (i, elm) {
|
1231
1267
|
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
|
1232
1268
|
selected = i;
|
1233
1269
|
return false;
|
@@ -1266,6 +1302,9 @@
|
|
1266
1302
|
|
1267
1303
|
// single
|
1268
1304
|
updateSelection: function (data) {
|
1305
|
+
|
1306
|
+
this.selection.data("select2-data", data);
|
1307
|
+
|
1269
1308
|
this.selection
|
1270
1309
|
.find("span")
|
1271
1310
|
.html(this.opts.formatSelection(data));
|
@@ -1308,6 +1347,20 @@
|
|
1308
1347
|
// single
|
1309
1348
|
clearSearch: function () {
|
1310
1349
|
this.search.val("");
|
1350
|
+
},
|
1351
|
+
|
1352
|
+
// single
|
1353
|
+
data: function(value) {
|
1354
|
+
if (arguments.length === 0) {
|
1355
|
+
return this.selection.data("select2-data");
|
1356
|
+
} else {
|
1357
|
+
if (!value || value === "") {
|
1358
|
+
this.clear();
|
1359
|
+
} else {
|
1360
|
+
this.opts.element.val(!value ? "" : this.id(value));
|
1361
|
+
this.updateSelection(value);
|
1362
|
+
}
|
1363
|
+
}
|
1311
1364
|
}
|
1312
1365
|
});
|
1313
1366
|
|
@@ -1342,13 +1395,16 @@
|
|
1342
1395
|
// TODO validate placeholder is a string if specified
|
1343
1396
|
|
1344
1397
|
if (opts.element.get(0).tagName.toLowerCase() === "select") {
|
1345
|
-
// install
|
1346
|
-
opts.initSelection = function (element) {
|
1398
|
+
// install sthe selection initializer
|
1399
|
+
opts.initSelection = function (element,callback) {
|
1400
|
+
|
1347
1401
|
var data = [];
|
1348
1402
|
element.find(":selected").each2(function (i, elm) {
|
1349
1403
|
data.push({id: elm.attr("value"), text: elm.text()});
|
1350
1404
|
});
|
1351
|
-
|
1405
|
+
|
1406
|
+
if ($.isFunction(callback))
|
1407
|
+
callback(data);
|
1352
1408
|
};
|
1353
1409
|
}
|
1354
1410
|
|
@@ -1460,18 +1516,21 @@
|
|
1460
1516
|
var data;
|
1461
1517
|
if (this.opts.element.val() === "") {
|
1462
1518
|
this.updateSelection([]);
|
1519
|
+
this.close();
|
1520
|
+
// set the placeholder if necessary
|
1521
|
+
this.clearSearch();
|
1463
1522
|
}
|
1464
1523
|
if (this.select || this.opts.element.val() !== "") {
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1524
|
+
var self = this;
|
1525
|
+
this.opts.initSelection.call(null, this.opts.element, function(data){
|
1526
|
+
if (data !== undefined && data !== null) {
|
1527
|
+
self.updateSelection(data);
|
1528
|
+
self.close();
|
1529
|
+
// set the placeholder if necessary
|
1530
|
+
self.clearSearch();
|
1531
|
+
}
|
1532
|
+
});
|
1469
1533
|
}
|
1470
|
-
|
1471
|
-
this.close();
|
1472
|
-
|
1473
|
-
// set the placeholder if necessary
|
1474
|
-
this.clearSearch();
|
1475
1534
|
},
|
1476
1535
|
|
1477
1536
|
// multi
|
@@ -1483,7 +1542,9 @@
|
|
1483
1542
|
// stretch the search box to full width of the container so as much of the placeholder is visible as possible
|
1484
1543
|
this.search.width(this.getContainerWidth());
|
1485
1544
|
} else {
|
1486
|
-
this
|
1545
|
+
// we set this to " " instead of "" and later clear it on focus() because there is a firefox bug
|
1546
|
+
// that does not properly render the caret when the field starts out blank
|
1547
|
+
this.search.val(" ").width(10);
|
1487
1548
|
}
|
1488
1549
|
},
|
1489
1550
|
|
@@ -1496,11 +1557,11 @@
|
|
1496
1557
|
|
1497
1558
|
// multi
|
1498
1559
|
open: function () {
|
1499
|
-
if (this.
|
1500
|
-
this.parent.open.apply(this, arguments);
|
1560
|
+
if (this.parent.open.apply(this, arguments) === false) return false;
|
1501
1561
|
this.clearPlaceholder();
|
1502
1562
|
this.resizeSearch();
|
1503
1563
|
this.focusSearch();
|
1564
|
+
return true;
|
1504
1565
|
},
|
1505
1566
|
|
1506
1567
|
// multi
|
@@ -1630,7 +1691,7 @@
|
|
1630
1691
|
// multi
|
1631
1692
|
postprocessResults: function () {
|
1632
1693
|
var val = this.getVal(),
|
1633
|
-
choices = this.results.find(".select2-result"),
|
1694
|
+
choices = this.results.find(".select2-result-selectable"),
|
1634
1695
|
self = this;
|
1635
1696
|
|
1636
1697
|
choices.each2(function (i, choice) {
|
@@ -1722,7 +1783,6 @@
|
|
1722
1783
|
this.updateSelection(data);
|
1723
1784
|
} else {
|
1724
1785
|
val = (val === null) ? [] : val;
|
1725
|
-
this.setVal(val);
|
1726
1786
|
// val is a list of objects
|
1727
1787
|
$(val).each(function () { data.push(self.id(this)); });
|
1728
1788
|
this.setVal(data);
|
@@ -1753,7 +1813,7 @@
|
|
1753
1813
|
this.searchContainer.show();
|
1754
1814
|
// make sure the search container is the last item in the list
|
1755
1815
|
this.searchContainer.appendTo(this.searchContainer.parent());
|
1756
|
-
// since we collapsed the width in
|
1816
|
+
// since we collapsed the width in dragStarted, we resize it here
|
1757
1817
|
this.resizeSearch();
|
1758
1818
|
|
1759
1819
|
// update selection
|
@@ -1763,6 +1823,22 @@
|
|
1763
1823
|
});
|
1764
1824
|
this.setVal(val);
|
1765
1825
|
this.triggerChange();
|
1826
|
+
},
|
1827
|
+
|
1828
|
+
// multi
|
1829
|
+
data: function(values) {
|
1830
|
+
var self=this, ids;
|
1831
|
+
if (arguments.length === 0) {
|
1832
|
+
return this.selection
|
1833
|
+
.find(".select2-search-choice")
|
1834
|
+
.map(function() { return $(this).data("select2-data"); })
|
1835
|
+
.get();
|
1836
|
+
} else {
|
1837
|
+
ids = $.map(values, function(e) { return self.opts.id(e)});
|
1838
|
+
this.setVal(ids);
|
1839
|
+
this.updateSelection(values);
|
1840
|
+
this.clearSearch();
|
1841
|
+
}
|
1766
1842
|
}
|
1767
1843
|
});
|
1768
1844
|
|
@@ -1771,7 +1847,7 @@
|
|
1771
1847
|
var args = Array.prototype.slice.call(arguments, 0),
|
1772
1848
|
opts,
|
1773
1849
|
select2,
|
1774
|
-
value, multiple, allowedMethods = ["val", "destroy", "open", "close", "focus", "isFocused", "container", "onSortStart", "onSortEnd", "enable", "disable", "positionDropdown"];
|
1850
|
+
value, multiple, allowedMethods = ["val", "destroy", "open", "close", "focus", "isFocused", "container", "onSortStart", "onSortEnd", "enable", "disable", "positionDropdown", "data"];
|
1775
1851
|
|
1776
1852
|
this.each(function () {
|
1777
1853
|
if (args.length === 0 || typeof(args[0]) === "object") {
|
@@ -456,9 +456,15 @@
|
|
456
456
|
|
457
457
|
/* end multiselect
|
458
458
|
|
459
|
-
.select2-match
|
459
|
+
.select2-result-selectable .select2-match
|
460
460
|
text-decoration: underline
|
461
461
|
|
462
|
+
.select2-result-unselectable
|
463
|
+
.select2-result-selectable .select2-match
|
464
|
+
text-decoration: underline
|
465
|
+
.select2-match
|
466
|
+
text-decoration: none
|
467
|
+
|
462
468
|
.select2-offscreen
|
463
469
|
position: absolute
|
464
470
|
left: -1000px
|
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.7
|
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-06
|
12
|
+
date: 2012-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &78770620 !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: *78770620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &78770270 !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: *78770270
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &78769910 !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: *78769910
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sass
|
49
|
-
requirement: &
|
49
|
+
requirement: &78769590 !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: *78769590
|
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.
|