1
0
mirror of synced 2024-11-26 23:06:02 +03:00

Merge pull request #503 from todd-givainc/master

Feature: Locked Items
This commit is contained in:
Igor Vaynberg 2012-10-24 13:48:46 -07:00
commit 4a363c4b30
2 changed files with 33 additions and 21 deletions

View File

@ -410,6 +410,10 @@ disabled look for already selected choices in the results dropdown
background-image: linear-gradient(top, #eeeeee 1%, #ffffff 15%); background-image: linear-gradient(top, #eeeeee 1%, #ffffff 15%);
} }
.select2-locked {
padding: 3px 5px 3px 5px !important;
}
.select2-container-multi .select2-choices { .select2-container-multi .select2-choices {
min-height: 26px; min-height: 26px;
} }

View File

@ -1838,7 +1838,7 @@ the specific language governing permissions and limitations under the Apache Lic
return; return;
} }
choices = selection.find(".select2-search-choice"); choices = selection.find(".select2-search-choice:not(.select2-locked)");
if (choices.length > 0) { if (choices.length > 0) {
choices.last().addClass("select2-search-choice-focus"); choices.last().addClass("select2-search-choice-focus");
} }
@ -2069,13 +2069,18 @@ the specific language governing permissions and limitations under the Apache Lic
this.focusSearch(); this.focusSearch();
}, },
// multi
addSelectedChoice: function (data) { addSelectedChoice: function (data) {
var choice=$( var enableChoice = !data.locked,
enabledItem = $(
"<li class='select2-search-choice'>" + "<li class='select2-search-choice'>" +
" <div></div>" + " <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>"), "</li>"),
disabledItem = $(
"<li class='select2-search-choice select2-locked'>" +
"<div></div>" +
"</li>");
var choice = enableChoice ? enabledItem : disabledItem,
id = this.id(data), id = this.id(data),
val = this.getVal(), val = this.getVal(),
formatted; formatted;
@ -2084,6 +2089,8 @@ the specific language governing permissions and limitations under the Apache Lic
if (formatted != undefined) { if (formatted != undefined) {
choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>"); choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>");
} }
if(enableChoice){
choice.find(".select2-search-choice-close") choice.find(".select2-search-choice-close")
.bind("mousedown", killEvent) .bind("mousedown", killEvent)
.bind("click dblclick", this.bind(function (e) { .bind("click dblclick", this.bind(function (e) {
@ -2101,6 +2108,7 @@ the specific language governing permissions and limitations under the Apache Lic
this.container.addClass("select2-container-active"); this.container.addClass("select2-container-active");
this.dropdown.addClass("select2-drop-active"); this.dropdown.addClass("select2-drop-active");
})); }));
}
choice.data("select2-data", data); choice.data("select2-data", data);
choice.insertBefore(this.searchContainer); choice.insertBefore(this.searchContainer);