How to change jQuery default context?

Go To StackoverFlow.com

2

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?

2012-04-03 21:07
by BrunoLM
possible duplicate of Override default jQuery selector contextBrunoLM 2012-04-03 23:09
Previous answer that should help:
http://stackoverflow.com/a/3690529/43722 - ramblinjan 2012-04-03 23:05


1

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.

2013-12-12 18:55
by BrunoLM
Ads