I am porting an extension from Google Chrome into Firefox's Addon SDK (v1.9). Since it uses jQuery on the background page (main.js on Firefox), I would like to use that library as well on the Firefox version. However, since the window object is not accessible from the addon code itself (and jQuery is widely based on that), I was wondering if there was a better way of implementing the jQuery library from the addon code. Maybe there is a way to import jQuery as a module using "require('jquery')".
Just to clarify, I am aware of how to implement jQuery on content scripts. What I am trying to do is use jQuery on the addon code itself, such as "main.js" (or whatever name you give the background "main" module).
I'm also porting an extension from Chrome to Firefox, and managed to come up with this:
var {Cc, Ci} = require("chrome");
_window = Cc["@mozilla.org/appshell/appShellService;1"]
.getService(Ci.nsIAppShellService).hiddenDOMWindow;
$ = require('jquery')(_window);
There's a little more detail here.
Nowadays there are lots of uses for jQuery in a non-DOM context, especially Deferreds and ajax stuff, as well as utilities like extend. It would be frustrating to have to rewrite cross-browser jQuery code to be Firefox-specific, e.g. the request module.