Skip to content

Instantly share code, notes, and snippets.

@dokipen
Created July 8, 2010 15:38
Show Gist options
  • Save dokipen/468163 to your computer and use it in GitHub Desktop.
Save dokipen/468163 to your computer and use it in GitHub Desktop.
Multi-Version jQuery on Crack
function(my_selector) {
var old_jQuery = jQuery;
var doWork = function() {
var my_jQuery = jQuery.noConflict();
jQuery = old_jQuery;
// load up myplugin on my_jQuery
my_jQuery(my_selector).myplugin({...});
}
var head = document.getElementsByTagName('head')[0]
var jq_script = document.createElement('script');
jq_script.src = "http://ajax.googleapis.com/ajax/libs.jquery/1.4.2/jquery.min.js";
jq_script.type = "text/javascript";
head.appendChild(jq_script);
jq_script.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
doWork();
}
};
jq_script.onload = doWork;
}();
@dokipen
Copy link
Author

dokipen commented Jul 8, 2010

This is a braindump and untested. I maintain the datepicker plugin for trac. Often times, users have some ancient version of jquery that doesn't work with datepicker. This problem usually shows up on Debian, which provides an older version of jquery and strips the default version from the trac installation. I'm trying to brainstorm a safe solution to use a newer version of jquery for my plugin only. The constraint is that my code shouldn't interfere with the rest of the site. This solution could be slow, but at least it will always work(in theory). Perhaps I can wrap this code in a conditional driven by a trac configuration parameter like [datepicker] safe_mode = enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment