##// END OF EJS Templates
js: update select2 to 3.5.4...
Mads Kiilerich -
r5924:304e83e9 default
parent child Browse files
Show More
@@ -1,13 +1,10 b''
1 /*
1 /*
2 Version: 3.5.0 Timestamp: Mon Jun 16 19:29:44 EDT 2014
2 Version: 3.5.4 Timestamp: Sun Aug 30 13:30:32 EDT 2015
3 */
3 */
4 .select2-container {
4 .select2-container {
5 margin: 0;
5 margin: 0;
6 position: relative;
6 position: relative;
7 display: inline-block;
7 display: inline-block;
8 /* inline-block for ie7 */
9 zoom: 1;
10 *display: inline;
11 vertical-align: middle;
8 vertical-align: middle;
12 }
9 }
13
10
@@ -180,10 +177,6 b' html[dir="rtl"] .select2-container .sele'
180 width: auto;
177 width: auto;
181 }
178 }
182
179
183 .select2-drop-auto-width .select2-search {
184 padding-top: 4px;
185 }
186
187 .select2-container .select2-choice .select2-arrow {
180 .select2-container .select2-choice .select2-arrow {
188 display: inline-block;
181 display: inline-block;
189 width: 18px;
182 width: 18px;
@@ -230,8 +223,7 b' html[dir="rtl"] .select2-container .sele'
230 width: 100%;
223 width: 100%;
231 min-height: 26px;
224 min-height: 26px;
232 margin: 0;
225 margin: 0;
233 padding-left: 4px;
226 padding: 4px 4px 0 4px;
234 padding-right: 4px;
235
227
236 position: relative;
228 position: relative;
237 z-index: 10000;
229 z-index: 10000;
@@ -273,10 +265,6 b' html[dir="rtl"] .select2-search input {'
273 background: url('select2.png') no-repeat -37px -22px, linear-gradient(to bottom, #fff 85%, #eee 99%) 0 0;
265 background: url('select2.png') no-repeat -37px -22px, linear-gradient(to bottom, #fff 85%, #eee 99%) 0 0;
274 }
266 }
275
267
276 .select2-drop.select2-drop-above .select2-search input {
277 margin-top: 4px;
278 }
279
280 .select2-search input.select2-active {
268 .select2-search input.select2-active {
281 background: #fff url('select2-spinner.gif') no-repeat 100%;
269 background: #fff url('select2-spinner.gif') no-repeat 100%;
282 background: url('select2-spinner.gif') no-repeat 100%, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, #fff), color-stop(0.99, #eee));
270 background: url('select2-spinner.gif') no-repeat 100%, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, #fff), color-stop(0.99, #eee));
@@ -422,9 +410,9 b' html[dir="rtl"] .select2-results {'
422 color: #000;
410 color: #000;
423 }
411 }
424
412
425
426 .select2-results .select2-no-results,
413 .select2-results .select2-no-results,
427 .select2-results .select2-searching,
414 .select2-results .select2-searching,
415 .select2-results .select2-ajax-error,
428 .select2-results .select2-selection-limit {
416 .select2-results .select2-selection-limit {
429 background: #f4f4f4;
417 background: #f4f4f4;
430 display: list-item;
418 display: list-item;
@@ -454,6 +442,10 b' disabled look for disabled choices in th'
454 background: #f4f4f4 url('select2-spinner.gif') no-repeat 100%;
442 background: #f4f4f4 url('select2-spinner.gif') no-repeat 100%;
455 }
443 }
456
444
445 .select2-results .select2-ajax-error {
446 background: rgba(255, 50, 50, .2);
447 }
448
457 .select2-more-results {
449 .select2-more-results {
458 background: #f4f4f4;
450 background: #f4f4f4;
459 display: list-item;
451 display: list-item;
@@ -582,7 +574,7 b' html[dir="rtl"] .select2-container-multi'
582 background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eee));
574 background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eee));
583 background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
575 background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
584 background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
576 background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
585 background-image: linear-gradient(to top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
577 background-image: linear-gradient(to bottom, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%);
586 }
578 }
587 html[dir="rtl"] .select2-container-multi .select2-choices .select2-search-choice
579 html[dir="rtl"] .select2-container-multi .select2-choices .select2-search-choice
588 {
580 {
@@ -1,7 +1,7 b''
1 /*
1 /*
2 Copyright 2012 Igor Vaynberg
2 Copyright 2012 Igor Vaynberg
3
3
4 Version: 3.5.0 Timestamp: Mon Jun 16 19:29:44 EDT 2014
4 Version: 3.5.4 Timestamp: Sun Aug 30 13:30:32 EDT 2015
5
5
6 This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
6 This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
7 General Public License version 2 (the "GPL License"). You may choose either license to govern your
7 General Public License version 2 (the "GPL License"). You may choose either license to govern your
@@ -46,7 +46,7 b' the specific language governing permissi'
46 return;
46 return;
47 }
47 }
48
48
49 var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
49 var AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
50 lastMousePosition={x:0,y:0}, $document, scrollBarDimensions,
50 lastMousePosition={x:0,y:0}, $document, scrollBarDimensions,
51
51
52 KEY = {
52 KEY = {
@@ -132,7 +132,7 b' the specific language governing permissi'
132
132
133 function measureScrollbar () {
133 function measureScrollbar () {
134 var $template = $( MEASURE_SCROLLBAR_TEMPLATE );
134 var $template = $( MEASURE_SCROLLBAR_TEMPLATE );
135 $template.appendTo('body');
135 $template.appendTo(document.body);
136
136
137 var dim = {
137 var dim = {
138 width: $template.width() - $template[0].clientWidth,
138 width: $template.width() - $template[0].clientWidth,
@@ -160,16 +160,16 b' the specific language governing permissi'
160 }
160 }
161
161
162 /**
162 /**
163 * Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty
163 * Splits the string into an array of values, transforming each value. An empty array is returned for nulls or empty
164 * strings
164 * strings
165 * @param string
165 * @param string
166 * @param separator
166 * @param separator
167 */
167 */
168 function splitVal(string, separator) {
168 function splitVal(string, separator, transform) {
169 var val, i, l;
169 var val, i, l;
170 if (string === null || string.length < 1) return [];
170 if (string === null || string.length < 1) return [];
171 val = string.split(separator);
171 val = string.split(separator);
172 for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
172 for (i = 0, l = val.length; i < l; i = i + 1) val[i] = transform(val[i]);
173 return val;
173 return val;
174 }
174 }
175
175
@@ -311,7 +311,7 b' the specific language governing permissi'
311 whiteSpace: "nowrap"
311 whiteSpace: "nowrap"
312 });
312 });
313 sizer.attr("class","select2-sizer");
313 sizer.attr("class","select2-sizer");
314 $("body").append(sizer);
314 $(document.body).append(sizer);
315 }
315 }
316 sizer.text(e.val());
316 sizer.text(e.val());
317 return sizer.width();
317 return sizer.width();
@@ -444,6 +444,16 b' the specific language governing permissi'
444 // added query as third paramter to keep backwards compatibility
444 // added query as third paramter to keep backwards compatibility
445 var results = options.results(data, query.page, query);
445 var results = options.results(data, query.page, query);
446 query.callback(results);
446 query.callback(results);
447 },
448 error: function(jqXHR, textStatus, errorThrown){
449 var results = {
450 hasError: true,
451 jqXHR: jqXHR,
452 textStatus: textStatus,
453 errorThrown: errorThrown
454 };
455
456 query.callback(results);
447 }
457 }
448 });
458 });
449 handler = transport.call(self, params);
459 handler = transport.call(self, params);
@@ -689,12 +699,15 b' the specific language governing permissi'
689
699
690 this.container = this.createContainer();
700 this.container = this.createContainer();
691
701
692 this.liveRegion = $("<span>", {
702 this.liveRegion = $('.select2-hidden-accessible');
693 role: "status",
703 if (this.liveRegion.length == 0) {
694 "aria-live": "polite"
704 this.liveRegion = $("<span>", {
695 })
705 role: "status",
696 .addClass("select2-hidden-accessible")
706 "aria-live": "polite"
697 .appendTo(document.body);
707 })
708 .addClass("select2-hidden-accessible")
709 .appendTo(document.body);
710 }
698
711
699 this.containerId="s2id_"+(opts.element.attr("id") || "autogen"+nextUid());
712 this.containerId="s2id_"+(opts.element.attr("id") || "autogen"+nextUid());
700 this.containerEventName= this.containerId
713 this.containerEventName= this.containerId
@@ -704,7 +717,7 b' the specific language governing permissi'
704
717
705 this.container.attr("title", opts.element.attr("title"));
718 this.container.attr("title", opts.element.attr("title"));
706
719
707 this.body = $("body");
720 this.body = $(document.body);
708
721
709 syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
722 syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
710
723
@@ -801,7 +814,7 b' the specific language governing permissi'
801 // focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
814 // focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
802 this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
815 this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
803
816
804 this.nextSearchTerm = undefined;
817 this.lastSearchTerm = undefined;
805
818
806 if ($.isFunction(this.opts.initSelection)) {
819 if ($.isFunction(this.opts.initSelection)) {
807 // initialize selection based on the current value of the source element
820 // initialize selection based on the current value of the source element
@@ -836,13 +849,15 b' the specific language governing permissi'
836
849
837 // abstract
850 // abstract
838 destroy: function () {
851 destroy: function () {
839 var element=this.opts.element, select2 = element.data("select2");
852 var element=this.opts.element, select2 = element.data("select2"), self = this;
840
853
841 this.close();
854 this.close();
842
855
843 if (element.length && element[0].detachEvent) {
856 if (element.length && element[0].detachEvent && self._sync) {
844 element.each(function () {
857 element.each(function () {
845 this.detachEvent("onpropertychange", this._sync);
858 if (self._sync) {
859 this.detachEvent("onpropertychange", self._sync);
860 }
846 });
861 });
847 }
862 }
848 if (this.propertyObserver) {
863 if (this.propertyObserver) {
@@ -855,17 +870,21 b' the specific language governing permissi'
855 select2.container.remove();
870 select2.container.remove();
856 select2.liveRegion.remove();
871 select2.liveRegion.remove();
857 select2.dropdown.remove();
872 select2.dropdown.remove();
858 element
873 element.removeData("select2")
859 .removeClass("select2-offscreen")
874 .off(".select2");
860 .removeData("select2")
875 if (!element.is("input[type='hidden']")) {
861 .off(".select2")
876 element
862 .prop("autofocus", this.autofocus || false);
877 .show()
863 if (this.elementTabIndex) {
878 .prop("autofocus", this.autofocus || false);
864 element.attr({tabindex: this.elementTabIndex});
879 if (this.elementTabIndex) {
880 element.attr({tabindex: this.elementTabIndex});
881 } else {
882 element.removeAttr("tabindex");
883 }
884 element.show();
865 } else {
885 } else {
866 element.removeAttr("tabindex");
886 element.css("display", "");
867 }
887 }
868 element.show();
869 }
888 }
870
889
871 cleanupJQueryElements.call(this,
890 cleanupJQueryElements.call(this,
@@ -917,6 +936,155 b' the specific language governing permissi'
917 });
936 });
918 }
937 }
919
938
939 opts.debug = opts.debug || $.fn.select2.defaults.debug;
940
941 // Warnings for options renamed/removed in Select2 4.0.0
942 // Only when it's enabled through debug mode
943 if (opts.debug && console && console.warn) {
944 // id was removed
945 if (opts.id != null) {
946 console.warn(
947 'Select2: The `id` option has been removed in Select2 4.0.0, ' +
948 'consider renaming your `id` property or mapping the property before your data makes it to Select2. ' +
949 'You can read more at https://select2.github.io/announcements-4.0.html#changed-id'
950 );
951 }
952
953 // text was removed
954 if (opts.text != null) {
955 console.warn(
956 'Select2: The `text` option has been removed in Select2 4.0.0, ' +
957 'consider renaming your `text` property or mapping the property before your data makes it to Select2. ' +
958 'You can read more at https://select2.github.io/announcements-4.0.html#changed-id'
959 );
960 }
961
962 // sortResults was renamed to results
963 if (opts.sortResults != null) {
964 console.warn(
965 'Select2: the `sortResults` option has been renamed to `sorter` in Select2 4.0.0. '
966 );
967 }
968
969 // selectOnBlur was renamed to selectOnClose
970 if (opts.selectOnBlur != null) {
971 console.warn(
972 'Select2: The `selectOnBlur` option has been renamed to `selectOnClose` in Select2 4.0.0.'
973 );
974 }
975
976 // ajax.results was renamed to ajax.processResults
977 if (opts.ajax != null && opts.ajax.results != null) {
978 console.warn(
979 'Select2: The `ajax.results` option has been renamed to `ajax.processResults` in Select2 4.0.0.'
980 );
981 }
982
983 // format* options were renamed to language.*
984 if (opts.formatNoResults != null) {
985 console.warn(
986 'Select2: The `formatNoResults` option has been renamed to `language.noResults` in Select2 4.0.0.'
987 );
988 }
989 if (opts.formatSearching != null) {
990 console.warn(
991 'Select2: The `formatSearching` option has been renamed to `language.searching` in Select2 4.0.0.'
992 );
993 }
994 if (opts.formatInputTooShort != null) {
995 console.warn(
996 'Select2: The `formatInputTooShort` option has been renamed to `language.inputTooShort` in Select2 4.0.0.'
997 );
998 }
999 if (opts.formatInputTooLong != null) {
1000 console.warn(
1001 'Select2: The `formatInputTooLong` option has been renamed to `language.inputTooLong` in Select2 4.0.0.'
1002 );
1003 }
1004 if (opts.formatLoading != null) {
1005 console.warn(
1006 'Select2: The `formatLoading` option has been renamed to `language.loadingMore` in Select2 4.0.0.'
1007 );
1008 }
1009 if (opts.formatSelectionTooBig != null) {
1010 console.warn(
1011 'Select2: The `formatSelectionTooBig` option has been renamed to `language.maximumSelected` in Select2 4.0.0.'
1012 );
1013 }
1014
1015 if (opts.element.data('select2Tags')) {
1016 console.warn(
1017 'Select2: The `data-select2-tags` attribute has been renamed to `data-tags` in Select2 4.0.0.'
1018 );
1019 }
1020 }
1021
1022 // Aliasing options renamed in Select2 4.0.0
1023
1024 // data-select2-tags -> data-tags
1025 if (opts.element.data('tags') != null) {
1026 var elemTags = opts.element.data('tags');
1027
1028 // data-tags should actually be a boolean
1029 if (!$.isArray(elemTags)) {
1030 elemTags = [];
1031 }
1032
1033 opts.element.data('select2Tags', elemTags);
1034 }
1035
1036 // sortResults -> sorter
1037 if (opts.sorter != null) {
1038 opts.sortResults = opts.sorter;
1039 }
1040
1041 // selectOnBlur -> selectOnClose
1042 if (opts.selectOnClose != null) {
1043 opts.selectOnBlur = opts.selectOnClose;
1044 }
1045
1046 // ajax.results -> ajax.processResults
1047 if (opts.ajax != null) {
1048 if ($.isFunction(opts.ajax.processResults)) {
1049 opts.ajax.results = opts.ajax.processResults;
1050 }
1051 }
1052
1053 // Formatters/language options
1054 if (opts.language != null) {
1055 var lang = opts.language;
1056
1057 // formatNoMatches -> language.noMatches
1058 if ($.isFunction(lang.noMatches)) {
1059 opts.formatNoMatches = lang.noMatches;
1060 }
1061
1062 // formatSearching -> language.searching
1063 if ($.isFunction(lang.searching)) {
1064 opts.formatSearching = lang.searching;
1065 }
1066
1067 // formatInputTooShort -> language.inputTooShort
1068 if ($.isFunction(lang.inputTooShort)) {
1069 opts.formatInputTooShort = lang.inputTooShort;
1070 }
1071
1072 // formatInputTooLong -> language.inputTooLong
1073 if ($.isFunction(lang.inputTooLong)) {
1074 opts.formatInputTooLong = lang.inputTooLong;
1075 }
1076
1077 // formatLoading -> language.loadingMore
1078 if ($.isFunction(lang.loadingMore)) {
1079 opts.formatLoading = lang.loadingMore;
1080 }
1081
1082 // formatSelectionTooBig -> language.maximumSelected
1083 if ($.isFunction(lang.maximumSelected)) {
1084 opts.formatSelectionTooBig = lang.maximumSelected;
1085 }
1086 }
1087
920 opts = $.extend({}, {
1088 opts = $.extend({}, {
921 populateResults: function(container, results, query) {
1089 populateResults: function(container, results, query) {
922 var populate, id=this.opts.id, liveRegion=this.liveRegion;
1090 var populate, id=this.opts.id, liveRegion=this.liveRegion;
@@ -960,7 +1128,6 b' the specific language governing permissi'
960
1128
961
1129
962 if (compound) {
1130 if (compound) {
963
964 innerContainer=$("<ul></ul>");
1131 innerContainer=$("<ul></ul>");
965 innerContainer.addClass("select2-result-sub");
1132 innerContainer.addClass("select2-result-sub");
966 populate(result.children, innerContainer, depth+1);
1133 populate(result.children, innerContainer, depth+1);
@@ -1027,11 +1194,10 b' the specific language governing permissi'
1027
1194
1028 query.callback(data);
1195 query.callback(data);
1029 });
1196 });
1030 // this is needed because inside val() we construct choices from options and there id is hardcoded
1197 // this is needed because inside val() we construct choices from options and their id is hardcoded
1031 opts.id=function(e) { return e.id; };
1198 opts.id=function(e) { return e.id; };
1032 } else {
1199 } else {
1033 if (!("query" in opts)) {
1200 if (!("query" in opts)) {
1034
1035 if ("ajax" in opts) {
1201 if ("ajax" in opts) {
1036 ajaxUrl = opts.element.data("ajax-url");
1202 ajaxUrl = opts.element.data("ajax-url");
1037 if (ajaxUrl && ajaxUrl.length > 0) {
1203 if (ajaxUrl && ajaxUrl.length > 0) {
@@ -1048,7 +1214,7 b' the specific language governing permissi'
1048 if (opts.initSelection === undefined) {
1214 if (opts.initSelection === undefined) {
1049 opts.initSelection = function (element, callback) {
1215 opts.initSelection = function (element, callback) {
1050 var data = [];
1216 var data = [];
1051 $(splitVal(element.val(), opts.separator)).each(function () {
1217 $(splitVal(element.val(), opts.separator, opts.transformVal)).each(function () {
1052 var obj = { id: this, text: this },
1218 var obj = { id: this, text: this },
1053 tags = opts.tags;
1219 tags = opts.tags;
1054 if ($.isFunction(tags)) tags=tags();
1220 if ($.isFunction(tags)) tags=tags();
@@ -1103,11 +1269,15 b' the specific language governing permissi'
1103 if (readonly === undefined) readonly = false;
1269 if (readonly === undefined) readonly = false;
1104 this.readonly(readonly);
1270 this.readonly(readonly);
1105
1271
1106 syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
1272 if (this.container) {
1107 this.container.addClass(evaluate(this.opts.containerCssClass, this.opts.element));
1273 syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
1108
1274 this.container.addClass(evaluate(this.opts.containerCssClass, this.opts.element));
1109 syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
1275 }
1110 this.dropdown.addClass(evaluate(this.opts.dropdownCssClass, this.opts.element));
1276
1277 if (this.dropdown) {
1278 syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
1279 this.dropdown.addClass(evaluate(this.opts.dropdownCssClass, this.opts.element));
1280 }
1111
1281
1112 });
1282 });
1113
1283
@@ -1212,9 +1382,10 b' the specific language governing permissi'
1212 // abstract
1382 // abstract
1213 positionDropdown: function() {
1383 positionDropdown: function() {
1214 var $dropdown = this.dropdown,
1384 var $dropdown = this.dropdown,
1215 offset = this.container.offset(),
1385 container = this.container,
1216 height = this.container.outerHeight(false),
1386 offset = container.offset(),
1217 width = this.container.outerWidth(false),
1387 height = container.outerHeight(false),
1388 width = container.outerWidth(false),
1218 dropHeight = $dropdown.outerHeight(false),
1389 dropHeight = $dropdown.outerHeight(false),
1219 $window = $(window),
1390 $window = $(window),
1220 windowWidth = $window.width(),
1391 windowWidth = $window.width(),
@@ -1226,7 +1397,12 b' the specific language governing permissi'
1226 enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
1397 enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
1227 enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
1398 enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
1228 dropWidth = $dropdown.outerWidth(false),
1399 dropWidth = $dropdown.outerWidth(false),
1229 enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
1400 enoughRoomOnRight = function() {
1401 return dropLeft + dropWidth <= viewPortRight;
1402 },
1403 enoughRoomOnLeft = function() {
1404 return offset.left + viewPortRight + container.outerWidth(false) > dropWidth;
1405 },
1230 aboveNow = $dropdown.hasClass("select2-drop-above"),
1406 aboveNow = $dropdown.hasClass("select2-drop-above"),
1231 bodyOffset,
1407 bodyOffset,
1232 above,
1408 above,
@@ -1261,7 +1437,6 b' the specific language governing permissi'
1261 dropTop = offset.top + height;
1437 dropTop = offset.top + height;
1262 dropLeft = offset.left;
1438 dropLeft = offset.left;
1263 dropWidth = $dropdown.outerWidth(false);
1439 dropWidth = $dropdown.outerWidth(false);
1264 enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
1265 $dropdown.show();
1440 $dropdown.show();
1266
1441
1267 // fix so the cursor does not move to the left within the search-textbox in IE
1442 // fix so the cursor does not move to the left within the search-textbox in IE
@@ -1276,7 +1451,6 b' the specific language governing permissi'
1276 dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
1451 dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
1277 dropWidth > width ? width = dropWidth : dropWidth = width;
1452 dropWidth > width ? width = dropWidth : dropWidth = width;
1278 dropHeight = $dropdown.outerHeight(false);
1453 dropHeight = $dropdown.outerHeight(false);
1279 enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
1280 }
1454 }
1281 else {
1455 else {
1282 this.container.removeClass('select2-drop-auto-width');
1456 this.container.removeClass('select2-drop-auto-width');
@@ -1292,7 +1466,7 b' the specific language governing permissi'
1292 dropLeft -= bodyOffset.left;
1466 dropLeft -= bodyOffset.left;
1293 }
1467 }
1294
1468
1295 if (!enoughRoomOnRight) {
1469 if (!enoughRoomOnRight() && enoughRoomOnLeft()) {
1296 dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
1470 dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
1297 }
1471 }
1298
1472
@@ -1302,10 +1476,11 b' the specific language governing permissi'
1302 };
1476 };
1303
1477
1304 if (above) {
1478 if (above) {
1479 this.container.addClass("select2-drop-above");
1480 $dropdown.addClass("select2-drop-above");
1481 dropHeight = $dropdown.outerHeight(false);
1305 css.top = offset.top - dropHeight;
1482 css.top = offset.top - dropHeight;
1306 css.bottom = 'auto';
1483 css.bottom = 'auto';
1307 this.container.addClass("select2-drop-above");
1308 $dropdown.addClass("select2-drop-above");
1309 }
1484 }
1310 else {
1485 else {
1311 css.top = dropTop;
1486 css.top = dropTop;
@@ -1381,7 +1556,7 b' the specific language governing permissi'
1381
1556
1382 // create the dropdown mask if doesn't already exist
1557 // create the dropdown mask if doesn't already exist
1383 mask = $("#select2-drop-mask");
1558 mask = $("#select2-drop-mask");
1384 if (mask.length == 0) {
1559 if (mask.length === 0) {
1385 mask = $(document.createElement("div"));
1560 mask = $(document.createElement("div"));
1386 mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
1561 mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
1387 mask.hide();
1562 mask.hide();
@@ -1458,6 +1633,9 b' the specific language governing permissi'
1458
1633
1459 this.clearSearch();
1634 this.clearSearch();
1460 this.search.removeClass("select2-active");
1635 this.search.removeClass("select2-active");
1636
1637 // Remove the aria active descendant for highlighted element
1638 this.search.removeAttr("aria-activedescendant");
1461 this.opts.element.trigger($.Event("select2-close"));
1639 this.opts.element.trigger($.Event("select2-close"));
1462 },
1640 },
1463
1641
@@ -1476,6 +1654,27 b' the specific language governing permissi'
1476
1654
1477 },
1655 },
1478
1656
1657 /**
1658 * @return {Boolean} Whether or not search value was changed.
1659 * @private
1660 */
1661 prefillNextSearchTerm: function () {
1662 // initializes search's value with nextSearchTerm (if defined by user)
1663 // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
1664 if(this.search.val() !== "") {
1665 return false;
1666 }
1667
1668 var nextSearchTerm = this.opts.nextSearchTerm(this.data(), this.lastSearchTerm);
1669 if(nextSearchTerm !== undefined){
1670 this.search.val(nextSearchTerm);
1671 this.search.select();
1672 return true;
1673 }
1674
1675 return false;
1676 },
1677
1479 //abstract
1678 //abstract
1480 getMaximumSelectionSize: function() {
1679 getMaximumSelectionSize: function() {
1481 return evaluate(this.opts.maximumSelectionSize, this.opts.element);
1680 return evaluate(this.opts.maximumSelectionSize, this.opts.element);
@@ -1515,7 +1714,7 b' the specific language governing permissi'
1515 }
1714 }
1516 }
1715 }
1517
1716
1518 rb = results.offset().top + results.outerHeight(true);
1717 rb = results.offset().top + results.outerHeight(false);
1519 if (hb > rb) {
1718 if (hb > rb) {
1520 results.scrollTop(results.scrollTop() + (hb - rb));
1719 results.scrollTop(results.scrollTop() + (hb - rb));
1521 }
1720 }
@@ -1638,7 +1837,7 b' the specific language governing permissi'
1638 self.postprocessResults(data, false, false);
1837 self.postprocessResults(data, false, false);
1639
1838
1640 if (data.more===true) {
1839 if (data.more===true) {
1641 more.detach().appendTo(results).text(evaluate(self.opts.formatLoadMore, self.opts.element, page+1));
1840 more.detach().appendTo(results).html(self.opts.escapeMarkup(evaluate(self.opts.formatLoadMore, self.opts.element, page+1)));
1642 window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1841 window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1643 } else {
1842 } else {
1644 more.remove();
1843 more.remove();
@@ -1691,7 +1890,7 b' the specific language governing permissi'
1691 self.liveRegion.text(results.text());
1890 self.liveRegion.text(results.text());
1692 }
1891 }
1693 else {
1892 else {
1694 self.liveRegion.text(self.opts.formatMatches(results.find('.select2-result-selectable').length));
1893 self.liveRegion.text(self.opts.formatMatches(results.find('.select2-result-selectable:not(".select2-selected")').length));
1695 }
1894 }
1696 }
1895 }
1697
1896
@@ -1766,6 +1965,12 b' the specific language governing permissi'
1766 return;
1965 return;
1767 }
1966 }
1768
1967
1968 // handle ajax error
1969 if(data.hasError !== undefined && checkFormatter(opts.formatAjaxError, "formatAjaxError")) {
1970 render("<li class='select2-ajax-error'>" + evaluate(opts.formatAjaxError, opts.element, data.jqXHR, data.textStatus, data.errorThrown) + "</li>");
1971 return;
1972 }
1973
1769 // save context, if any
1974 // save context, if any
1770 this.context = (data.context===undefined) ? null : data.context;
1975 this.context = (data.context===undefined) ? null : data.context;
1771 // create a default choice and prepend it to the list
1976 // create a default choice and prepend it to the list
@@ -1783,6 +1988,9 b' the specific language governing permissi'
1783
1988
1784 if (data.results.length === 0 && checkFormatter(opts.formatNoMatches, "formatNoMatches")) {
1989 if (data.results.length === 0 && checkFormatter(opts.formatNoMatches, "formatNoMatches")) {
1785 render("<li class='select2-no-results'>" + evaluate(opts.formatNoMatches, opts.element, search.val()) + "</li>");
1990 render("<li class='select2-no-results'>" + evaluate(opts.formatNoMatches, opts.element, search.val()) + "</li>");
1991 if(this.showSearch){
1992 this.showSearch(search.val());
1993 }
1786 return;
1994 return;
1787 }
1995 }
1788
1996
@@ -1887,7 +2095,7 b' the specific language governing permissi'
1887 } else if (this.opts.width === "copy" || this.opts.width === "resolve") {
2095 } else if (this.opts.width === "copy" || this.opts.width === "resolve") {
1888 // check if there is inline style on the element that contains width
2096 // check if there is inline style on the element that contains width
1889 style = this.opts.element.attr('style');
2097 style = this.opts.element.attr('style');
1890 if (style !== undefined) {
2098 if (typeof(style) === "string") {
1891 attrs = style.split(';');
2099 attrs = style.split(';');
1892 for (i = 0, l = attrs.length; i < l; i = i + 1) {
2100 for (i = 0, l = attrs.length; i < l; i = i + 1) {
1893 attr = attrs[i].replace(/\s/g, '');
2101 attr = attrs[i].replace(/\s/g, '');
@@ -1986,14 +2194,7 b' the specific language governing permissi'
1986 }
2194 }
1987 }
2195 }
1988
2196
1989 // initializes search's value with nextSearchTerm (if defined by user)
2197 this.prefillNextSearchTerm();
1990 // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
1991 if(this.search.val() === "") {
1992 if(this.nextSearchTerm != undefined){
1993 this.search.val(this.nextSearchTerm);
1994 this.search.select();
1995 }
1996 }
1997
2198
1998 this.focusser.prop("disabled", true).val("");
2199 this.focusser.prop("disabled", true).val("");
1999 this.updateResults(true);
2200 this.updateResults(true);
@@ -2080,6 +2281,7 b' the specific language governing permissi'
2080 this.focusser.attr("id", "s2id_autogen"+idSuffix);
2281 this.focusser.attr("id", "s2id_autogen"+idSuffix);
2081
2282
2082 elementLabel = $("label[for='" + this.opts.element.attr("id") + "']");
2283 elementLabel = $("label[for='" + this.opts.element.attr("id") + "']");
2284 this.opts.element.on('focus.select2', this.bind(function () { this.focus(); }));
2083
2285
2084 this.focusser.prev()
2286 this.focusser.prev()
2085 .text(elementLabel.text())
2287 .text(elementLabel.text())
@@ -2101,6 +2303,9 b' the specific language governing permissi'
2101 this.search.on("keydown", this.bind(function (e) {
2303 this.search.on("keydown", this.bind(function (e) {
2102 if (!this.isInterfaceEnabled()) return;
2304 if (!this.isInterfaceEnabled()) return;
2103
2305
2306 // filter 229 keyCodes (input method editor is processing key input)
2307 if (229 == e.keyCode) return;
2308
2104 if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
2309 if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
2105 // prevent the page from scrolling
2310 // prevent the page from scrolling
2106 killEvent(e);
2311 killEvent(e);
@@ -2132,7 +2337,7 b' the specific language governing permissi'
2132 // without this the search field loses focus which is annoying
2337 // without this the search field loses focus which is annoying
2133 if (document.activeElement === this.body.get(0)) {
2338 if (document.activeElement === this.body.get(0)) {
2134 window.setTimeout(this.bind(function() {
2339 window.setTimeout(this.bind(function() {
2135 if (this.opened()) {
2340 if (this.opened() && this.results && this.results.length > 1) {
2136 this.search.focus();
2341 this.search.focus();
2137 }
2342 }
2138 }), 0);
2343 }), 0);
@@ -2181,11 +2386,17 b' the specific language governing permissi'
2181 }));
2386 }));
2182
2387
2183 selection.on("mousedown touchstart", "abbr", this.bind(function (e) {
2388 selection.on("mousedown touchstart", "abbr", this.bind(function (e) {
2184 if (!this.isInterfaceEnabled()) return;
2389 if (!this.isInterfaceEnabled()) {
2390 return;
2391 }
2392
2185 this.clear();
2393 this.clear();
2186 killEventImmediately(e);
2394 killEventImmediately(e);
2187 this.close();
2395 this.close();
2188 this.selection.focus();
2396
2397 if (this.selection) {
2398 this.selection.focus();
2399 }
2189 }));
2400 }));
2190
2401
2191 selection.on("mousedown touchstart", this.bind(function (e) {
2402 selection.on("mousedown touchstart", this.bind(function (e) {
@@ -2234,7 +2445,7 b' the specific language governing permissi'
2234 }));
2445 }));
2235
2446
2236 this.initContainerWidth();
2447 this.initContainerWidth();
2237 this.opts.element.addClass("select2-offscreen");
2448 this.opts.element.hide();
2238 this.setPlaceholder();
2449 this.setPlaceholder();
2239
2450
2240 },
2451 },
@@ -2278,7 +2489,7 b' the specific language governing permissi'
2278 self.updateSelection(selected);
2489 self.updateSelection(selected);
2279 self.close();
2490 self.close();
2280 self.setPlaceholder();
2491 self.setPlaceholder();
2281 self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
2492 self.lastSearchTerm = self.search.val();
2282 }
2493 }
2283 });
2494 });
2284 }
2495 }
@@ -2415,7 +2626,7 b' the specific language governing permissi'
2415
2626
2416 this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
2627 this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
2417
2628
2418 this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
2629 this.lastSearchTerm = this.search.val();
2419 this.close();
2630 this.close();
2420
2631
2421 if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
2632 if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
@@ -2469,9 +2680,23 b' the specific language governing permissi'
2469
2680
2470 if (arguments.length > 1) {
2681 if (arguments.length > 1) {
2471 triggerChange = arguments[1];
2682 triggerChange = arguments[1];
2683
2684 if (this.opts.debug && console && console.warn) {
2685 console.warn(
2686 'Select2: The second option to `select2("val")` is not supported in Select2 4.0.0. ' +
2687 'The `change` event will always be triggered in 4.0.0.'
2688 );
2689 }
2472 }
2690 }
2473
2691
2474 if (this.select) {
2692 if (this.select) {
2693 if (this.opts.debug && console && console.warn) {
2694 console.warn(
2695 'Select2: Setting the value on a <select> using `select2("val")` is no longer supported in 4.0.0. ' +
2696 'You can use the `.val(newValue).trigger("change")` method provided by jQuery instead.'
2697 );
2698 }
2699
2475 this.select
2700 this.select
2476 .val(val)
2701 .val(val)
2477 .find("option").filter(function() { return this.selected }).each2(function (i, elm) {
2702 .find("option").filter(function() { return this.selected }).each2(function (i, elm) {
@@ -2520,6 +2745,13 b' the specific language governing permissi'
2520 if (data == undefined) data = null;
2745 if (data == undefined) data = null;
2521 return data;
2746 return data;
2522 } else {
2747 } else {
2748 if (this.opts.debug && console && console.warn) {
2749 console.warn(
2750 'Select2: The `select2("data")` method can no longer set selected values in 4.0.0, ' +
2751 'consider using the `.val()` method instead.'
2752 );
2753 }
2754
2523 if (arguments.length > 1) {
2755 if (arguments.length > 1) {
2524 triggerChange = arguments[1];
2756 triggerChange = arguments[1];
2525 }
2757 }
@@ -2563,7 +2795,6 b' the specific language governing permissi'
2563 self=this;
2795 self=this;
2564
2796
2565 // TODO validate placeholder is a string if specified
2797 // TODO validate placeholder is a string if specified
2566
2567 if (opts.element.get(0).tagName.toLowerCase() === "select") {
2798 if (opts.element.get(0).tagName.toLowerCase() === "select") {
2568 // install the selection initializer
2799 // install the selection initializer
2569 opts.initSelection = function (element, callback) {
2800 opts.initSelection = function (element, callback) {
@@ -2578,7 +2809,7 b' the specific language governing permissi'
2578 } else if ("data" in opts) {
2809 } else if ("data" in opts) {
2579 // install default initSelection when applied to hidden input and data is local
2810 // install default initSelection when applied to hidden input and data is local
2580 opts.initSelection = opts.initSelection || function (element, callback) {
2811 opts.initSelection = opts.initSelection || function (element, callback) {
2581 var ids = splitVal(element.val(), opts.separator);
2812 var ids = splitVal(element.val(), opts.separator, opts.transformVal);
2582 //search in data by array of ids, storing matching items in a list
2813 //search in data by array of ids, storing matching items in a list
2583 var matches = [];
2814 var matches = [];
2584 opts.query({
2815 opts.query({
@@ -2655,8 +2886,7 b' the specific language governing permissi'
2655 this.selection = selection = this.container.find(selector);
2886 this.selection = selection = this.container.find(selector);
2656
2887
2657 var _this = this;
2888 var _this = this;
2658 this.selection.on("click", ".select2-search-choice:not(.select2-locked)", function (e) {
2889 this.selection.on("click", ".select2-container:not(.select2-container-disabled) .select2-search-choice:not(.select2-locked)", function (e) {
2659 //killEvent(e);
2660 _this.search[0].focus();
2890 _this.search[0].focus();
2661 _this.selectChoice($(this));
2891 _this.selectChoice($(this));
2662 });
2892 });
@@ -2667,6 +2897,7 b' the specific language governing permissi'
2667 this.search.prev()
2897 this.search.prev()
2668 .text($("label[for='" + this.opts.element.attr("id") + "']").text())
2898 .text($("label[for='" + this.opts.element.attr("id") + "']").text())
2669 .attr('for', this.search.attr('id'));
2899 .attr('for', this.search.attr('id'));
2900 this.opts.element.on('focus.select2', this.bind(function () { this.focus(); }));
2670
2901
2671 this.search.on("input paste", this.bind(function() {
2902 this.search.on("input paste", this.bind(function() {
2672 if (this.search.attr('placeholder') && this.search.val().length == 0) return;
2903 if (this.search.attr('placeholder') && this.search.val().length == 0) return;
@@ -2818,7 +3049,7 b' the specific language governing permissi'
2818 }));
3049 }));
2819
3050
2820 this.initContainerWidth();
3051 this.initContainerWidth();
2821 this.opts.element.addClass("select2-offscreen");
3052 this.opts.element.hide();
2822
3053
2823 // set the placeholder if necessary
3054 // set the placeholder if necessary
2824 this.clearSearch();
3055 this.clearSearch();
@@ -2884,16 +3115,9 b' the specific language governing permissi'
2884
3115
2885 this.focusSearch();
3116 this.focusSearch();
2886
3117
2887 // initializes search's value with nextSearchTerm (if defined by user)
3118 this.prefillNextSearchTerm();
2888 // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
2889 if(this.search.val() === "") {
2890 if(this.nextSearchTerm != undefined){
2891 this.search.val(this.nextSearchTerm);
2892 this.search.select();
2893 }
2894 }
2895
2896 this.updateResults(true);
3119 this.updateResults(true);
3120
2897 if (this.opts.shouldFocusInput(this)) {
3121 if (this.opts.shouldFocusInput(this)) {
2898 this.search.focus();
3122 this.search.focus();
2899 }
3123 }
@@ -2919,21 +3143,18 b' the specific language governing permissi'
2919
3143
2920 // multi
3144 // multi
2921 updateSelection: function (data) {
3145 updateSelection: function (data) {
2922 var ids = [], filtered = [], self = this;
3146 var ids = {}, filtered = [], self = this;
2923
3147
2924 // filter out duplicates
3148 // filter out duplicates
2925 $(data).each(function () {
3149 $(data).each(function () {
2926 if (indexOf(self.id(this), ids) < 0) {
3150 if (!(self.id(this) in ids)) {
2927 ids.push(self.id(this));
3151 ids[self.id(this)] = 0;
2928 filtered.push(this);
3152 filtered.push(this);
2929 }
3153 }
2930 });
3154 });
2931 data = filtered;
2932
3155
2933 this.selection.find(".select2-search-choice").remove();
3156 this.selection.find(".select2-search-choice").remove();
2934 $(data).each(function () {
3157 this.addSelectedChoice(filtered);
2935 self.addSelectedChoice(this);
2936 });
2937 self.postprocessResults();
3158 self.postprocessResults();
2938 },
3159 },
2939
3160
@@ -2953,14 +3174,14 b' the specific language governing permissi'
2953 // multi
3174 // multi
2954 onSelect: function (data, options) {
3175 onSelect: function (data, options) {
2955
3176
2956 if (!this.triggerSelect(data)) { return; }
3177 if (!this.triggerSelect(data) || data.text === "") { return; }
2957
3178
2958 this.addSelectedChoice(data);
3179 this.addSelectedChoice(data);
2959
3180
2960 this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
3181 this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
2961
3182
2962 // keep track of the search's value before it gets cleared
3183 // keep track of the search's value before it gets cleared
2963 this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
3184 this.lastSearchTerm = this.search.val();
2964
3185
2965 this.clearSearch();
3186 this.clearSearch();
2966 this.updateResults();
3187 this.updateResults();
@@ -2980,10 +3201,8 b' the specific language governing permissi'
2980 this.updateResults(true);
3201 this.updateResults(true);
2981 } else {
3202 } else {
2982 // initializes search's value with nextSearchTerm and update search result
3203 // initializes search's value with nextSearchTerm and update search result
2983 if(this.nextSearchTerm != undefined){
3204 if (this.prefillNextSearchTerm()) {
2984 this.search.val(this.nextSearchTerm);
2985 this.updateResults();
3205 this.updateResults();
2986 this.search.select();
2987 }
3206 }
2988 }
3207 }
2989 this.positionDropdown();
3208 this.positionDropdown();
@@ -3009,6 +3228,14 b' the specific language governing permissi'
3009 },
3228 },
3010
3229
3011 addSelectedChoice: function (data) {
3230 addSelectedChoice: function (data) {
3231 var val = this.getVal(), self = this;
3232 $(data).each(function () {
3233 val.push(self.createChoice(this));
3234 });
3235 this.setVal(val);
3236 },
3237
3238 createChoice: function (data) {
3012 var enableChoice = !data.locked,
3239 var enableChoice = !data.locked,
3013 enabledItem = $(
3240 enabledItem = $(
3014 "<li class='select2-search-choice'>" +
3241 "<li class='select2-search-choice'>" +
@@ -3021,13 +3248,12 b' the specific language governing permissi'
3021 "</li>");
3248 "</li>");
3022 var choice = enableChoice ? enabledItem : disabledItem,
3249 var choice = enableChoice ? enabledItem : disabledItem,
3023 id = this.id(data),
3250 id = this.id(data),
3024 val = this.getVal(),
3025 formatted,
3251 formatted,
3026 cssClass;
3252 cssClass;
3027
3253
3028 formatted=this.opts.formatSelection(data, choice.find("div"), this.opts.escapeMarkup);
3254 formatted=this.opts.formatSelection(data, choice.find("div"), this.opts.escapeMarkup);
3029 if (formatted != undefined) {
3255 if (formatted != undefined) {
3030 choice.find("div").replaceWith("<div>"+formatted+"</div>");
3256 choice.find("div").replaceWith($("<div></div>").html(formatted));
3031 }
3257 }
3032 cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
3258 cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
3033 if (cssClass != undefined) {
3259 if (cssClass != undefined) {
@@ -3055,8 +3281,7 b' the specific language governing permissi'
3055 choice.data("select2-data", data);
3281 choice.data("select2-data", data);
3056 choice.insertBefore(this.searchContainer);
3282 choice.insertBefore(this.searchContainer);
3057
3283
3058 val.push(id);
3284 return id;
3059 this.setVal(val);
3060 },
3285 },
3061
3286
3062 // multi
3287 // multi
@@ -3125,7 +3350,7 b' the specific language governing permissi'
3125 }
3350 }
3126 });
3351 });
3127
3352
3128 if (this.highlight() == -1 && noHighlightUpdate !== false){
3353 if (this.highlight() == -1 && noHighlightUpdate !== false && this.opts.closeOnSelect === true){
3129 self.highlight(0);
3354 self.highlight(0);
3130 }
3355 }
3131
3356
@@ -3182,20 +3407,22 b' the specific language governing permissi'
3182 return val === null ? [] : val;
3407 return val === null ? [] : val;
3183 } else {
3408 } else {
3184 val = this.opts.element.val();
3409 val = this.opts.element.val();
3185 return splitVal(val, this.opts.separator);
3410 return splitVal(val, this.opts.separator, this.opts.transformVal);
3186 }
3411 }
3187 },
3412 },
3188
3413
3189 // multi
3414 // multi
3190 setVal: function (val) {
3415 setVal: function (val) {
3191 var unique;
3192 if (this.select) {
3416 if (this.select) {
3193 this.select.val(val);
3417 this.select.val(val);
3194 } else {
3418 } else {
3195 unique = [];
3419 var unique = [], valMap = {};
3196 // filter out duplicates
3420 // filter out duplicates
3197 $(val).each(function () {
3421 $(val).each(function () {
3198 if (indexOf(this, unique) < 0) unique.push(this);
3422 if (!(this in valMap)) {
3423 unique.push(this);
3424 valMap[this] = 0;
3425 }
3199 });
3426 });
3200 this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator));
3427 this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator));
3201 }
3428 }
@@ -3211,11 +3438,9 b' the specific language governing permissi'
3211 for (var j = 0; j < old.length; j++) {
3438 for (var j = 0; j < old.length; j++) {
3212 if (equal(this.opts.id(current[i]), this.opts.id(old[j]))) {
3439 if (equal(this.opts.id(current[i]), this.opts.id(old[j]))) {
3213 current.splice(i, 1);
3440 current.splice(i, 1);
3214 if(i>0){
3441 i--;
3215 i--;
3216 }
3217 old.splice(j, 1);
3442 old.splice(j, 1);
3218 j--;
3443 break;
3219 }
3444 }
3220 }
3445 }
3221 }
3446 }
@@ -3385,6 +3610,7 b' the specific language governing permissi'
3385
3610
3386 // plugin defaults, accessible to users
3611 // plugin defaults, accessible to users
3387 $.fn.select2.defaults = {
3612 $.fn.select2.defaults = {
3613 debug: false,
3388 width: "copy",
3614 width: "copy",
3389 loadMorePadding: 0,
3615 loadMorePadding: 0,
3390 closeOnSelect: true,
3616 closeOnSelect: true,
@@ -3395,29 +3621,36 b' the specific language governing permissi'
3395 dropdownCssClass: "",
3621 dropdownCssClass: "",
3396 formatResult: function(result, container, query, escapeMarkup) {
3622 formatResult: function(result, container, query, escapeMarkup) {
3397 var markup=[];
3623 var markup=[];
3398 markMatch(result.text, query.term, markup, escapeMarkup);
3624 markMatch(this.text(result), query.term, markup, escapeMarkup);
3399 return markup.join("");
3625 return markup.join("");
3400 },
3626 },
3627 transformVal: function(val) {
3628 return $.trim(val);
3629 },
3401 formatSelection: function (data, container, escapeMarkup) {
3630 formatSelection: function (data, container, escapeMarkup) {
3402 return data ? escapeMarkup(data.text) : undefined;
3631 return data ? escapeMarkup(this.text(data)) : undefined;
3403 },
3632 },
3404 sortResults: function (results, container, query) {
3633 sortResults: function (results, container, query) {
3405 return results;
3634 return results;
3406 },
3635 },
3407 formatResultCssClass: function(data) {return data.css;},
3636 formatResultCssClass: function(data) {return data.css;},
3408 formatSelectionCssClass: function(data, container) {return undefined;},
3637 formatSelectionCssClass: function(data, container) {return undefined;},
3409 formatMatches: function (matches) { if (matches === 1) { return "One result is available, press enter to select it."; } return matches + " results are available, use up and down arrow keys to navigate."; },
3410 formatNoMatches: function () { return "No matches found"; },
3411 formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1? "" : "s"); },
3412 formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
3413 formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3414 formatLoadMore: function (pageNumber) { return "Loading more results…"; },
3415 formatSearching: function () { return "Searching…"; },
3416 minimumResultsForSearch: 0,
3638 minimumResultsForSearch: 0,
3417 minimumInputLength: 0,
3639 minimumInputLength: 0,
3418 maximumInputLength: null,
3640 maximumInputLength: null,
3419 maximumSelectionSize: 0,
3641 maximumSelectionSize: 0,
3420 id: function (e) { return e == undefined ? null : e.id; },
3642 id: function (e) { return e == undefined ? null : e.id; },
3643 text: function (e) {
3644 if (e && this.data && this.data.text) {
3645 if ($.isFunction(this.data.text)) {
3646 return this.data.text(e);
3647 } else {
3648 return e[this.data.text];
3649 }
3650 } else {
3651 return e.text;
3652 }
3653 },
3421 matcher: function(term, text) {
3654 matcher: function(term, text) {
3422 return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
3655 return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
3423 },
3656 },
@@ -3451,6 +3684,21 b' the specific language governing permissi'
3451 }
3684 }
3452 };
3685 };
3453
3686
3687 $.fn.select2.locales = [];
3688
3689 $.fn.select2.locales['en'] = {
3690 formatMatches: function (matches) { if (matches === 1) { return "One result is available, press enter to select it."; } return matches + " results are available, use up and down arrow keys to navigate."; },
3691 formatNoMatches: function () { return "No matches found"; },
3692 formatAjaxError: function (jqXHR, textStatus, errorThrown) { return "Loading failed"; },
3693 formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1 ? "" : "s"); },
3694 formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1 ? "" : "s"); },
3695 formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3696 formatLoadMore: function (pageNumber) { return "Loading more results…"; },
3697 formatSearching: function () { return "Searching…"; }
3698 };
3699
3700 $.extend($.fn.select2.defaults, $.fn.select2.locales['en']);
3701
3454 $.fn.select2.ajaxDefaults = {
3702 $.fn.select2.ajaxDefaults = {
3455 transport: $.ajax,
3703 transport: $.ajax,
3456 params: {
3704 params: {
General Comments 0
You need to be logged in to leave comments. Login now