Skip to content

Commit

Permalink
Fixed #2078: use jQuery's on if available instead of bind
Browse files Browse the repository at this point in the history
test with ?jquery=3.1.1.slim to check that "on" is used
test with ?jquery=1.6.1 to check that "bind" is used
  • Loading branch information
mbest committed Dec 6, 2016
1 parent 86dfaf3 commit 32bfa9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/lib/loadDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
var dependencies = {
// All specs should pass with or without jQuery+Modernizr being referenced
jquery: {
url: "http://code.jquery.com/jquery-1.11.3.js",
url: "http://code.jquery.com/jquery-3.1.1.js",
include: false,
versionString: "1.11.3"
versionString: "3.1.1"
},
modernizr: {
url: "http://modernizr.com/downloads/modernizr-latest.js",
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ ko.utils = (function () {
// see: https://github.com/knockout/knockout/issues/1597
var cssClassNameRegex = /\S+/g;

var jQueryEventAttachName;

function toggleDomNodeCssClass(node, classNames, shouldHaveClass) {
var addOrRemoveFn;
if (classNames) {
Expand Down Expand Up @@ -370,7 +372,10 @@ ko.utils = (function () {

var mustUseAttachEvent = eventsThatMustBeRegisteredUsingAttachEvent[eventType];
if (!ko.options['useOnlyNativeEvents'] && !mustUseAttachEvent && jQueryInstance) {
jQueryInstance(element)['bind'](eventType, wrappedHandler);
if (!jQueryEventAttachName) {
jQueryEventAttachName = (typeof jQueryInstance(element)['on'] == 'function') ? 'on' : 'bind';
}
jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler);
} else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
element.addEventListener(eventType, wrappedHandler, false);
else if (typeof element.attachEvent != "undefined") {
Expand Down

0 comments on commit 32bfa9d

Please sign in to comment.