<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/prototype/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/prototype"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Making anchor links smarter... and sexier</title>
   <link href="http://davedash.com/2007/02/14/making-anchor-links-smarter-and-sexier/"/>
   <updated>2007-02-14T00:00:00-08:00</updated>
   <id>http://davedash.com/2007/02/14/making-anchor-links-smarter-and-sexier</id>
   <content type="html">&lt;p&gt;So I have a small bone to pick with Jacob Nielsen and his &lt;a href=&quot;http://www.useit.com/alertbox/within_page_links.html&quot;&gt;opinion on within-page links&lt;/a&gt; or anchor links&lt;sup id=&quot;fnr1&quot;&gt;.&lt;a href=&quot;#fn1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;  There clearly is a benefit to not just linking to a specific page, but linking to a specific part of a page.&lt;/p&gt;

&lt;p&gt;With a little help from &lt;a href=&quot;http://script.aculo.us/&quot;&gt;script.aculo.us&lt;/a&gt; we can spice up our anchor links by highlighting them as well as linking to them.&lt;/p&gt;

&lt;p&gt;For this article we'll limit our scope to internal anchors only.&lt;sup&gt;&lt;a href=&quot;#fn2&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;  We'll write the code using the symfony framework and in straight up &lt;acronym title=&quot;eXtended HypterText Markup Language&quot;&gt;XHTML&lt;/acronym&gt;.  This is really dirt simple and is more of a design pattern with an example than a tutorial.&lt;/p&gt;

&lt;p&gt;Let's do the &lt;acronym title=&quot;eXtended HypterText Markup Language&quot;&gt;XHTML&lt;/acronym&gt; first:&lt;/p&gt;

&lt;div&gt;
    
    &lt;textarea name=&quot;code&quot; class=&quot;xhtml&quot; rows=&quot;10&quot; cols=&quot;50&quot;&gt;
    &amp;lt;a href=&amp;quot;#test&amp;quot; onclick=&amp;quot;new Effect.Highlight(&amp;apos;test&amp;apos;)&amp;quot;&amp;gt;this is a test&amp;lt;/a&amp;gt;
&lt;/textarea&gt;

&lt;/div&gt;


&lt;p&gt;Yup, that's it... I told you it was dirt simple.  You just need to include the proper &lt;a href=&quot;http://prototypejs.org/&quot;&gt;prototype&lt;/a&gt; and &lt;a href=&quot;http://script.aculo.us/&quot;&gt;script.aculo.us&lt;/a&gt; libraries.&lt;/p&gt;

&lt;p&gt;In &lt;a href=&quot;http://symfony-project.com/&quot;&gt;symfony&lt;/a&gt; we avoid repeating ourselves with a helper function:&lt;/p&gt;

&lt;div&gt;
    
&lt;textarea name=&quot;code&quot; class=&quot;php&quot; rows=&quot;10&quot; cols=&quot;50&quot;&gt;
    function link_to_anchor($text, $target)
    {
        return link_to($text, '#'.$target, 'onclick='.visual_effect('highlight',$target);
    }
&lt;/textarea&gt;

&lt;/div&gt;


&lt;p&gt;and call it by doing:&lt;/p&gt;

&lt;div&gt;
    
    &lt;textarea name=&quot;code&quot; class=&quot;php&quot; rows=&quot;10&quot; cols=&quot;50&quot;&gt;
    echo link_to_anchor('this is a test', 'test');
    &lt;/textarea&gt;

&lt;/div&gt;


&lt;p&gt;That's it.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot;&gt;
    &lt;hr/&gt;
    &lt;ol&gt;
        &lt;li id=&quot;fn1&quot;&gt;Jacob Nielsen is an easy target. &lt;a href=&quot;#fnr1&quot; class=&quot;footnoteBackLink&quot;  title=&quot;Jump back to footnote 1 in the text.&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/li&gt;
        
        &lt;li id=&quot;fn2&quot;&gt;Anchors on other pages are equally useful.  To implement that, you need to have an event listener to examine the URL for an anchor and appropriately highlight the correct element. &lt;a href=&quot;#fnr2&quot; class=&quot;footnoteBackLink&quot;  title=&quot;Jump back to footnote 2 in the text.&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

</content>
 </entry>
 
 <entry>
   <title>How to make Prototype Window Class as easy as Lightbox Gone Wild</title>
   <link href="http://davedash.com/2006/11/13/how-to-make-prototype-window-class-as-easy-as-lightbox-gone-wild/"/>
   <updated>2006-11-13T00:00:00-08:00</updated>
   <id>http://davedash.com/2006/11/13/how-to-make-prototype-window-class-as-easy-as-lightbox-gone-wild</id>
   <content type="html">&lt;p&gt;I like the way that &lt;a href=&quot;http://particletree.com/features/lightbox-gone-wild/&quot; title=&quot;Lightbox Gone Wild&quot;&gt;Lightbox Gone Wild&lt;/a&gt; will automatically pickup any links with the &lt;code&gt;class=lbOn&lt;/code&gt;, but I wanted to use (at some point) &lt;a href=&quot;http://prototype-window.xilinus.com/&quot; title=&quot;Prototype Window Class&quot;&gt;Prototype Window Class&lt;/a&gt; instead.&lt;/p&gt;

&lt;p&gt;Luckily &lt;a href=&quot;http://prototype-window.xilinus.com/&quot; title=&quot;Prototype Window Class&quot;&gt;PWC&lt;/a&gt; is built on Prototype which means we've already loaded a helpful library.&lt;/p&gt;

&lt;!--more--&gt;


&lt;p&gt;In order to take all &lt;code&gt;class=lbOn&lt;/code&gt; objects and run them through &lt;a href=&quot;http://prototype-window.xilinus.com/&quot; title=&quot;Prototype Window Class&quot;&gt;PWC&lt;/a&gt; we just write a simple loop and iterate.&lt;/p&gt;

&lt;p&gt;So here's the low-down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download &lt;a href=&quot;http://prototype-window.xilinus.com/&quot; title=&quot;Prototype Window Class&quot;&gt;PWC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Copy window.js&lt;/li&gt;
&lt;li&gt;Use the included prototype &amp;amp; script.aculo.us if you don't already include it in your page&lt;/li&gt;
&lt;li&gt;copy any themes you wish to use.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;In your page add this bit of JavaScript:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;js&quot;&gt;
    var mylb = Class.create();
    
    mylb.prototype = {
        initialize: function(ctrl) {
            this.content = ctrl.href;
            Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
            ctrl.onclick = function(){return false;};
            },
    
            // Turn everything on - mainly the IE fixes
            activate: function(){
                var win = new Window('window_id', {className: &quot;alphacube&quot;,title: &quot;Tour&quot;, url: this.content, width:700, height:500});
                win.setDestroyOnClose();
                win.showCenter(true);
            }
        }

        lbox = document.getElementsByClassName('lbOn');
        for(i = 0; i &lt; lbox.length; i++) {
            valid = new mylb(lbox[i]);
        }
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;So, this code simply looks for all the anchor tags with &lt;code&gt;class=lbOn&lt;/code&gt; and then  creates a new &lt;code&gt;mylb&lt;/code&gt; instance for each anchor.  The end.&lt;/p&gt;
</content>
 </entry>
 

</feed>

