javascript - JQuery Plugins and JQuery noConflict -
i'm using jquery in noconflict
mode since code js widget running on host page.
i have code dynamically load jquery plugin (qtip2) without interfering page's jquery.
the problem plugin binds $ variable local page's jquery.
i tried loading plugin before calling noconflict()
, works, leaves period global $ pointing jquery.
here's code (i've omitted loadjsfile
function keep short. adds script head , calls when it's loaded):
(function trackjq(timestogo) { if (timestogo-- > 0) { log("timed"); settimeout(function() {trackjq(timestogo)}, 20); } })(10) function isdef() { return typeof $.qtip !== 'undefined'; } function log (msg) { console.log(msg + " $:" + jquery.fn.jquery + " qtip:" + isdef()); } log("before loading jquery"); loadjsfile("https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", function() { log("after loading jquery"); loadjsfile("http://cdn.jsdelivr.net/qtip2/2.2.0/jquery.qtip.min.js", function() { log("after loading qtip"); $jq = jquery.noconflict(true); log("after calling noconflict"); // rest of code here... }); });
and output (shows there's time interval jquery takes over):
timed $:1.2.3 qtip:false before loading jquery $:1.2.3 qtip:false timed $:1.2.3 qtip:false after loading jquery $:1.11.0 qtip:false timed $:1.11.0 qtip:false timed $:1.11.0 qtip:false timed $:1.11.0 qtip:false after loading qtip $:1.11.0 qtip:true after calling noconflict $:1.2.3 qtip:false timed $:1.2.3 qtip:false timed $:1.2.3 qtip:false timed $:1.2.3 qtip:false timed $:1.2.3 qtip:false timed $:1.2.3 qtip:false
is there better way this?
Comments
Post a Comment