Skip to content

Commit 0c4888c

Browse files
committed
expose plugin defaults to make configuration easier. fixes select2#199
1 parent 5d2bcd4 commit 0c4888c

1 file changed

Lines changed: 30 additions & 26 deletions

File tree

select2.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,12 @@
547547
}
548548

549549
opts = $.extend({}, {
550-
containerCss: {},
551-
dropdownCss: {},
552-
containerCssClass: "",
553-
dropdownCssClass: "",
554550
populateResults: function(container, results, query) {
555-
var uidToData={}, populate, markup=[], uid, data, result, children, formatted, id=this.opts.id;
551+
var populate, data, result, children, id=this.opts.id;
556552

557553
populate=function(results, container, depth) {
558554

559-
var i, l, uid, result, selectable, compound, node, label, innerContainer;
555+
var i, l, result, selectable, compound, node, label, innerContainer, formatted;
560556
for (i = 0, l = results.length; i < l; i = i + 1) {
561557

562558
result=results[i];
@@ -572,7 +568,7 @@
572568
label=$("<div></div>");
573569
label.addClass("select2-result-label");
574570

575-
var formatted=opts.formatResult(result, label, query);
571+
formatted=opts.formatResult(result, label, query);
576572
if (formatted!==undefined) {
577573
label.html(formatted);
578574
}
@@ -589,29 +585,12 @@
589585

590586
node.data("select2-data", result);
591587
container.append(node);
592-
}
588+
}
593589
};
594590

595591
populate(results, container, 0);
596-
},
597-
formatResult: function(result, container, query) {
598-
var markup=[];
599-
markMatch(result.text, query.term, markup);
600-
return markup.join("");
601-
},
602-
formatSelection: function (data, container) {
603-
return data.text;
604-
},
605-
formatNoMatches: function () { return "No matches found"; },
606-
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
607-
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
608-
minimumResultsForSearch: 0,
609-
minimumInputLength: 0,
610-
id: function (e) { return e.id; },
611-
matcher: function(term, text) {
612-
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0;
613592
}
614-
}, opts);
593+
}, $.fn.select2.defaults, opts);
615594

616595
if (typeof(opts.id) !== "function") {
617596
idKey = opts.id;
@@ -1970,6 +1949,31 @@
19701949
return (value === undefined) ? this : value;
19711950
};
19721951

1952+
// plugin defaults, accessible to users
1953+
$.fn.select2.defaults = {
1954+
containerCss: {},
1955+
dropdownCss: {},
1956+
containerCssClass: "",
1957+
dropdownCssClass: "",
1958+
formatResult: function(result, container, query) {
1959+
var markup=[];
1960+
markMatch(result.text, query.term, markup);
1961+
return markup.join("");
1962+
},
1963+
formatSelection: function (data, container) {
1964+
return data.text;
1965+
},
1966+
formatNoMatches: function () { return "No matches found"; },
1967+
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
1968+
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
1969+
minimumResultsForSearch: 0,
1970+
minimumInputLength: 0,
1971+
id: function (e) { return e.id; },
1972+
matcher: function(term, text) {
1973+
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0;
1974+
}
1975+
};
1976+
19731977
// exports
19741978
window.Select2 = {
19751979
query: {

0 commit comments

Comments
 (0)