Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #503 from todd-givainc/master

Feature: Locked Items
  • Loading branch information...
commit 4a363c4b3018a0508064e4eaf81b167ddfabe760 2 parents b3b75a8 + 1d4ea63
@ivaynberg ivaynberg authored
Showing with 33 additions and 21 deletions.
  1. +4 −0 select2.css
  2. +29 −21 select2.js
View
4 select2.css
@@ -410,6 +410,10 @@ disabled look for already selected choices in the results dropdown
background-image: linear-gradient(top, #eeeeee 1%, #ffffff 15%);
}
+.select2-locked {
+ padding: 3px 5px 3px 5px !important;
+}
+
.select2-container-multi .select2-choices {
min-height: 26px;
}
View
50 select2.js
@@ -1838,7 +1838,7 @@ the specific language governing permissions and limitations under the Apache Lic
return;
}
- choices = selection.find(".select2-search-choice");
+ choices = selection.find(".select2-search-choice:not(.select2-locked)");
if (choices.length > 0) {
choices.last().addClass("select2-search-choice-focus");
}
@@ -2069,38 +2069,46 @@ the specific language governing permissions and limitations under the Apache Lic
this.focusSearch();
},
- // multi
addSelectedChoice: function (data) {
- var choice=$(
+ var enableChoice = !data.locked,
+ enabledItem = $(
"<li class='select2-search-choice'>" +
" <div></div>" +
- " <a href='javascript:void(0)' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
+ " <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
"</li>"),
+ disabledItem = $(
+ "<li class='select2-search-choice select2-locked'>" +
+ "<div></div>" +
+ "</li>");
+ var choice = enableChoice ? enabledItem : disabledItem,
id = this.id(data),
val = this.getVal(),
formatted;
-
+
formatted=this.opts.formatSelection(data, choice.find("div"));
if (formatted != undefined) {
choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>");
}
- choice.find(".select2-search-choice-close")
- .bind("mousedown", killEvent)
- .bind("click dblclick", this.bind(function (e) {
- if (!this.enabled) return;
- $(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
- this.unselect($(e.target));
- this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
- this.close();
- this.focusSearch();
- })).dequeue();
- killEvent(e);
- })).bind("focus", this.bind(function () {
- if (!this.enabled) return;
- this.container.addClass("select2-container-active");
- this.dropdown.addClass("select2-drop-active");
- }));
+ if(enableChoice){
+ choice.find(".select2-search-choice-close")
+ .bind("mousedown", killEvent)
+ .bind("click dblclick", this.bind(function (e) {
+ if (!this.enabled) return;
+
+ $(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
+ this.unselect($(e.target));
+ this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
+ this.close();
+ this.focusSearch();
+ })).dequeue();
+ killEvent(e);
+ })).bind("focus", this.bind(function () {
+ if (!this.enabled) return;
+ this.container.addClass("select2-container-active");
+ this.dropdown.addClass("select2-drop-active");
+ }));
+ }
choice.data("select2-data", data);
choice.insertBefore(this.searchContainer);
Please sign in to comment.
Something went wrong with that request. Please try again.