|
547 | 547 | } |
548 | 548 |
|
549 | 549 | opts = $.extend({}, { |
550 | | - containerCss: {}, |
551 | | - dropdownCss: {}, |
552 | | - containerCssClass: "", |
553 | | - dropdownCssClass: "", |
554 | 550 | 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; |
556 | 552 |
|
557 | 553 | populate=function(results, container, depth) { |
558 | 554 |
|
559 | | - var i, l, uid, result, selectable, compound, node, label, innerContainer; |
| 555 | + var i, l, result, selectable, compound, node, label, innerContainer, formatted; |
560 | 556 | for (i = 0, l = results.length; i < l; i = i + 1) { |
561 | 557 |
|
562 | 558 | result=results[i]; |
|
572 | 568 | label=$("<div></div>"); |
573 | 569 | label.addClass("select2-result-label"); |
574 | 570 |
|
575 | | - var formatted=opts.formatResult(result, label, query); |
| 571 | + formatted=opts.formatResult(result, label, query); |
576 | 572 | if (formatted!==undefined) { |
577 | 573 | label.html(formatted); |
578 | 574 | } |
|
589 | 585 |
|
590 | 586 | node.data("select2-data", result); |
591 | 587 | container.append(node); |
592 | | - } |
| 588 | + } |
593 | 589 | }; |
594 | 590 |
|
595 | 591 | 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; |
613 | 592 | } |
614 | | - }, opts); |
| 593 | + }, $.fn.select2.defaults, opts); |
615 | 594 |
|
616 | 595 | if (typeof(opts.id) !== "function") { |
617 | 596 | idKey = opts.id; |
|
1970 | 1949 | return (value === undefined) ? this : value; |
1971 | 1950 | }; |
1972 | 1951 |
|
| 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 | + |
1973 | 1977 | // exports |
1974 | 1978 | window.Select2 = { |
1975 | 1979 | query: { |
|
0 commit comments