From 7baa3b9e93690b7dacad8fbb22f71b8a3940e04d Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Mon, 27 Aug 2012 09:48:02 -0700 Subject: [PATCH] make escapeMarkup configurable. closes #355 --- select2.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/select2.js b/select2.js index b9e1b5ff..ff6b7998 100755 --- a/select2.js +++ b/select2.js @@ -702,7 +702,7 @@ formatted=opts.formatResult(result, label, query); if (formatted!==undefined) { - label.html(self.escapeMarkup(formatted)); + label.html(self.opts.escapeMarkup(formatted)); } node.append(label); @@ -801,15 +801,6 @@ return opts; }, - escapeMarkup: function (markup) { - if (this.opts.doEscapeMarkup) { - if (markup && typeof(markup) === "string") { - return markup.replace(/&/g, "&"); - } - } - return markup; - }, - /** * Monitor the original element for changes and update select2 accordingly */ @@ -1181,7 +1172,7 @@ } function render(html) { - results.html(self.escapeMarkup(html)); + results.html(self.opts.escapeMarkup(html)); postRender(); } @@ -1244,7 +1235,7 @@ self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null}); if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) { - results.append("
  • " + self.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "
  • "); + results.append("
  • " + self.opts.escapeMarkup(opts.formatLoadMore(this.resultsPage)) + "
  • "); window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10); } @@ -1628,7 +1619,7 @@ // check for a first blank option if attached to a select if (this.select && this.select.find("option:first").text() !== "") return; - this.selection.find("span").html(this.escapeMarkup(placeholder)); + this.selection.find("span").html(this.opts.escapeMarkup(placeholder)); this.selection.addClass("select2-default"); @@ -1687,7 +1678,7 @@ container.empty(); formatted=this.opts.formatSelection(data, container); if (formatted !== undefined) { - container.append(this.escapeMarkup(formatted)); + container.append(this.opts.escapeMarkup(formatted)); } this.selection.removeClass("select2-default"); @@ -2064,7 +2055,7 @@ formatted; formatted=this.opts.formatSelection(data, choice); - choice.find("div").replaceWith("
    "+this.escapeMarkup(formatted)+"
    "); + choice.find("div").replaceWith("
    "+this.opts.escapeMarkup(formatted)+"
    "); choice.find(".select2-search-choice-close") .bind("mousedown", killEvent) .bind("click dblclick", this.bind(function (e) { @@ -2339,7 +2330,6 @@ closeOnSelect: true, openOnEnter: true, containerCss: {}, - doEscapeMarkup: true, dropdownCss: {}, containerCssClass: "", dropdownCssClass: "", @@ -2356,7 +2346,7 @@ formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; }, formatSelectionTooBig: function (limit) { return "You can only select " + limit + " items"; }, formatLoadMore: function (pageNumber) { return "Loading more results..."; }, - formatSearching: function () { return "Searching..."; }, + formatSearching: function () { return "Searching..."; }, minimumResultsForSearch: 0, minimumInputLength: 0, maximumSelectionSize: 0, @@ -2366,7 +2356,13 @@ }, separator: ",", tokenSeparators: [], - tokenizer: defaultTokenizer + tokenizer: defaultTokenizer, + escapeMarkup: function (markup) { + if (markup && typeof(markup) === "string") { + return markup.replace(/&/g, "&"); + } + return markup; + } }; // exports