Welcome to the jQuery Concrete group

10 views
Skip to first unread message

hamish

unread,
Oct 15, 2009, 3:55:53 AM10/15/09
to jQuery Concrete
Welcome,

For anyone that finds their way here, welcome. There's no particular
agenda for this group, but if you like jQuery.concrete, or hate it, or
wish it did something it doesn't, or doesn't do something it does,
yell out.

Eric S.

unread,
Oct 19, 2009, 2:42:17 PM10/19/09
to jQuery Concrete
Neat plugin!

I'm still not 100% on the namespaces. It looks like there are two
similar syntaxes?

The README tutorial shows:
$.concrete('foo', function($){ ...

While the "walkthrough" tutorial shows:
$('ss.accordian').concrete(function($){

Are these syntaxes identical? Is one preferred?

hamish

unread,
Oct 19, 2009, 2:56:17 PM10/19/09
to jQuery Concrete
Hi,

Yeah, there are two syntaxes for defining concrete functions.

Newer format:

$.concrete('namespace', function($){
$('.selector').concrete({
foo: function(){}
})
})

Older format:

$('.selector').concrete('namespace',function($){ return {
foo: function(){}
}})

The older format can occasionally be useful for adding single
functions to a namespace, but it's not as well tested, it's less
clear, and the structure has more framing to get it to work. The
recommended format is the new one.

Having said that, the old format still has a primary use - calling
(rather that defining) functions from namespaces externally:

$('.selector').concrete('namespace').foo();

You can also do

$.concrete('namespace', function($){
this.foo();
})

but that's kinda wordy

Hamish Friedlander

Eric S.

unread,
Oct 19, 2009, 5:51:36 PM10/19/09
to jQuery Concrete
So, is this syntax used at all?

$('namespace').concrete(function($){
$('.selector').concrete({
foo: function(){}
...


Also, why does the dollar sign function have to be passed into the
callback? I couldn't find the reasoning in the concrete docs.


Thanks!
-Eric

hamish

unread,
Oct 19, 2009, 6:03:35 PM10/19/09
to jQuery Concrete

On Oct 20, 10:51 am, "Eric S." <estrathme...@gmail.com> wrote:
> So, is this syntax used at all?
>
> $('namespace').concrete(function($){
>         $('.selector').concrete({
>                  foo: function(){}
>              ...

No. Have I used that in the docs? It's wrong :). Anything passed
directly to the $() function is a selector. The namespace is always
passed as the first argument to the concrete function - either
$.concrete(namespace, ... ) or $(selector).concrete(namespace, ...)

> Also, why does the dollar sign function have to be passed into the
> callback?  

We override the $ function to return jQuery selection objects that
know what their namespace is. It's needed for both the internal
concrete definitions and for the lookup-in-namespace-before-base logic

If you did this (notice no $ argument to the function):

$.concrete('namespace', function(){
$('.selector').concrete({
foo: function(){ $('div').bar(); }
bar: function(){}
})
});

Then the second concrete call (the $('.selector').concrete one)
doesn't have any way of knowing what namespace to inject foo and bar
into, and the $('div').bar() call would also not know that bar should
be looked up in namespace first.

> I couldn't find the reasoning in the concrete docs.

Yeah. The docs still need some work, especially the reference portion.

Hamish Friedlander

Eric S.

unread,
Oct 19, 2009, 6:17:56 PM10/19/09
to jQuery Concrete
Thanks so much for your quick replies! All is now clear. The
overriding-$ trick seems a little mischievous, but I can't think of a
better alternative.

Perhaps including an example like the following would clarify what's
going on (and show people that the dollar sign isn't magic):
$('namespace').concrete(function(namespaceAwareQuery){
namespaceAwareQuery('.selector').concrete({
foo: function(){}
...


Small FYI stuff:
- The weird name space syntax came from:
http://hafriedlander.github.com/jquery.concrete/tutorial/step_08.html
- The video tutorial up on vimeo (http://www.vimeo.com/6353390)
implies that there's an explanation about the namespace/$ syntax in
the concrete docs.
Reply all
Reply to author
Forward
0 new messages