<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2010://34/tag:www.insideria.com,2009://34.33651-</id>
  <updated>2010-03-09T16:01:46Z</updated>
  <title>Comments for Creating your own Side bar &quot;widget&quot; using SpryDOMUtils and SpryEffects! Part 1 (http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.33651</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=33651" title="Creating your own Side bar &quot;widget&quot; using SpryDOMUtils and SpryEffects! Part 1" />
    <published>2009-02-11T14:00:00Z</published>
    <updated>2009-02-11T14:00:00Z</updated>
    <title>Creating your own Side bar &quot;widget&quot; using SpryDOMUtils and SpryEffects! Part 1</title>
    <summary>The Adobe Spry Framework is ideal for creating your own little widgets using existing Spry components as your tools. The best thing about Spry is that it requires very little knowledge of JavaScript, HTML and CSS. With the two files...</summary>
    <author>
      <name>Arnout Kazemier</name>
      
    </author>
    
    <category term="Adobe Feed" />
    
    <category term="Features" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p>The Adobe Spry Framework is ideal for creating your own little widgets using existing Spry  components as your tools. The best thing about Spry is that it requires very little knowledge of JavaScript, HTML and CSS. With the two files that we will be using today, I will teach you  how to create the most amazing widgets your self!</p>

<p>Note: All source code is available for download at the end <a href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid-1.html">part 2</a></p>

<p>In part 1 of this article I will show you how to a build your own widget using SpryDOMUtils and SpryEffects. I will teach you how to build it up from scratch, how to style it and of course how to make it functional. I will be explaining each step in detail so it will be easy to follow for everybody.</p>
<p>In part 2 we are going to evolve the widget, making it more powerful, unobstructive and easier to use. We will replace the Spry Effects and make it in to a effect cluster. I will also give you some tips and show how to tackle some potential issues.</p>

<p><strong>Requirements:</strong></p>
<ul>
<li>Adobe Spry Framework 1.6.1+</li>
<li>Dreamweaver CS3 (optional) </li>
</ul>
<p><strong>Sample files:</strong></p>
<ul>
<li>SprySideBar.zip</li>
 <li>-SideBar basic</li>
 <li>-SideBar Advanced</li>
 <li>-SideBar Skinned with SpryAccordion</li>
 </ul>
 <p><strong>Prerequisite knowledge:</strong></p>

<p>Familiarity with building HTML, CSS and JavaScript can be considered as a bonus.</p>

<p><strong>Recommend reading:</strong></p>
 <p>Effect Coding [<a href="http://labs.adobe.com/technologies/spry/articles/effects_coding/index.html" target="_blank">http://labs.adobe.com/technologies/spry/articles/effects_coding/index.html</a>]</p>

<p><strong>Preparing our files:</strong></p>
  <p>We are going to start with a basic HTML file (basic tags, like doctype, html, header and  body). It might also be helpful to create a SpryAssets folder and place our required
  JavaScript files (SpryEffects.js and SpryDOMUtils.js) and a CSS file in this folder. </p>

  <h2>Part 1: The skeleton of the widget.</h2>
  <p>We want to create a simple widget that shows a little box, or menu when a user clicks on the tab. To achieve this behavior we will need a good skeleton for our widget that allows us to fully control the process.</p>

<p>Let's open our HTML file and start adding our required files to the header of the page:</p>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;link <span class="category2">type</span>="<span class="quote">text/css</span>" rel="<span class="quote">stylesheet</span>" href="<span class="quote">SpryAssets/SprySideBar.css</span>" /&gt;
&lt;script <span class="category2">type</span>="<span class="quote">text/javascript</span>" src="<span class="quote">SpryAssets/SpryDOMUtils.js</span>"&gt;&lt;/script&gt;
&lt;script <span class="category2">type</span>="<span class="quote">text/javascript</span>" src="<span class="quote">SpryAssets/SpryEffects.js</span>"&gt;&lt;/script&gt;</pre>
</code>

</div></div>

<p>There is no required order of placing the files in the header. Now that we have our
components add to the page we are going to start on the skeleton of our widget. Let's create
a container for our SideBar we will be using a &lt;div&gt; tag for this and you can place this &lt;div&gt;
under the &lt;body&gt; of our page. Because we want to be able to easily access our widget we
are going to add a id='example1' to the div, this will help our components later on to
identify the div as the widget. As we want flexible skinning for the widget as well we are
also going to add a class to it, use easily identifying names for your classes I'm going to use
SprySideBar here, there are almost no limits in the amount of classes you can add to an
element, it has been tested that most browsers can read up to 2000 classes for a element,
this is more than we hopefully will ever use!</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;div id="<span class="quote">example1</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;
&lt;/div&gt;</pre>
</code>

</div></div>

<p>That is how your code should look like, now let's continue with creating the content of our
widget and add a &lt;div&gt; tag inside the div we just created. We will use this div for our
animations to slide or scale it. Give the &lt;div&gt; a id that you can easily remember, I'm using
example_content as it's the content of my example1 id also add a class to this element and
give it a value of SprySideBarContent.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;div id="<span class="quote">example1</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarContent</span>" id="<span class="quote">example_content</span>"&gt;
&lt;/div&gt;
&lt;/div&gt;</pre>
</code>

</div></div>

<p>We have our content &lt;div&gt;, now we want to add our tab to the skeleton. &lt;a&gt; element for this as we want to click on it, for the href attribute we will not be using a
link but a 'javascript://' some of you might think why not use a simple #? This is because I
have found out that some Opera browsers think it still a link, and actually reload the page.
So it's rather to be save than sorry! Add an id='SideBarTab' and class='SprySideTab' to the
&lt;a&gt; element, the id will be used to attach the event listener on and the class is used to skin
the button. Between the &lt;a&gt; &lt;/a&gt; tags I placed a &lt;em&gt; &lt;/em&gt; code, these will be used
as status indicators of our widget. Add in a image or some text to indicate the current status
of the widget.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;div id="<span class="quote">example1</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarContent</span>" id="<span class="quote">example_content</span>"&gt;
&lt;/div&gt;
&lt;a href="<span class="quote">javascript://</span>" id="<span class="quote">sideBarTab</span>" <span class="category1">class</span>="<span class="quote">SprySideTab</span>"&gt;&lt;em&gt; &gt;&gt; &lt;/em&gt;&lt;/a&gt;
&lt;/div&gt;</pre>
</code>

</div></div>

<p>Now that already looks like a nice skeleton to me, but we are not done yet! It's time to add something in the content, you can basically put anything you want in here, from images, SpryTabbedPanels till complete SpryDataSets! In this example I will be using a simple menu
that is created from &lt;ul&gt; and &lt;li&gt; elements with a little header to inform the user, but
before you add anything, create a new &lt;div&gt; with a class=''SprySideBarMenu" and id='menu'
so we can attach another effect for showing up the content of the menu and place your
menu inside of it.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;div id="<span class="quote">example1</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarContent</span>" id="<span class="quote">example_content</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarMenu</span>" id='<span class="quote">menu</span>'&gt;
&lt;h1&gt;SprySideBar&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
2
&lt;/div&gt;
&lt;a href="<span class="quote">javascript://</span>" id="<span class="quote">sideBarTab</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;&lt;em&gt; &gt;&gt; &lt;/em&gt;&lt;/a&gt;
&lt;/div&gt;</pre>
</code>

</div></div>

<p>Because we want an always visible background, and the background of the content &lt;div&gt;
will scale away from the effect we need to create a little wrapper for the content. This will
be a mostly CSS powered background. This &lt;div&gt; only needs to be wrapped around the
SprySideBarContent &lt;div&gt; and it only requires a class='SprySideBarGroup'. This is the last
addition to our skeleton!</p>

<p>Your final skeleton should look similar to this:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;div id="<span class="quote">example1</span>" <span class="category1">class</span>="<span class="quote">SprySideBar</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarGroup</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarContent</span>" id="<span class="quote">example_content</span>"&gt;
&lt;div <span class="category1">class</span>="<span class="quote">SprySideBarMenu</span>" id='<span class="quote">menu</span>'&gt;
&lt;h1&gt;SprySideBar&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="<span class="quote">#</span>"&gt;Link 5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;a href="<span class="quote">javascript://</span>" id="<span class="quote">sideBarTab</span>" <span class="category1">class</span>="<span class="quote">SprySideTab</span>"&gt;&lt;em&gt;&lt;/em&gt;&lt;/a&gt;
&lt;/div&gt;</pre>
</code>

</div></div>

<h2>Part 2: Styling the widget!</h2>

<p>Now that we have our widget's skeleton done we can take a closer look at our CSS and
focus on styling our widget, this is just as important as creating the skeleton because this is
the skin of our widget. Let's open up our SprySideBar.css that we created in our SpryAssets
folder.</p>
<p>I will be discussing all required attributes of our widget, so this will help you understand the
working of it. Let's stop the blah blah and start working on our skin!</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBar {
 left:0px;
 <span class="category2">position</span>:absolute;
 <span class="category2">text</span>-<span class="category2">align</span>:left;
 top:140px;
}</pre>
</code>

</div></div>

<p>This is class of our container, I have positioned this absolute because this gives all of rock
solid freedom of positioning our widget, the left:0px; makes sure that the widget is on it's
absolute left side, top:140px; is the height of our widget, how much space from the top of
our widget to the top of the view port.</p>

<p>As we are using &lt;a&gt; tags in our widget, and we don't want the dotted outlines to be shown
when the users focus or clicks on it I have add:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBar a {outline:none;}</pre>
</code>

</div></div>

<p>This will remove all outlines from the &lt;a&gt; elements that are INSIDE of your container, all
other &lt;a&gt; element in your page will not be affected by this, that is the beauty and power
CSS.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarGroup{
 <span class="category2">background</span>-<span class="category2">color</span>:#F3F3F3;
 <span class="category2">border</span>:1px solid #CCCCCC;
 <span class="category2">min</span>-<span class="category2">height</span>:100px;
 float:left;
}</pre>
</code>

</div></div>

<p>There are no limitations for the background of the group, you can use an image or add a
simple background color with a nice border like I'm currently doing. The min-height
attribute makes sure that background doesn't become smaller than our tab button (which
I'm also going to give a height of 100px). The float:left allows us to place our tab button
next to our group.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarContent {
 display:none;
 <span class="category2">height</span>:150px;
 overflow:hidden !important;
 <span class="category2">width</span>:200px;
}</pre>
</code>

</div></div>

<p>The first thing that you might notice is the display:none attribute, this will hide our content
and allows us to show a closed default state of the widget when the page loads. In this class
u can customize the overall height and width of the widget. I have add overflow:hidden to
the class to make sure the content doesn't go outside our widget.</p>
<p><strong>NOTE:</strong> The next few classes are only needed if you are using the same menu as I am. They
are not required for the functionality of the widget.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarMenu h1 {
 <span class="category2">color</span>:#000;
 <span class="category2">font</span>:<span class="category2">bold</span> 110% arial;
 margin:10px;
}</pre>
</code>

</div></div>

<p>This gives my H1 a nice black color, I'm using a CSS shorthand for my font, this will save
me some file size and space, it's allot shorter than writing: font-weight:bold; fontsize:
110%; font-family:arial;, I also gave it a margin of 10px to give it some white space
around the text.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarMenu ul {
 margin:0px;
 padding:0px;
}</pre>
</code>

</div></div>

<p>Reset the margin and padding of our UL element to 0px;</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarMenu li {
 4
 <span class="category2">list</span>-style-<span class="category2">type</span>:none;
 margin:0px 10px 3px;
 padding:2px;
 <span class="category2">width</span>:170px;
}</pre>
</code>

</div></div>

<p>The list-style-style:none will hide the dot that is usually next to a list element, this will
make it look more like a menu instead of a list. The margin is used to give some extra space
between the items of the list, and padding gives is a bit bigger 'click able' target area (same
counts for the width:170px wich will allow users to click next to text and still hit the link!).</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideBarMenu ul li a:link, .SprySideBarMenu ul li a:visited {
 <span class="category2">color</span>:#000;
 display:block;
 <span class="category2">font</span>-family:verdana;
 <span class="category2">font</span>-<span class="category2">size</span>:100%;
 <span class="category2">text</span>-decoration:none;
}</pre>
</code>

</div></div>

<p>This is to style our &lt;a&gt; elements in side the &lt;li&gt;'s display:block will enable the big target area for us that we had set in our previous class) The rest doesn't require any extra words as they style our text, except for our text-decoration:none this will hide underline from the links.</p>

<p><strong>NOTE:</strong> The following CSS style is required for the widget again!</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideTab, .SprySideTab a{
 float:left;
 <span class="category2">height</span>:100px;
 <span class="category2">width</span>:25px;
 display:block;
 <span class="category2">border</span>:1px solid #CCCCCC;
 <span class="category2">background</span>-<span class="category2">color</span>:#F3F3F3;
 margin-left:-1px;
 <span class="category2">text</span>-decoration:none;
}</pre>
</code>

</div></div>

<p>Time finish up our CSS and style the last part of our widget, the tab! The float:left will place our tab next to our group. As a said a few styles back that I would set the height of the tab
100px; here it is. Together with the width:25px attribute we have created a nice block for
uses to click and activate our menu, display:block will make sure that they can press on the whole background to activate the widget. I gave it the same background and border as the
SprySideBarGroup so they match! I don't like having a double border on the left side so I
gave the tab a negative margin on the left side. This will slide the SprySlideTab a bit over
the group. And text-decoration:none; to hide the underline again.</p>

<p><strong>Note:</strong> if you wish to style indicator you can do this by adding styles to the following line:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
.SprySideTab a em{
 <span class="blockcomment">/* styles here */</span>
}</pre>
</code>

</div></div>

<h2>Part 3: Building the muscles of our widget!</h2>

<p>Yes, it's time to power our skeleton with the muscles of Spry! I already decided what effects I wanted to use for this widget, the effect Squish to move the sidebar, and Fade to fade in the menu's content.  can find allot pre-build Spry Effects in the Effects demo that you can find here: <a href="http://labs.adobe.com/technologies/spry/demos/effects/index.html">http://labs.adobe.com/technologies/spry/demos/effects/index.html</a>.</p>

<p>Instead of the Squish effect it's also possible to use the Slide effect. Just pick what you think works best for your widget.</p>

<p>Let's start off by creating the <script type='text/javascript'></script> tags. This helps the browsers to identify JavaScript from HTML codes. Inside our script tags we will begin with
setting up our effects.</p>

<p>You can set up effects with the following effect constructor:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> squish = <span class="category1">new</span> Spry.Effect.Squish('<span class="quote">example_content</span>',{options})</pre>
</code>

</div></div>

<p>This basicly means:<br/>
var (variable) variablename = new (a new effect) Spry.Effect.Squish(the effect
name)('Id_of_elemement',{effect options});</p>

<p>Let's set the options for our effect, the widget will be initially hidden with the display:none
that we have set in our CSS. This will allow us scale the widget from:'0%' to:'100%' in size.
We can even set how long much milliseconds the effect should take, and the duration of the
effect. We want to be able to toggle, open and close the effect. Now that we know our
options we can set the options for our effect.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
{from:'<span class="quote">0%</span>', to:'<span class="quote">100%</span>', <span class="category2">duration</span>:1000, toggle:<span class="category1">true</span>}</pre>
</code>

</div></div>

<p>And set these options in your constructor. The finished constructor should look like this:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> squish = <span class="category1">new</span> Spry.Effect.Squish('<span class="quote">example_content</span>',{from: '<span class="quote">0%</span>', to: '<span class="quote">100%</span>', <span class="category2">duration</span>:
 1000, toggle: <span class="category1">true</span>});</pre>
</code>

</div></div>

<p>We wanted to fade our content to, so we have to add another effect for that, the good thing
is we can use the same options for it and only have to switch effect name.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> fade = <span class="category1">new</span> Spry.Effect.Fade('<span class="quote">menu</span>',{from: '<span class="quote">0%</span>',to: '<span class="quote">100%</span>', <span class="category2">duration</span>: 1000, toggle:
 <span class="category1">true</span>});</pre>
</code>

</div></div>

<p>Now we have gotten our effects configured and attached to our required Id's, it's time to set
up our status indicators, Spry allows you set up Observers. The name already says it, to
observ the effect. Before the effect starts we want to change the content of our indicators
this is called onPreEffect. So let's set up our observer:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> myObserver = <span class="category1">new</span> <span class="category2">Object</span>;
myObserver.onPreEffect = <span class="category1">function</span>(effect){
};</pre>
</code>

</div></div>

<p>The variable myObserver is now an object. We have attached a function to the onPreEffect
value of our object. This function will recieve information about the effect with the effect
variable. Let's expand the function a bit more, if the effect is going forward (starting) we
want that the content of your &lt;em&gt; changes. Let's set up the effect direction first:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> myObserver = <span class="category1">new</span> <span class="category2">Object</span>;
myObserver.onPreEffect = <span class="category1">function</span>(effect){
 <span class="category1">if</span>(effect.direction == Spry.forwards)
 <span class="linecomment">//do something</span>
 <span class="category1">else</span>
 <span class="linecomment">//do something else</span>
};</pre>
</code>

</div></div>

<p>That would indicate the direction of the effect. Now we want to be able to access the our element, this where we are going to use our SpryDOMUtils. It has a nice short hand function to access our element: Spry.$('sideBarTab'). That will give us acces to the &lt;a&gt; element, but we want to acces the &lt;em&gt; element, you could attach ANOTHER id to that element but you can also access the element through the &lt;a&gt; element. you can see the HTML structure as a family with childeren, sibblings and parents. The &lt;a&gt; is the parent of &lt;em&gt; so that makes &lt;em&gt; the child of &lt;a&gt;. In JavaScript you can call this the FirstChild or ChildNode so Spry.$('sideBarTab').childNodes[0] would allow access to our &lt;em&gt;. With the .innerHTML attribute we can change the content of the &lt;em&gt;.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> myObserver = <span class="category1">new</span> <span class="category2">Object</span>;
myObserver.onPreEffect = <span class="category1">function</span>(effect){
 <span class="category1">if</span>(effect.direction == Spry.forwards)
 Spry.$('<span class="quote">sideBarTab</span>').<span class="category2">childNodes</span>[0].innerHTML = '<span class="quote">&gt;&gt;</span>';
 <span class="category1">else</span>
 Spry.$('<span class="quote">sideBarTab</span>').<span class="category2">childNodes</span>[0].innerHTML = '<span class="quote">&lt;&lt;</span>';
};</pre>
</code>

</div></div>

<p>You can attach the Observer to any effect you want, I'll be attaching it our content Squish effect,
You can attach it by using: effects_var_name.addObserver(myObserver);. Our complete script
should look like this:</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> squish = <span class="category1">new</span> Spry.Effect.Squish('<span class="quote">example_content</span>',{from: '<span class="quote">0%</span>', to: '<span class="quote">100%</span>', <span class="category2">duration</span>:
 1000, toggle: <span class="category1">true</span>});
<span class="category1">var</span> fade = <span class="category1">new</span> Spry.Effect.Fade('<span class="quote">menu</span>',{from: '<span class="quote">0%</span>',to: '<span class="quote">100%</span>', <span class="category2">duration</span>: 1000, toggle:
 <span class="category1">true</span>});
<span class="category1">var</span> myObserver = <span class="category1">new</span> <span class="category2">Object</span>;
myObserver.onPreEffect = <span class="category1">function</span>(effect){
 <span class="category1">if</span>(effect.direction == Spry.forwards)
 Spry.$('<span class="quote">sideBarTab</span>').<span class="category2">childNodes</span>[0].innerHTML = '<span class="quote">&gt;&gt;</span>';
 <span class="category1">else</span>
 Spry.$('<span class="quote">sideBarTab</span>').<span class="category2">childNodes</span>[0].innerHTML = '<span class="quote">&lt;&lt;</span>';
};
squish.addObserver(myObserver);</pre>
</code>

</div></div>

<p>Now we want to attach the effects to the SprySideBarTab, when a user clicks on it the effect
gets activated we will be using addEventListener and addLoadListener for this. The
addEventLister will allow us to attach a function to a certain element without having to write
any in line JavaScript. We going to start with setting up our AddLoadListener</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
Spry.Utils.addLoadListener(<span class="category1">function</span>(){
});</pre>
</code>

</div></div>

<p>All load listeners require a function inside. you can create a new function outside the
Loadlistener or declare a function inside it. If you declare it outside the listener you can still
access it normally by calling the function name, if you declare it inside the listener you wont be
able to call the function again, unless the page reloads. As you can see I created a function
inside of it as there is no need to access it again. Within this function we are going to place
our EventListener, the same function concept counts here to.</p>
<p><strong>Note:</strong> If you add a function outside of the listeners, make sure you don't execute the code within
it. So leave the () out of the function name.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
Spry.Utils.addEventListener("<span class="quote">sideBarTab</span>", "<span class="quote">click</span>", <span class="category1">function</span>(){
 squish.<span class="category2">start</span>();
 fade.<span class="category2">start</span>();
}, <span class="category1">false</span>);</pre>
</code>

</div></div>

<p>That is how our EventListener should look like: Spry.Utils.addEventListener('id of the
element','eventtype',function,capture); for the function I'm using a in line function again.
Within in this function I have add the start commands for our effects.
var_name_of_effect.start(); place the EventListener inside the LoadListener and we are
done.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
Spry.Utils.addLoadListener(<span class="category1">function</span>(){
 Spry.Utils.addEventListener("<span class="quote">sideBarTab</span>", "<span class="quote">click</span>", <span class="category1">function</span>(){
  squish.<span class="category2">start</span>();
  fade.<span class="category2">start</span>();
 }, <span class="category1">false</span>);
});</pre>
</code>

</div></div>

<p>Load your page and it should work properly if you followed my steps correctly! If you click on
the Tab button the menu appears and Squishes in full position and the menu gets faded in.
This is the end of the basic part of creating your side bar widget, in the next part of this
article I will show you how to make the animation a bit smoother, clean up your code, and
only require ONE id to power up this widget! And in the last part will describe some basic
tweaks for the scripts, to improve it even more!</p>

<p>In part 2 we are going to evolve the widget, making it more powerful, unobstructive and easier to use. 
We will replace the Spry Effects and make it in to a effect cluster. I will also give you some tips and 
show how to tackle some potential issues.</p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.33651-comment:2058784</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.33651" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html#comment-2058784" />
    <title>Comment from Andrea Moro on 2009-05-03</title>
    <author>
        <name>Andrea Moro</name>
        <uri>http://blog.teammatelabs.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://blog.teammatelabs.com">
        <![CDATA[<p>Hi Arnout</p>

<p>thanks for sharing your code with the community. I'm starting to look at Spry, and your tutorial is very useful.</p>

<p>Regards<br />
Andrea</p>]]>
    </content>
    <published>2009-05-03T13:10:04Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.33651-comment:2144548</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.33651" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html#comment-2144548" />
    <title>Comment from Niki Sen on 2009-10-17</title>
    <author>
        <name>Niki Sen</name>
        <uri>http://www.adsguard.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.adsguard.com">
        <![CDATA[<p>very useful tutorial & thanks for sharing your code with the community</p>]]>
    </content>
    <published>2009-10-18T04:21:43Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.33651-comment:2170510</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.33651" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/02/creating-your-own-side-bar-wid.html#comment-2170510" />
    <title>Comment from Jeff on 2009-11-03</title>
    <author>
        <name>Jeff</name>
        <uri>http://na.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://na.com">
        <![CDATA[<p>How would you make the effect go from right to left so it could be on the right hand side of the page?</p>]]>
    </content>
    <published>2009-11-03T22:45:07Z</published>
  </entry>

</feed
