-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Wade Preston Shearer was heard saying on 07/18/2007 09:25 PM:
> Would someone be willing to walk me through the following javascript
> snippet, line-by-line? I do not understand what is happening exactly in
> the second, fourth, and sixth lines. The values being passed into the
> function are being picked up as an array, but I am not familiar with the
> syntax.
> 
> <a onclick="javascript:Effect.Combo('drawer_one', {duration: 0.5});"></a>
> 
>  Effect.Combo = function(element) {
>      element = $(element);
>      if(element.style.display == 'none') {
>           new Effect.OpenUp(element, arguments[1] || {});
>      }else {
>           new Effect.CloseDown(element, arguments[1] || {});
>      }
>  }
> 
> 
> ------------------------------------------------------------------------
> 
> 
> _______________________________________________
> 
> UPHPU mailing list
> [email protected]
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net

(Sorry for the dup post Wade, I must not be thinking straight on the
emails tonight).  Also like to thank Walt for clearing up something I
had wrong, the Object literal, instead of an array (yep, should have
caught that too).  Any, to everyone else, here's the text I sent to Wade:

Hi Wade, the JS in question uses Prototype (you probably already new
that) and Scriptaculous
(http://24ways.org/2005/introduction-to-scriptaculous-effects has the
full listing of the code snippet).  The $() function is an added
function from Prototype that is essentially an enhanced
document.getElementById which will take either the id of the element or
the actual DOM Element and return the element.

- From the full example on the above site, the author is creating an
accordion type panel and aliasing the BlindUp and BlindDown with OpenUp
and CloseDown.  Combo then toggles between the two of them (Effects, BTW
is a collection of functions from Prototype and Scriptaculous).

As for the syntax I didn't even know you could do that in JS, but it's
pretty cool.  What they're saying (because the Effects.BlindDown and
BlindUp take optional arguments which override some internal defaults)
is to pass the second argument (zero based array of course) and pass
that, unless it doesn't exist (null || nil || empty || undefined)which
just pass an empty array.

The Effects.Combo declaration is in effect creating an alias to an
inline function.  Effects.Combo then becomes the function and expects at
least an id or DOM element.  The arguments array is a reserved array
that will let you access all of the arguments of the function without
naming or declaring them.

Hope that helped.

- --
- -Jason Porter
Programmer
Infobytes, INC.
http://www.infobytes.com

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGnuRJEEbDm5Jsz/URCJnRAKC+1SVW6wbNvHpxlP+s1A9hYBexDwCfdiKU
LaV5zTTPUwF+vbddIeJnY0o=
=bKIr
-----END PGP SIGNATURE-----

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to