Skip to content

Commit 852a515

Browse files
slafsivaynberg
authored andcommitted
make escapeMarkup optional
Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
1 parent 3b55a65 commit 852a515

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

select2.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@
9292

9393
nextUid=(function() { var counter=1; return function() { return counter++; }; }());
9494

95-
function escapeMarkup(markup) {
96-
if (markup && typeof(markup) === "string") {
97-
return markup.replace(/&/g, "&amp;");
98-
} else {
99-
return markup;
100-
}
101-
}
102-
10395
function indexOf(value, array) {
10496
var i = 0, l = array.length, v;
10597

@@ -710,7 +702,7 @@
710702

711703
formatted=opts.formatResult(result, label, query);
712704
if (formatted!==undefined) {
713-
label.html(escapeMarkup(formatted));
705+
label.html(self.escapeMarkup(formatted));
714706
}
715707

716708
node.append(label);
@@ -809,6 +801,15 @@
809801
return opts;
810802
},
811803

804+
escapeMarkup: function (markup) {
805+
if (this.opts.doEscapeMarkup) {
806+
if (markup && typeof(markup) === "string") {
807+
return markup.replace(/&/g, "&amp;");
808+
}
809+
}
810+
return markup;
811+
},
812+
812813
/**
813814
* Monitor the original element for changes and update select2 accordingly
814815
*/
@@ -1180,7 +1181,7 @@
11801181
}
11811182

11821183
function render(html) {
1183-
results.html(escapeMarkup(html));
1184+
results.html(self.escapeMarkup(html));
11841185
postRender();
11851186
}
11861187

@@ -1243,7 +1244,7 @@
12431244
self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null});
12441245

12451246
if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) {
1246-
results.append("<li class='select2-more-results'>" + escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "</li>");
1247+
results.append("<li class='select2-more-results'>" + self.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "</li>");
12471248
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
12481249
}
12491250

@@ -1627,7 +1628,7 @@
16271628
// check for a first blank option if attached to a select
16281629
if (this.select && this.select.find("option:first").text() !== "") return;
16291630

1630-
this.selection.find("span").html(escapeMarkup(placeholder));
1631+
this.selection.find("span").html(this.escapeMarkup(placeholder));
16311632

16321633
this.selection.addClass("select2-default");
16331634

@@ -1686,7 +1687,7 @@
16861687
container.empty();
16871688
formatted=this.opts.formatSelection(data, container);
16881689
if (formatted !== undefined) {
1689-
container.append(escapeMarkup(formatted));
1690+
container.append(this.escapeMarkup(formatted));
16901691
}
16911692

16921693
this.selection.removeClass("select2-default");
@@ -2063,7 +2064,8 @@
20632064
formatted;
20642065

20652066
formatted=this.opts.formatSelection(data, choice);
2066-
choice.find("div").replaceWith("<div>"+escapeMarkup(formatted)+"</div>");
2067+
console.log(" 7 " + this.escapeMarkup);
2068+
choice.find("div").replaceWith("<div>"+this.escapeMarkup(formatted)+"</div>");
20672069
choice.find(".select2-search-choice-close")
20682070
.bind("mousedown", killEvent)
20692071
.bind("click dblclick", this.bind(function (e) {
@@ -2338,6 +2340,7 @@
23382340
closeOnSelect: true,
23392341
openOnEnter: true,
23402342
containerCss: {},
2343+
doEscapeMarkup: true,
23412344
dropdownCss: {},
23422345
containerCssClass: "",
23432346
dropdownCssClass: "",
@@ -2354,7 +2357,7 @@
23542357
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
23552358
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " items"; },
23562359
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
2357-
formatSearching: function () { return "Searching..."; },
2360+
formatSearching: function () { return "Searching..."; },
23582361
minimumResultsForSearch: 0,
23592362
minimumInputLength: 0,
23602363
maximumSelectionSize: 0,

0 commit comments

Comments
 (0)