Jquery and Jetpack 0.5

10 views
Skip to first unread message

woidda

unread,
Sep 17, 2009, 12:04:57 PM9/17/09
to mozilla-labs-jetpack
Hello everybody,

I have experienced a some problems with the new version (0.5) of
Jetpack in combination with jQuery features.

For example simple things are broken such as:

$('<html><head></head><body><h1>TEST header <h1><div id="bla">bla bla</
div></body></html>').find('#bla');

this throws an errror in the firebug console:
" context.createElement is not a function"
linking to some jQuery code. Meaning the jQuery code is loaded but
there are some issues.
Have you changed the included jQuery version?

Also e.g. the example plugin: http://steveram.info/jetpacks/fml/ does
not work for me anymore.
I hope this issues are not only specific to my setup: Windows XP,
Firefox 3.5.3 (+ Firebug 1.5X.0a24)

Maybe this helps to find bugs. Actually I do like Jetpack a lot.

best
Walter

david

unread,
Sep 24, 2009, 3:47:43 AM9/24/09
to mozilla-labs-jetpack
Hello everybody,

I have exactly the same problem.
Are there any solutions?

David

Walter Kammergruber

unread,
Sep 24, 2009, 6:53:59 AM9/24/09
to mozilla-la...@googlegroups.com
Hello again,

just to give a really simple example:
Go to
1) about:jetpack
2) tab: Develop
3) paste into the black box:

console.log($('<html><head></head><body><h1>TEST header <h1><div
id="bla">bla bla</div></body></html>').find('#bla'));

Does this work for you?

For me an error is thrown (in the firebug console):
"TypeError context.createElement is not a function ( TypeError:
context.createElement is not a function )"

In JetPack 0.4 the example works fine.

What might be the reason?

best
Walter

Thomas Bassetto

unread,
Oct 28, 2009, 10:09:48 AM10/28/09
to mozilla-la...@googlegroups.com
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.ka...@gmail.com>:
--
Thomas Bassetto — tb4.fr
Élève-ingénieur de l'INSA de Rouen en Architecture des Systèmes
d'Information — 5ème année

Aza

unread,
Oct 28, 2009, 3:48:45 PM10/28/09
to mozilla-la...@googlegroups.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ɐ --

Thomas Bassetto

unread,
Oct 28, 2009, 5:23:18 PM10/28/09
to mozilla-la...@googlegroups.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 to http://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 Bassetto

unread,
Oct 29, 2009, 5:57:32 AM10/29/09
to mozilla-la...@googlegroups.com
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 <tbas...@gmail.com>:

Aza

unread,
Nov 1, 2009, 10:29:08 PM11/1/09
to mozilla-la...@googlegroups.com, Daniel Buchner
Thanks Thomas.

That makes sense, although it is a bit annoying for coders.

-- aza | ɐzɐ --

ghayes

unread,
Nov 23, 2009, 2:55:03 AM11/23/09
to mozilla-labs-jetpack
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>:

Aza

unread,
Nov 23, 2009, 2:50:48 PM11/23/09
to mozilla-la...@googlegroups.com
That's a very clever little hack.

Geoff, what do you think about us adding that to jQuery by default in Jetpack?



-- aza | ɐzɐ --


--

You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To post to this group, send email to mozilla-la...@googlegroups.com.
To unsubscribe from this group, send email to mozilla-labs-jet...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mozilla-labs-jetpack?hl=.



Zbigniew Braniecki

unread,
Nov 30, 2009, 6:18:59 AM11/30/09
to mozilla-labs-jetpack
On Nov 23, 11:50 am, Aza <aza...@gmail.com> wrote:
> That's a very clever little hack.
>
> Geoff, what do you think about us adding that to jQuery by default in
> Jetpack?
>
> -- aza | ɐzɐ --
>
> On Sun, Nov 22, 2009 at 11:55 PM, ghayes <haye...@gmail.com> wrote:
> > You can also work around this issue by specifying a default context
> > parameter and overriding the jQuery init function:

This must be solved, this way or another.
Currently, some pieces of basic jquery functionality depend on ability
to silently inject DOM nodes into context - for example in show()
function.

in JP0.5 this will not work: $('#dialog',doc).show()

Greetings,
Zbigniew Braniecki
--

Mozilla (http://www.mozilla.org)

openjaf

unread,
Jan 7, 2010, 2:35:37 PM1/7/10
to mozilla-labs-jetpack
Has this issue been resolved?

I still must insert the code insert above to use this functionallity.

-- Jim

On Nov 30 2009, 6:18 am, Zbigniew Braniecki

Reply all
Reply to author
Forward
0 new messages