You can also work around this issue by specifying a default context
parameter and overriding the jQuery init function:
//Use jQuery extend to override init in jQuery.fn
jQuery.fn.extend(jQuery.fn, {
_init : jQuery.fn.init, //the original init function
init : function (selector, context) {
//If context is not specified, let's use jetpack's current
document
return this._init(selector, context ||
jetpack.tabs.focused.contentDocument);
}
});
//Add jQuery's prototype to the new init function (so we can
instantiate object via init() call)
$.prototype.init.prototype = $.prototype;
With this code in onReady(), you should be able to get away without
worrying about the issue above.
Hope this helps,
-Geoff
On Nov 1, 10:29 pm, Aza <
aza...@gmail.com> wrote:
> Thanks Thomas.
>
> That makes sense, although it is a bit annoying for coders.
>
> -- aza | ɐzɐ --
>
> On Thu, Oct 29, 2009 at 2:57 AM, Thomas Bassetto <
tbasse...@gmail.com>wrote:
>
> > Hi again,
>
> > I've found the "problem". It appears that since Jetpack 0.5 we have to
> > specify the context when creating an element. I was not aware of :(
>
> > So the "new" code is:
>
> > --------------------------------------------------------
> > jetpack.future.import("pageMods");
>
> > var callback = function(document){
> > document.title = "This site is blacklisted. Get some work done!";
> > $(document).find("body").children().hide();
> > $(document).find("body").prepend($('<h1>Sorry this site is blacklisted
> > until 17:00. sadface.</h1>', document));
>
> > };
>
> > var options = {};
> > options.matches = ["
http://xkcd.com/*"];
> > jetpack.pageMods.add(callback, options);
> > --------------------------------------------------------
>
> > Regards,
> > Thomas
>
> > 2009/10/28 Thomas Bassetto <
tbasse...@gmail.com>:
>
> > > Hi,
>
> > > I'm using the latest Jetpack build from Mercurial, with Firefox 3.5.4
> > > on Mac OS X 10.5 and the following code (it's just an example based on
> > > the official "Blacklist Sites - Page Mods Demo"):
> > > --------------------------------------------------------
> > > jetpack.future.import("pageMods");
>
> > > var callback = function(document){
> > > document.title = "This site is blacklisted. Get some work done!";
> > > $(document).find("body").children().hide();
> > > $(document).find("body").prepend($('<h1>Sorry this site is
> > > blacklisted until 17:00. sadface.</h1>'));
> > > };
>
> > > var options = {};
> > > options.matches = ["
http://xkcd.com/*"];
> > > jetpack.pageMods.add(callback, options);
> > > --------------------------------------------------------
>
> > > Now go tohttp://
xkcd.com=> This script runs well expect the
> > > ".prepend()" which generates the following error :
> > > context.createElement is not a function
> > > chrome://jetpack/content/index.html ->
>
> > file:///Users/tbassetto/Documents/MMTC/jetpacks/test/extension/content/js/ext/jquery.js
> > > Line 862
>
> > > It's the same problem with a line like: var myDiv = $("<div />");
> > > Sadly, it seems impossible to create an element.
>
> > > BTW, I also (re)confirm the bug 521078:
> > >
https://bugzilla.mozilla.org/show_bug.cgi?id=521078
>
> > > Regards,
> > > Thomas
>
> > > 2009/10/28 Aza <
aza...@gmail.com>:
> > >> Thomas,
>
> > >> Can you confirm that this doesn't work in the latest build from
> > Mercurial.
> > >> We had some issues around our security code for 0.5 that broke things in
> > >> unexpected ways. We rolled that code back for 0.6.
>
> > >> -- aza | ɐzɐ --
>
> > >> On Wed, Oct 28, 2009 at 7:09 AM, Thomas Bassetto <
tbasse...@gmail.com>
> > >> wrote:
>
> > >>> Up.
>
> > >>> Know, I encounter this error too. I use Jetpack 0.6pre2 (from
> > >>> Mercurial) and Firefox 3.5.4 on Mac OS X.
>
> > >>> It seems that since Jetpack 0.5, creating an element inside the
> > >>> callback used with jetpack.pageMods is no longer possible. For
> > >>> instance, the
> > >>> Blacklist Sites demo is broken...
>
> > >>> Could you provide us a workaround? Maybe we are doing it wrong, but I
> > >>> can't find any solution. Developing with Jetpack is so painful :(
>
> > >>> Regards,
> > >>> Thomas
>
> > >>> 2009/9/17 woidda <
walter.kammergru...@gmail.com>: