I loaded jQuery on a Firefox addon, which causes it to load using XUL's window
.
I want to change the default context so it will use the correct window
object.
The classic example I always see is:
var $ = function(selector,context){
return new jQuery.fn.init(selector,context|| correctWindow );
};
$.fn = $.prototype = jQuery.fn;
But doing it I kill a lot of functions, like .ajax
, .browser
, ... I need these methods.
AMO won't let me create an wrapper to jQuery
to send the correct window
object.
So my only option is to somehow change jQuery's default context without changing its source code.
What options do I have?
On the first content script I added
var loader = Components
.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://extensions/js/jquery-1.7.2.min.js");
var initjQuery = jQuery.fn.init;
$.fn.init = function(s,c,r) {
c = c || window.document;
return new initjQuery(s,c,r);
};
This way it works.