bind/delegate -> on. #1260
This commit is contained in:
parent
92617ec54e
commit
11c08cab12
81
select2.js
81
select2.js
@ -157,12 +157,12 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
function installKeyUpChangeEvent(element) {
|
function installKeyUpChangeEvent(element) {
|
||||||
var key="keyup-change-value";
|
var key="keyup-change-value";
|
||||||
element.bind("keydown", function () {
|
element.on("keydown", function () {
|
||||||
if ($.data(element, key) === undefined) {
|
if ($.data(element, key) === undefined) {
|
||||||
$.data(element, key, element.val());
|
$.data(element, key, element.val());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
element.bind("keyup", function () {
|
element.on("keyup", function () {
|
||||||
var val= $.data(element, key);
|
var val= $.data(element, key);
|
||||||
if (val !== undefined && element.val() !== val) {
|
if (val !== undefined && element.val() !== val) {
|
||||||
$.removeData(element, key);
|
$.removeData(element, key);
|
||||||
@ -171,7 +171,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$document.bind("mousemove", function (e) {
|
$document.on("mousemove", function (e) {
|
||||||
lastMousePosition = {x: e.pageX, y: e.pageY};
|
lastMousePosition = {x: e.pageX, y: e.pageY};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
* the elements under the pointer are scrolled.
|
* the elements under the pointer are scrolled.
|
||||||
*/
|
*/
|
||||||
function installFilteredMouseMove(element) {
|
function installFilteredMouseMove(element) {
|
||||||
element.bind("mousemove", function (e) {
|
element.on("mousemove", function (e) {
|
||||||
var lastpos = lastMousePosition;
|
var lastpos = lastMousePosition;
|
||||||
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
||||||
$(e.target).trigger("mousemove-filtered", e);
|
$(e.target).trigger("mousemove-filtered", e);
|
||||||
@ -227,7 +227,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
function installDebouncedScroll(threshold, element) {
|
function installDebouncedScroll(threshold, element) {
|
||||||
var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
|
var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
|
||||||
element.bind("scroll", function (e) {
|
element.on("scroll", function (e) {
|
||||||
if (indexOf(e.target, element.get()) >= 0) notify(e);
|
if (indexOf(e.target, element.get()) >= 0) notify(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -657,7 +657,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// swap container for the element
|
// swap container for the element
|
||||||
this.opts.element
|
this.opts.element
|
||||||
.data("select2", this)
|
.data("select2", this)
|
||||||
.bind("focus.select2", function() { $(this).select2("focus"); })
|
|
||||||
.attr("tabindex", "-1")
|
.attr("tabindex", "-1")
|
||||||
.before(this.container);
|
.before(this.container);
|
||||||
this.container.data("select2", this);
|
this.container.data("select2", this);
|
||||||
@ -676,14 +675,14 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.initContainer();
|
this.initContainer();
|
||||||
|
|
||||||
installFilteredMouseMove(this.results);
|
installFilteredMouseMove(this.results);
|
||||||
this.dropdown.delegate(resultsSelector, "mousemove-filtered touchstart touchmove touchend", this.bind(this.highlightUnderEvent));
|
this.dropdown.on("mousemove-filtered touchstart touchmove touchend", resultsSelector, this.bind(this.highlightUnderEvent));
|
||||||
|
|
||||||
installDebouncedScroll(80, this.results);
|
installDebouncedScroll(80, this.results);
|
||||||
this.dropdown.delegate(resultsSelector, "scroll-debounced", this.bind(this.loadMoreIfNeeded));
|
this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
|
||||||
|
|
||||||
// do not propagate change event from the search field out of the component
|
// do not propagate change event from the search field out of the component
|
||||||
$(this.container).delegate(".select2-input", "change", function(e) {e.stopPropagation();});
|
$(this.container).on("change", ".select2-input", function(e) {e.stopPropagation();});
|
||||||
$(this.dropdown).delegate(".select2-input", "change", function(e) {e.stopPropagation();});
|
$(this.dropdown).on("change", ".select2-input", function(e) {e.stopPropagation();});
|
||||||
|
|
||||||
// if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
|
// if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
|
||||||
if ($.fn.mousewheel) {
|
if ($.fn.mousewheel) {
|
||||||
@ -700,11 +699,11 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
|
|
||||||
installKeyUpChangeEvent(search);
|
installKeyUpChangeEvent(search);
|
||||||
search.bind("keyup-change input paste", this.bind(this.updateResults));
|
search.on("keyup-change input paste", this.bind(this.updateResults));
|
||||||
search.bind("focus", function () { search.addClass("select2-focused"); });
|
search.on("focus", function () { search.addClass("select2-focused"); });
|
||||||
search.bind("blur", function () { search.removeClass("select2-focused");});
|
search.on("blur", function () { search.removeClass("select2-focused");});
|
||||||
|
|
||||||
this.dropdown.delegate(resultsSelector, "mouseup", this.bind(function (e) {
|
this.dropdown.on("mouseup", resultsSelector, this.bind(function (e) {
|
||||||
if ($(e.target).closest(".select2-result-selectable").length > 0) {
|
if ($(e.target).closest(".select2-result-selectable").length > 0) {
|
||||||
this.highlightUnderEvent(e);
|
this.highlightUnderEvent(e);
|
||||||
this.selectHighlighted(e);
|
this.selectHighlighted(e);
|
||||||
@ -714,7 +713,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// trap all mouse events from leaving the dropdown. sometimes there may be a modal that is listening
|
// trap all mouse events from leaving the dropdown. sometimes there may be a modal that is listening
|
||||||
// for mouse events outside of itself so it can close itself. since the dropdown is now outside the select2's
|
// for mouse events outside of itself so it can close itself. since the dropdown is now outside the select2's
|
||||||
// dom it will trigger the popup close, which is not what we want
|
// dom it will trigger the popup close, which is not what we want
|
||||||
this.dropdown.bind("click mouseup mousedown", function (e) { e.stopPropagation(); });
|
this.dropdown.on("click mouseup mousedown", function (e) { e.stopPropagation(); });
|
||||||
|
|
||||||
if ($.isFunction(this.opts.initSelection)) {
|
if ($.isFunction(this.opts.initSelection)) {
|
||||||
// initialize selection based on the current value of the source element
|
// initialize selection based on the current value of the source element
|
||||||
@ -754,7 +753,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
select2.opts.element
|
select2.opts.element
|
||||||
.removeClass("select2-offscreen")
|
.removeClass("select2-offscreen")
|
||||||
.removeData("select2")
|
.removeData("select2")
|
||||||
.unbind(".select2")
|
.off(".select2")
|
||||||
.attr({"tabindex": this.elementTabIndex})
|
.attr({"tabindex": this.elementTabIndex})
|
||||||
.prop("autofocus", this.autofocus||false)
|
.prop("autofocus", this.autofocus||false)
|
||||||
.show();
|
.show();
|
||||||
@ -951,7 +950,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
monitorSource: function () {
|
monitorSource: function () {
|
||||||
var el = this.opts.element, sync;
|
var el = this.opts.element, sync;
|
||||||
|
|
||||||
el.bind("change.select2", this.bind(function (e) {
|
el.on("change.select2", this.bind(function (e) {
|
||||||
if (this.opts.element.data("select2-change-triggered") !== true) {
|
if (this.opts.element.data("select2-change-triggered") !== true) {
|
||||||
this.initSelection();
|
this.initSelection();
|
||||||
}
|
}
|
||||||
@ -980,7 +979,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
});
|
});
|
||||||
|
|
||||||
// mozilla and IE
|
// mozilla and IE
|
||||||
el.bind("propertychange.select2 DOMAttrModified.select2", sync);
|
el.on("propertychange.select2 DOMAttrModified.select2", sync);
|
||||||
|
|
||||||
|
|
||||||
// hold onto a reference of the callback to work around a chromium bug
|
// hold onto a reference of the callback to work around a chromium bug
|
||||||
@ -1215,7 +1214,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
|
mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
|
||||||
mask.hide();
|
mask.hide();
|
||||||
mask.appendTo(this.body());
|
mask.appendTo(this.body());
|
||||||
mask.bind("mousedown touchstart", function (e) {
|
mask.on("mousedown touchstart", function (e) {
|
||||||
var dropdown = $("#select2-drop"), self;
|
var dropdown = $("#select2-drop"), self;
|
||||||
if (dropdown.length > 0) {
|
if (dropdown.length > 0) {
|
||||||
self=dropdown.data("select2");
|
self=dropdown.data("select2");
|
||||||
@ -1251,7 +1250,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// the position of the dropdown to be updated as well so it does not come unglued from the container
|
// the position of the dropdown to be updated as well so it does not come unglued from the container
|
||||||
var that = this;
|
var that = this;
|
||||||
this.container.parents().add(window).each(function () {
|
this.container.parents().add(window).each(function () {
|
||||||
$(this).bind(resize+" "+scroll+" "+orient, function (e) {
|
$(this).on(resize+" "+scroll+" "+orient, function (e) {
|
||||||
$("#select2-drop-mask").css(_makeMaskCss());
|
$("#select2-drop-mask").css(_makeMaskCss());
|
||||||
that.positionDropdown();
|
that.positionDropdown();
|
||||||
});
|
});
|
||||||
@ -1275,7 +1274,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
orient = "orientationchange."+cid;
|
orient = "orientationchange."+cid;
|
||||||
|
|
||||||
// unbind event listeners
|
// unbind event listeners
|
||||||
this.container.parents().add(window).each(function () { $(this).unbind(scroll).unbind(resize).unbind(orient); });
|
this.container.parents().add(window).each(function () { $(this).off(scroll).off(resize).off(orient); });
|
||||||
|
|
||||||
this.clearDropdownAlignmentPreference();
|
this.clearDropdownAlignmentPreference();
|
||||||
|
|
||||||
@ -1790,7 +1789,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
this.focusser.attr("tabindex", this.elementTabIndex);
|
this.focusser.attr("tabindex", this.elementTabIndex);
|
||||||
|
|
||||||
this.search.bind("keydown", this.bind(function (e) {
|
this.search.on("keydown", this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
|
|
||||||
if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
|
if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
|
||||||
@ -1819,7 +1818,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.search.bind("blur", this.bind(function(e) {
|
this.search.on("blur", this.bind(function(e) {
|
||||||
// a workaround for chrome to keep the search field focussed when the scroll bar is used to scroll the dropdown.
|
// a workaround for chrome to keep the search field focussed when the scroll bar is used to scroll the dropdown.
|
||||||
// without this the search field loses focus which is annoying
|
// without this the search field loses focus which is annoying
|
||||||
if (document.activeElement === this.body().get(0)) {
|
if (document.activeElement === this.body().get(0)) {
|
||||||
@ -1829,7 +1828,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.focusser.bind("keydown", this.bind(function (e) {
|
this.focusser.on("keydown", this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
|
|
||||||
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
|
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
|
||||||
@ -1859,13 +1858,13 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
|
|
||||||
installKeyUpChangeEvent(this.focusser);
|
installKeyUpChangeEvent(this.focusser);
|
||||||
this.focusser.bind("keyup-change input", this.bind(function(e) {
|
this.focusser.on("keyup-change input", this.bind(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (this.opened()) return;
|
if (this.opened()) return;
|
||||||
this.open();
|
this.open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
selection.delegate("abbr", "mousedown", this.bind(function (e) {
|
selection.on("mousedown", "abbr", this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
this.clear();
|
this.clear();
|
||||||
killEventImmediately(e);
|
killEventImmediately(e);
|
||||||
@ -1873,7 +1872,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.selection.focus();
|
this.selection.focus();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
selection.bind("mousedown", this.bind(function (e) {
|
selection.on("mousedown", this.bind(function (e) {
|
||||||
|
|
||||||
if (!this.container.hasClass("select2-container-active")) {
|
if (!this.container.hasClass("select2-container-active")) {
|
||||||
this.opts.element.trigger($.Event("select2-focus"));
|
this.opts.element.trigger($.Event("select2-focus"));
|
||||||
@ -1888,24 +1887,24 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
killEvent(e);
|
killEvent(e);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
dropdown.bind("mousedown", this.bind(function() { this.search.focus(); }));
|
dropdown.on("mousedown", this.bind(function() { this.search.focus(); }));
|
||||||
|
|
||||||
selection.bind("focus", this.bind(function(e) {
|
selection.on("focus", this.bind(function(e) {
|
||||||
killEvent(e);
|
killEvent(e);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.focusser.bind("focus", this.bind(function(){
|
this.focusser.on("focus", this.bind(function(){
|
||||||
if (!this.container.hasClass("select2-container-active")) {
|
if (!this.container.hasClass("select2-container-active")) {
|
||||||
this.opts.element.trigger($.Event("select2-focus"));
|
this.opts.element.trigger($.Event("select2-focus"));
|
||||||
}
|
}
|
||||||
this.container.addClass("select2-container-active");
|
this.container.addClass("select2-container-active");
|
||||||
})).bind("blur", this.bind(function() {
|
})).on("blur", this.bind(function() {
|
||||||
if (!this.opened()) {
|
if (!this.opened()) {
|
||||||
this.container.removeClass("select2-container-active");
|
this.container.removeClass("select2-container-active");
|
||||||
this.opts.element.trigger($.Event("select2-blur"));
|
this.opts.element.trigger($.Event("select2-blur"));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
this.search.bind("focus", this.bind(function(){
|
this.search.on("focus", this.bind(function(){
|
||||||
if (!this.container.hasClass("select2-container-active")) {
|
if (!this.container.hasClass("select2-container-active")) {
|
||||||
this.opts.element.trigger($.Event("select2-focus"));
|
this.opts.element.trigger($.Event("select2-focus"));
|
||||||
}
|
}
|
||||||
@ -2302,7 +2301,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
$("label[for='" + this.opts.element.attr("id") + "']")
|
$("label[for='" + this.opts.element.attr("id") + "']")
|
||||||
.attr('for', this.search.attr('id'));
|
.attr('for', this.search.attr('id'));
|
||||||
|
|
||||||
this.search.bind("input paste", this.bind(function() {
|
this.search.on("input paste", this.bind(function() {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
if (!this.opened()) {
|
if (!this.opened()) {
|
||||||
this.open();
|
this.open();
|
||||||
@ -2312,7 +2311,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.search.attr("tabindex", this.elementTabIndex);
|
this.search.attr("tabindex", this.elementTabIndex);
|
||||||
|
|
||||||
this.keydowns = 0;
|
this.keydowns = 0;
|
||||||
this.search.bind("keydown", this.bind(function (e) {
|
this.search.on("keydown", this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
|
|
||||||
++this.keydowns;
|
++this.keydowns;
|
||||||
@ -2406,13 +2405,13 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.search.bind("keyup", this.bind(function (e) {
|
this.search.on("keyup", this.bind(function (e) {
|
||||||
this.keydowns = 0;
|
this.keydowns = 0;
|
||||||
this.resizeSearch();
|
this.resizeSearch();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.search.bind("blur", this.bind(function(e) {
|
this.search.on("blur", this.bind(function(e) {
|
||||||
this.container.removeClass("select2-container-active");
|
this.container.removeClass("select2-container-active");
|
||||||
this.search.removeClass("select2-focused");
|
this.search.removeClass("select2-focused");
|
||||||
this.selectChoice(null);
|
this.selectChoice(null);
|
||||||
@ -2421,7 +2420,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.opts.element.trigger($.Event("select2-blur"));
|
this.opts.element.trigger($.Event("select2-blur"));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.container.delegate(selector, "mousedown", this.bind(function (e) {
|
this.container.on("mousedown", selector, this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
if ($(e.target).closest(".select2-search-choice").length > 0) {
|
if ($(e.target).closest(".select2-search-choice").length > 0) {
|
||||||
// clicked inside a select2 search choice, do not open
|
// clicked inside a select2 search choice, do not open
|
||||||
@ -2437,7 +2436,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.container.delegate(selector, "focus", this.bind(function () {
|
this.container.on("focus", selector, this.bind(function () {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
if (!this.container.hasClass("select2-container-active")) {
|
if (!this.container.hasClass("select2-container-active")) {
|
||||||
this.opts.element.trigger($.Event("select2-focus"));
|
this.opts.element.trigger($.Event("select2-focus"));
|
||||||
@ -2638,8 +2637,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
if(enableChoice){
|
if(enableChoice){
|
||||||
choice.find(".select2-search-choice-close")
|
choice.find(".select2-search-choice-close")
|
||||||
.bind("mousedown", killEvent)
|
.on("mousedown", killEvent)
|
||||||
.bind("click dblclick", this.bind(function (e) {
|
.on("click dblclick", this.bind(function (e) {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
|
|
||||||
$(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
|
$(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
|
||||||
@ -2649,7 +2648,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.focusSearch();
|
this.focusSearch();
|
||||||
})).dequeue();
|
})).dequeue();
|
||||||
killEvent(e);
|
killEvent(e);
|
||||||
})).bind("focus", this.bind(function () {
|
})).on("focus", this.bind(function () {
|
||||||
if (!this.isInterfaceEnabled()) return;
|
if (!this.isInterfaceEnabled()) return;
|
||||||
this.container.addClass("select2-container-active");
|
this.container.addClass("select2-container-active");
|
||||||
this.dropdown.addClass("select2-drop-active");
|
this.dropdown.addClass("select2-drop-active");
|
||||||
|
Loading…
Reference in New Issue
Block a user