Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.22 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Include a specific version of JQuery and a plugin without conflicting with the page's JavaScript library?
  2. var myWidgetLoader = function() {
  3.  
  4.    this.start = function() {
  5.       this.getScript('https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', function(){
  6.  
  7.          jquery1_8_2 = jQuery.noConflict(true);  // true = unconflict all jQuery vars, including "jQuery"
  8.          (function(jQuery) {
  9.             var $ = jQuery;
  10.             // do stuff that uses jQuery
  11.          })(jquery1_8_2);
  12.  
  13.       });
  14.    }
  15.  
  16.    this.getScript = function(url, success) {
  17.       var script = document.createElement('script');
  18.       script.src = url;
  19.       var head = document.getElementsByTagName('head')[0], done=false;
  20.       script.onload = script.onreadystatechange = function(){
  21.          if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
  22.             done = true;
  23.             success();
  24.          }
  25.       };
  26.       head.appendChild(script);
  27.    }
  28.  
  29. }
  30.  
  31. myWidgetLoader.start();
  32.        
  33. window.jQuery = window.$ = jQuery;
  34.        
  35. window.myRedditPluginJquery = jQuery;
  36.        
  37. (function($){
  38.     //your code goes here
  39.     //you also probably have to paste the source code for that plugin here too
  40. })(myRedditPluginJquery);