expose plugin defaults to make configuration easier. fixes #199
This commit is contained in:
parent
5d2bcd4007
commit
0c4888c6ef
56
select2.js
56
select2.js
@ -547,16 +547,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts = $.extend({}, {
|
opts = $.extend({}, {
|
||||||
containerCss: {},
|
|
||||||
dropdownCss: {},
|
|
||||||
containerCssClass: "",
|
|
||||||
dropdownCssClass: "",
|
|
||||||
populateResults: function(container, results, query) {
|
populateResults: function(container, results, query) {
|
||||||
var uidToData={}, populate, markup=[], uid, data, result, children, formatted, id=this.opts.id;
|
var populate, data, result, children, id=this.opts.id;
|
||||||
|
|
||||||
populate=function(results, container, depth) {
|
populate=function(results, container, depth) {
|
||||||
|
|
||||||
var i, l, uid, result, selectable, compound, node, label, innerContainer;
|
var i, l, result, selectable, compound, node, label, innerContainer, formatted;
|
||||||
for (i = 0, l = results.length; i < l; i = i + 1) {
|
for (i = 0, l = results.length; i < l; i = i + 1) {
|
||||||
|
|
||||||
result=results[i];
|
result=results[i];
|
||||||
@ -572,7 +568,7 @@
|
|||||||
label=$("<div></div>");
|
label=$("<div></div>");
|
||||||
label.addClass("select2-result-label");
|
label.addClass("select2-result-label");
|
||||||
|
|
||||||
var formatted=opts.formatResult(result, label, query);
|
formatted=opts.formatResult(result, label, query);
|
||||||
if (formatted!==undefined) {
|
if (formatted!==undefined) {
|
||||||
label.html(formatted);
|
label.html(formatted);
|
||||||
}
|
}
|
||||||
@ -589,29 +585,12 @@
|
|||||||
|
|
||||||
node.data("select2-data", result);
|
node.data("select2-data", result);
|
||||||
container.append(node);
|
container.append(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
populate(results, container, 0);
|
populate(results, container, 0);
|
||||||
},
|
|
||||||
formatResult: function(result, container, query) {
|
|
||||||
var markup=[];
|
|
||||||
markMatch(result.text, query.term, markup);
|
|
||||||
return markup.join("");
|
|
||||||
},
|
|
||||||
formatSelection: function (data, container) {
|
|
||||||
return data.text;
|
|
||||||
},
|
|
||||||
formatNoMatches: function () { return "No matches found"; },
|
|
||||||
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
|
|
||||||
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
|
|
||||||
minimumResultsForSearch: 0,
|
|
||||||
minimumInputLength: 0,
|
|
||||||
id: function (e) { return e.id; },
|
|
||||||
matcher: function(term, text) {
|
|
||||||
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0;
|
|
||||||
}
|
}
|
||||||
}, opts);
|
}, $.fn.select2.defaults, opts);
|
||||||
|
|
||||||
if (typeof(opts.id) !== "function") {
|
if (typeof(opts.id) !== "function") {
|
||||||
idKey = opts.id;
|
idKey = opts.id;
|
||||||
@ -1970,6 +1949,31 @@
|
|||||||
return (value === undefined) ? this : value;
|
return (value === undefined) ? this : value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// plugin defaults, accessible to users
|
||||||
|
$.fn.select2.defaults = {
|
||||||
|
containerCss: {},
|
||||||
|
dropdownCss: {},
|
||||||
|
containerCssClass: "",
|
||||||
|
dropdownCssClass: "",
|
||||||
|
formatResult: function(result, container, query) {
|
||||||
|
var markup=[];
|
||||||
|
markMatch(result.text, query.term, markup);
|
||||||
|
return markup.join("");
|
||||||
|
},
|
||||||
|
formatSelection: function (data, container) {
|
||||||
|
return data.text;
|
||||||
|
},
|
||||||
|
formatNoMatches: function () { return "No matches found"; },
|
||||||
|
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
|
||||||
|
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
|
||||||
|
minimumResultsForSearch: 0,
|
||||||
|
minimumInputLength: 0,
|
||||||
|
id: function (e) { return e.id; },
|
||||||
|
matcher: function(term, text) {
|
||||||
|
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// exports
|
// exports
|
||||||
window.Select2 = {
|
window.Select2 = {
|
||||||
query: {
|
query: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user