
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.22 KB | hits: 8 | expires: Never
Include a specific version of JQuery and a plugin without conflicting with the page's JavaScript library?
var myWidgetLoader = function() {
this.start = function() {
this.getScript('https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', function(){
jquery1_8_2 = jQuery.noConflict(true); // true = unconflict all jQuery vars, including "jQuery"
(function(jQuery) {
var $ = jQuery;
// do stuff that uses jQuery
})(jquery1_8_2);
});
}
this.getScript = function(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0], done=false;
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
done = true;
success();
}
};
head.appendChild(script);
}
}
myWidgetLoader.start();
window.jQuery = window.$ = jQuery;
window.myRedditPluginJquery = jQuery;
(function($){
//your code goes here
//you also probably have to paste the source code for that plugin here too
})(myRedditPluginJquery);