Skip to content

Commit 7baa3b9

Browse files
committed
make escapeMarkup configurable. closes select2#355
1 parent 55cc11f commit 7baa3b9

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

select2.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@
702702

703703
formatted=opts.formatResult(result, label, query);
704704
if (formatted!==undefined) {
705-
label.html(self.escapeMarkup(formatted));
705+
label.html(self.opts.escapeMarkup(formatted));
706706
}
707707

708708
node.append(label);
@@ -801,15 +801,6 @@
801801
return opts;
802802
},
803803

804-
escapeMarkup: function (markup) {
805-
if (this.opts.doEscapeMarkup) {
806-
if (markup && typeof(markup) === "string") {
807-
return markup.replace(/&/g, "&");
808-
}
809-
}
810-
return markup;
811-
},
812-
813804
/**
814805
* Monitor the original element for changes and update select2 accordingly
815806
*/
@@ -1181,7 +1172,7 @@
11811172
}
11821173

11831174
function render(html) {
1184-
results.html(self.escapeMarkup(html));
1175+
results.html(self.opts.escapeMarkup(html));
11851176
postRender();
11861177
}
11871178

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

12461237
if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) {
1247-
results.append("<li class='select2-more-results'>" + self.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "</li>");
1238+
results.append("<li class='select2-more-results'>" + self.opts.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "</li>");
12481239
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
12491240
}
12501241

@@ -1628,7 +1619,7 @@
16281619
// check for a first blank option if attached to a select
16291620
if (this.select && this.select.find("option:first").text() !== "") return;
16301621

1631-
this.selection.find("span").html(this.escapeMarkup(placeholder));
1622+
this.selection.find("span").html(this.opts.escapeMarkup(placeholder));
16321623

16331624
this.selection.addClass("select2-default");
16341625

@@ -1687,7 +1678,7 @@
16871678
container.empty();
16881679
formatted=this.opts.formatSelection(data, container);
16891680
if (formatted !== undefined) {
1690-
container.append(this.escapeMarkup(formatted));
1681+
container.append(this.opts.escapeMarkup(formatted));
16911682
}
16921683

16931684
this.selection.removeClass("select2-default");
@@ -2064,7 +2055,7 @@
20642055
formatted;
20652056

20662057
formatted=this.opts.formatSelection(data, choice);
2067-
choice.find("div").replaceWith("<div>"+this.escapeMarkup(formatted)+"</div>");
2058+
choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>");
20682059
choice.find(".select2-search-choice-close")
20692060
.bind("mousedown", killEvent)
20702061
.bind("click dblclick", this.bind(function (e) {
@@ -2339,7 +2330,6 @@
23392330
closeOnSelect: true,
23402331
openOnEnter: true,
23412332
containerCss: {},
2342-
doEscapeMarkup: true,
23432333
dropdownCss: {},
23442334
containerCssClass: "",
23452335
dropdownCssClass: "",
@@ -2356,7 +2346,7 @@
23562346
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
23572347
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " items"; },
23582348
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
2359-
formatSearching: function () { return "Searching..."; },
2349+
formatSearching: function () { return "Searching..."; },
23602350
minimumResultsForSearch: 0,
23612351
minimumInputLength: 0,
23622352
maximumSelectionSize: 0,
@@ -2366,7 +2356,13 @@
23662356
},
23672357
separator: ",",
23682358
tokenSeparators: [],
2369-
tokenizer: defaultTokenizer
2359+
tokenizer: defaultTokenizer,
2360+
escapeMarkup: function (markup) {
2361+
if (markup && typeof(markup) === "string") {
2362+
return markup.replace(/&/g, "&amp;");
2363+
}
2364+
return markup;
2365+
}
23702366
};
23712367

23722368
// exports

0 commit comments

Comments
 (0)