Bug Tracker

Opened 11 years ago

Closed 10 years ago

#4534 closed bug (invalid)

2 instances of jQuery kills unbind

Reported by: ptarjan Owned by:
Priority: major Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Description

Steps to recreate :

  • http://paul.slowgeek.com/nodeSelector/dev/bad-unbind.html
  • Click the "Add key listener"
  • Press keys and notice they are printed
  • Press ESC and see it says "unbinding"
  • Press more keys and see they AREN'T printed
  • Click the "add key listener" again
  • Press keys and see they ARE printed
  • Press ESC and see it says "unbinding"
  • Press keys and see they ARE printed (this is the bad part)

If I change the javascript code to NOT add the jQuery library, then it works as expected.

Pasting Code incase my site is down:

--- bad-unbind.html <a href=' javascript:(

function() {

var s=document.createElement("script");

s.charset="UTF-8"; s.src="bad-unbind.js";

document.body.appendChild(s)

})();

'>Add key listener</a> <p id='key'></p> --- end

--- bad-unbind.js addLibs = function () {

if (typeof(document.body) == "undefined"
document.body == null) {

setTimeout(addLibs, 100); return;

}

This line makes it work if (typeof($) == "undefined") {

node = document.createElement("script"); node.src = "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"; document.body.appendChild(node);

} addEvents();

}

addEvents = function () {

if (typeof($) == "undefined"
$("*") == null) {

setTimeout(addEvents, 100); return;

} var keydown = function(e) {

if (e.keyCode == undefined && e.charCode != undefined) e.keyCode = e.charCode; $("#key").html("keydown " + e.keyCode); Escape key if (e.keyCode == 27) {

$("#key").html("unbinding"); $(document).unbind("keydown", keydown);

}

}; $(document).keydown(keydown);

} addLibs(); --- end

Change History (2)

comment:1 Changed 10 years ago by petersendidit

The fix is don't include jQuery twice. I don't think jQuery needs to support itself getting loaded twice.

comment:2 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

It's okay to load two copies of jQuery, for example two different versions. However, at least one of them would need to use jQuery.noConflict() so that they could each be referenced. Loading two copies where the second clobbers the first doesn't make sense.

Note: See TracTickets for help on using tickets.