1
0
mirror of synced 2024-11-23 05:26:10 +03:00

Merge pull request #1320 from jamesramsay/selected-css-class

Added support for css class for selected elements
This commit is contained in:
Igor Vaynberg 2013-05-16 21:50:35 -07:00
commit 38f6b2bd71

View File

@ -2087,7 +2087,7 @@ the specific language governing permissions and limitations under the Apache Lic
// single // single
updateSelection: function (data) { updateSelection: function (data) {
var container=this.selection.find("span"), formatted; var container=this.selection.find("span"), formatted, cssClass;
this.selection.data("select2-data", data); this.selection.data("select2-data", data);
@ -2096,6 +2096,10 @@ the specific language governing permissions and limitations under the Apache Lic
if (formatted !== undefined) { if (formatted !== undefined) {
container.append(this.opts.escapeMarkup(formatted)); container.append(this.opts.escapeMarkup(formatted));
} }
cssClass=this.opts.formatSelectionCssClass(data, container);
if (cssClass !== undefined) {
container.addClass(cssClass);
}
this.selection.removeClass("select2-default"); this.selection.removeClass("select2-default");
@ -2632,12 +2636,17 @@ the specific language governing permissions and limitations under the Apache Lic
var choice = enableChoice ? enabledItem : disabledItem, var choice = enableChoice ? enabledItem : disabledItem,
id = this.id(data), id = this.id(data),
val = this.getVal(), val = this.getVal(),
formatted; formatted,
cssClass;
formatted=this.opts.formatSelection(data, choice.find("div")); formatted=this.opts.formatSelection(data, choice.find("div"));
if (formatted != undefined) { if (formatted != undefined) {
choice.find("div").replaceWith("<div title='"+this.opts.escapeMarkup(formatted)+"'>"+this.opts.escapeMarkup(formatted)+"</div>"); choice.find("div").replaceWith("<div title='"+this.opts.escapeMarkup(formatted)+"'>"+this.opts.escapeMarkup(formatted)+"</div>");
} }
cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
if (cssClass != undefined) {
choice.addClass(cssClass);
}
if(enableChoice){ if(enableChoice){
choice.find(".select2-search-choice-close") choice.find(".select2-search-choice-close")
@ -2988,6 +2997,7 @@ the specific language governing permissions and limitations under the Apache Lic
return results; return results;
}, },
formatResultCssClass: function(data) {return undefined;}, formatResultCssClass: function(data) {return undefined;},
formatSelectionCssClass: function(data, container) {return undefined;},
formatNoMatches: function () { return "No matches found"; }, formatNoMatches: function () { return "No matches found"; },
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); }, formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); },
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); }, formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },