<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'A "Hybrid Designer's" Perspective' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/45/topics/149</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Fri, 21 Dec 2007 13:11:03 -0000</title>
      <description>&lt;p&gt;Oh yeah, you&amp;#8217;re absolutely right about the &amp;lt;a&amp;gt; tag not being allowed directly under the &amp;lt;body&amp;gt; tag in xHTML 1.0 Strict.  I believed you, but wanted to try it out for myself&amp;#8230; my validator yelled at me.&lt;/p&gt;


	&lt;p&gt;The missing &amp;#8216;href&amp;#8217; was a case of coding in a hurry :).&lt;/p&gt;</description>
      <pubDate>Fri, 21 Dec 2007 13:11:03 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:2061</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Fri, 21 Dec 2007 12:59:07 -0000</title>
      <description>&lt;p&gt;Christophe,&lt;/p&gt;


	&lt;p&gt;Thanks so much for your reply.  As you can see, I&amp;#8217;ve only ever worked with the &lt;span class="caps"&gt;DOM&lt;/span&gt;, so the &amp;#8220;Ways of the Proto&amp;#8221; are totally new to me.  I just received my paperback copy of your book in the mail, and I&amp;#8217;m excited to begin rewiring my brain to do things the efficient, Prototype way.  I&amp;#8217;ve been charged with training our development team in Prototype, so your book and blog should be excellent resources.&lt;/p&gt;


	&lt;p&gt;Thanks again&amp;#8230; Merry Christmas.&lt;/p&gt;</description>
      <pubDate>Fri, 21 Dec 2007 12:59:07 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:2060</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Christophe Porteneuve @ Wed, 21 Nov 2007 21:27:31 -0000</title>
      <description>&lt;p&gt;Hey Jason!&lt;/p&gt;


	&lt;p&gt;Thanks for the feedback.  I&amp;#8217;m delighted you do find the book helpful, although perhaps not as hand-holding as you were hoping.&lt;/p&gt;


	&lt;p&gt;The book&amp;#8217;s idea is, indeed, not to explain JavaScript itself (other books do that wonderfully well), although I sometimes pause for a moment to quickly describe a language feature or another.  The book is about the libs, so we dive into these.  However, I agree that lowering the barrier to entry sometimes would be good (although this makes the book bigger and bigger, to the point where it might scare off quite a few people!).&lt;/p&gt;


	&lt;p&gt;Allow me to thank you for your examples and the desire to help out that drove them, and let me comment on those to help you out in turn:&lt;/p&gt;


	&lt;p&gt;First one: just fine, although I would personally recommend, most times, to start the handler with a event.stop() call (it lets me abbreviate code by returning instead of using (potentially nested) if/else and stuff).&lt;/p&gt;


	&lt;p&gt;The &lt;code&gt;$$&lt;/code&gt; example: ah, a prime case of over-using &lt;code&gt;each&lt;/code&gt; and under-using &lt;code&gt;invoke&lt;/code&gt;.  Here&amp;#8217;s the culprit:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$$( 'a.helloWorld' ).each( function( instance, i ) { instance.observe( 'click', sayIt ) } );&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;You see, the anonymous function is unnecessary overhead here, because all it does is invoke the same method on each element, with the same arguments.  That&amp;#8217;s a prime case for &lt;code&gt;invoke&lt;/code&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$$('a.helloWorld').invoke('observe', 'click', sayIt);&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Isn&amp;#8217;t it sweet?  Plus, it does not use an anonymous function internally, so it&amp;#8217;s faster, too!&lt;/p&gt;


	&lt;p&gt;In the same manner, &lt;code&gt;pluck&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; optimize common iteration patterns; see the book&amp;#8217;s dedicated sidebar and the online &lt;span class="caps"&gt;API&lt;/span&gt; docs for details and cross references between all those.&lt;/p&gt;


	&lt;p&gt;Third example: the toggling thing.  First off, the markup:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;a href id='showHide'&amp;gt;Hide&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Is not valid &lt;span class="caps"&gt;XHTML&lt;/span&gt;.  The &lt;code&gt;href&lt;/code&gt; attribute is here pretty useless, as you don&amp;#8217;t have an accessible (i.e. non-JS) alternative.  On the other hand, stripping it entirely will make the link not react to &lt;code&gt;click&lt;/code&gt;, and even sometimes not render as a link, on a few browsers.  So you should just provide the classic &lt;code&gt;href="#"&lt;/code&gt; tweak.  Also, inline elements such as &lt;code&gt;a&lt;/code&gt; are not allowed directly within &lt;code&gt;body&lt;/code&gt;, according to the &lt;span class="caps"&gt;XHTML 1&lt;/span&gt; Strict &lt;span class="caps"&gt;DTD&lt;/span&gt;.  Just wrap it inside a paragraph to be fully compliant ;-)&lt;/p&gt;


	&lt;p&gt;Now, the code you&amp;#8217;re using to change the contents:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;event.element().childNodes[0].nodeValue    = ( event.element().childNodes[0].nodeValue == 'Hide' ? 'Show' : 'Hide' );&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This is typical half-Prototype code, e.g. half old-school-doing-it-all-myself, way-too-much-DOM-intimacy way, and half Prototypish way.  You shouldn&amp;#8217;t care about &lt;code&gt;childNodes&lt;/code&gt;: that&amp;#8217;s raw &lt;span class="caps"&gt;DOM&lt;/span&gt; stuff.  Incidentally, this (only) child node is a text node, which makes it &lt;strong&gt;outside the scope of &lt;code&gt;firstDescendant()&lt;/code&gt;&lt;/strong&gt;: the &lt;span class="caps"&gt;DOM&lt;/span&gt; traversal methods in Prototype only care about element nodes (as well they should).&lt;/p&gt;


	&lt;p&gt;What you&amp;#8217;re trying to do here is change the contents of your toggler, toggling between two states.  First, you should avoid multiple traversals for no reason.  Second, you can either go with &lt;code&gt;innerHTML&lt;/code&gt; (which is reasonably well supported for such simple purposes) and &lt;code&gt;update&lt;/code&gt;, or still go DOMish.&lt;/p&gt;


	&lt;p&gt;The Proto way:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;var contents = event.element().innerHTML;
event.element().update('Hide' == contents ? 'Show' : 'Hide');&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The DOMish way:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;var contents = event.elements().firstChild;
contents.nodeValue = ('Hide' == contents.nodeValue ? 'Show' : 'Hide');&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;There, I hope this helps.&lt;/p&gt;


	&lt;p&gt;In addition to this forum, I suggest you keep an eye on the &lt;a href="http://thebungeebook.net"&gt;book&amp;#8217;s blog&lt;/a&gt; for upcoming tips and tricks, answers to the &#8220;Neuron Workout&#8221; sections, announcements, challenges, quizzes, and more!&lt;/p&gt;</description>
      <pubDate>Wed, 21 Nov 2007 21:27:31 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:1962</guid>
      <author>Christophe Porteneuve</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Wed, 21 Nov 2007 16:07:07 -0000</title>
      <description>&lt;p&gt;Here is an example of using toggle() to show/hide a &amp;lt;div&amp;gt; element.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;script type="text/javascript" src="lib/prototype.js"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type="text/javascript"&amp;gt;

    // document.onload

    document.observe( 'dom:loaded', function()
    {
        $( 'showHide' ).observe( 'click', makeToggle );
    } );

    // global functions

    function makeToggle( event )
    {
        // Change &amp;lt;a&amp;gt; nodeValue     NOTE: event.element().firstDescendant().nodeValue will not work (why?)

        event.element().childNodes[0].nodeValue    = ( event.element().childNodes[0].nodeValue == 'Hide' ? 'Show' : 'Hide' );

        // Show / Hide &amp;lt;div&amp;gt;

        $( 'togglable' ).toggle();

        event.stop();
    }

    &amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
        *            { font-family:Arial, Helvetica, sans-serif; color:#036; margin:5px; }
        #showHide    { display:block; float:left; padding:5px; border:1px solid #aaa; }
        #togglable    { display:block; float:left; padding:5px; background-color:#036; color:#fff; }
    &amp;lt;/style&amp;gt;

    &amp;lt;title&amp;gt;PrototypeTest&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;a href id='showHide'&amp;gt;Hide&amp;lt;/a&amp;gt;
    &amp;lt;div id="togglable"&amp;gt;I am visible!&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 21 Nov 2007 16:07:07 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:1960</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Wed, 21 Nov 2007 14:51:12 -0000</title>
      <description>&lt;p&gt;Here is another example, this time using the $$() magic search, and the incredible .each() method to attach the &amp;#8220;Hello, World!&amp;#8221; alert to all &amp;lt;a&amp;gt; anchors with a class of &amp;#8220;helloWorld&amp;#8221;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;script type="text/javascript" src="lib/prototype.js"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type="text/javascript"&amp;gt;

    // document.onload

    document.observe( 'dom:loaded', function()
    { 
        $$( 'a.helloWorld' ).each( function( instance, i ) { instance.observe( 'click', sayIt ) } );
    } );

    // custom functions

    function sayIt( event )
    {
        alert( 'Hello, World!' );
        event.stop();
        return true;
    }

    &amp;lt;/script&amp;gt;

    &amp;lt;title&amp;gt;PrototypeTest&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;a href="ignored.html" class='helloWorld'&amp;gt;Link 1&amp;lt;/a&amp;gt;
    &amp;lt;a href="ignored.html" class='helloWorld'&amp;gt;Link 2&amp;lt;/a&amp;gt;
    &amp;lt;a href="ignored.html" class='helloWorld'&amp;gt;Link 3&amp;lt;/a&amp;gt;
    &amp;lt;a href="ignored.html" class='helloWorld'&amp;gt;Link 4&amp;lt;/a&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;For more examples of using $$(), see pages 45 &amp;#8211; 47.  Examples of .each() are sprinkled throughout the book, so check the Index.&lt;/p&gt;</description>
      <pubDate>Wed, 21 Nov 2007 14:51:12 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:1959</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Wed, 21 Nov 2007 13:58:10 -0000</title>
      <description>&lt;p&gt;I thought, rather than just complaining, maybe I could provide some simple examples myself as I learn Prototype from the book.  Here is the simple &amp;#8220;Hello, World!&amp;#8221; alert exercise I mentioned above:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;script type="text/javascript" src="prototype.js"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type="text/javascript"&amp;gt;

    // document.onload

    document.observe( 'dom:loaded', function()
    { 
        $( 'helloWorld' ).observe( 'click', sayIt );
    } );

    // custom functions

    function sayIt( event )
    {
        alert( 'Hello, World!' );
        event.stop();
        return true;
    }

    &amp;lt;/script&amp;gt;

    &amp;lt;title&amp;gt;PrototypeTest&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;a href="ignored.html" id="helloWorld"&amp;gt;Click Me&amp;lt;/a&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 21 Nov 2007 13:58:10 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:1958</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
    <item>
      <title>A &amp;quot;Hybrid Designer's&amp;quot; Perspective posted by Jason Pecor @ Tue, 20 Nov 2007 23:15:30 -0000</title>
      <description>&lt;p&gt;I just purchased/downloaded the &lt;span class="caps"&gt;PDF&lt;/span&gt; of this book yesterday, excited to start building slick UI&amp;#8217;s for my projects.  I wanted to give my first impressions of the book, and some recommendations for making Prototype more accessible to &amp;#8220;the rest of us.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m a so-called &amp;#8220;Hybrid Designer&amp;#8221; meaning I&amp;#8217;m from a graphic design background, and slowly migrated into programming as the industry began to demand it.  My programming background consists almost entirely of &lt;span class="caps"&gt;PHP&lt;/span&gt;, and my only real exposure to Object-Oriented programming is to the extent that it is implemented in &lt;span class="caps"&gt;PHP 5&lt;/span&gt;.  I write standards-compliant markup, &lt;span class="caps"&gt;CSS&lt;/span&gt;, and unobtrusive JavaScript; I&amp;#8217;ve used &lt;span class="caps"&gt;AJAX&lt;/span&gt; on a very small scale; And, I&amp;#8217;ve manipulated the &lt;span class="caps"&gt;DOM&lt;/span&gt; using the standard browser-supported methods.&lt;/p&gt;


	&lt;p&gt;As of yesterday, I thought I was doing well.  I thought I had a pretty good handle on things.  Then I was served an extra large helping of humble pie!  You can pass a function as a parameter?  Who knew?!  But that&amp;#8217;s okay.  I pressed on, eager to get to chapter 7, where the &lt;span class="caps"&gt;DOM&lt;/span&gt; would become fun, and the magical powers of Prototype would be layed at my feet.&lt;/p&gt;


	&lt;p&gt;The chapter started off being very promising.  Then, at the bottom of page 132, when you&amp;#8217;re itching to get your feet wet with some simple exercises, you&amp;#8217;re hit with a bold heading to the effect of &amp;#8220;Now, Let&amp;#8217;s Rebuild Google Maps From Scratch&amp;#8221;...&amp;#8221;Building a Staff Manager.&amp;#8221;  &lt;span class="caps"&gt;ARGH&lt;/span&gt;!  How about starting with something simple?  Every &lt;span class="caps"&gt;DOM&lt;/span&gt; book I&amp;#8217;ve read starts with the most generic exercise there is&amp;#8230; attaching an alert() call to the &amp;#8216;click&amp;#8217; event of an &amp;lt;a&amp;gt; anchor tag, starting with &amp;#8220;document.onload&amp;#8221; ( or document.observe(&amp;#8216;dom:loaded&amp;#8217;, [listener]) in this case ).  It reminds of my first time behind the wheel when my driving instructor casually instructed me to &amp;#8220;take the interstate; it&amp;#8217;s faster.&amp;#8221;  Again, &lt;span class="caps"&gt;ARGH&lt;/span&gt;!&lt;/p&gt;


	&lt;p&gt;For people such as myself, I think a little more hand-holding would be much appreciated in Chapter 7.  This way knowledge of the syntax builds gradually through use.  Perhaps such hand-holding could be relegated to an appendix, but I definitely see a need for this.&lt;/p&gt;


	&lt;p&gt;All said, I am really enjoying the book.  It&amp;#8217;s eye-opening, entertaining, and (as I mentioned earlier) humbling!&lt;/p&gt;</description>
      <pubDate>Tue, 20 Nov 2007 23:15:30 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:149:1956</guid>
      <author>Jason Pecor</author>
      <link>http://forums.pragprog.com/forums/45/topics/149</link>
    </item>
  </channel>
</rss>
