<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The html blog &#187; collapse</title>
	<atom:link href="http://htmlblog.net/tag/collapse/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<lastBuildDate>Tue, 09 Nov 2010 11:39:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Show/hide containers by only adding CSS classes without writing javascript code (YUI-based)</title>
		<link>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/</link>
		<comments>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 07:37:49 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[collapse]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=34</guid>
		<description><![CDATA[This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it&#8217;s all YUI-based and also a demo of the fantastic YUI selector utility. What does the script do ? OK, [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it&#8217;s all YUI-based and also a demo of the fantastic <a href="http://developer.yahoo.com/yui/selector/">YUI selector utility</a>.</p>
<p><span id="more-34"></span></p>
<h3>What does the script do ?</h3>
<p>OK, suppose you have a FAQ page where you have traditional anchor methods, i.e you click on the question and then you go to the bottom of the page to get the answer or you get redirected to another page. But now your users are complaining your site&#8217;s not trendy enough and want to have the answer displayed immediately after clicking the question.</p>
<h3>The solution.</h3>
<p>After downloading the javascript file, include it at the bottom of your page with the following HTML code:</p>
<pre class="brush: xhtml">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/selector/selector-beta-min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/toggler.js&quot;&gt;&lt;/script&gt;
</pre>
<p>We need to include the <a href="http://developer.yahoo.com/yui/selector/">selector utility</a> which will be used to retrieve a collection of elements that match a given CSS selector. For e.g if we want to retrieve all div nodes in HTML page having the class &#8220;foo&#8221;, we can write :</p>
<pre class="brush: javascript">
var myNodes = YAHOO.util.Selector.query(&#039;div.foo&#039;);
</pre>
<p>The selector is used in the toggler.js file.</p>
<p>After adding the scripts, now you have to add CSS classes to your containers. For example for the FAQ, for questions (or main, call it whatever you want), you add the class &#8220;htmlblog-main&#8221; and for the answers (or sub), add the &#8220;htmlblog-sub&#8221; class.</p>
<p>Before :</p>
<pre class="brush: xhtml">
&lt;div&gt;1. Question&lt;/div&gt;
&lt;div&gt;Answer1&lt;/div&gt;
&lt;div&gt;2. Question 2&lt;/div&gt;
&lt;div&gt;Answer 2&lt;/div&gt;
</pre>
<p>After :</p>
<pre class="brush: xhtml">
&lt;div class=&quot;htmlblog-main&quot;&gt;1. Question&lt;/div&gt;
&lt;div class=&quot;htmlblog-sub&quot;&gt;Answer1&lt;/div&gt;
&lt;div class=&quot;htmlblog-main&quot;&gt;2. Question 2&lt;/div&gt;
&lt;div class=&quot;htmlblog-sub&quot;&gt;Answer 2&lt;/div&gt;
</pre>
<p>If you already had a class for that container, no problem you can add the htmlblog-main or htmlblog-sub class :</p>
<pre class="brush: xhtml">
&lt;div class=&quot;myclass htmlblog-main&quot;&gt;1. Question&lt;/div&gt;
</pre>
<h3>What next ? </h3>
<p>That&#8217;s all ! All your answer containers will be hidden and questions will have a [+] besides them. Pretty easy</p>
<h3>Am I obliged to use the htmlblog-main and html-sub classes ? And I don&#8217;t want to use div tags, I want li tags.</h3>
<p>Don&#8217;t worry, if you don&#8217;t like the class names you can put whatever you want but you&#8217;ll have to edit the toggler.js file at the following lines :</p>
<pre class="brush: javascript">
YAHOO.util.Event.addListener(window, &#039;load&#039;, function(){
	YAHOO.htmlblog.init(&#039;div&#039;, &#039;htmlblog-main&#039;, &#039;htmlblog-sub&#039;);
});
</pre>
<p>For e.g, if you&#8217;re using li tags instead of divs with the &#8220;myMainClass&#8221; as main and &#8220;mySubClass&#8221; as sub, the code goes :</p>
<pre class="brush: javascript">
YAHOO.util.Event.addListener(window, &#039;load&#039;, function(){
	YAHOO.htmlblog.init(&#039;li&#039;, &#039;myMainClass&#039;, &#039;mySubClass&#039;);
});
</pre>
<h3>I&#8217;am getting an alert saying &#8220;Number of main and subs incorrect&#8221;.</h3>
<p>That means the number of main/subs are not the same. You need to have the number of the main class equals the number of the sub class.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expanding/collapsing javascript menu</title>
		<link>http://htmlblog.net/expanding-collapsing-javascript-menu/</link>
		<comments>http://htmlblog.net/expanding-collapsing-javascript-menu/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 18:07:13 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[collapse]]></category>
		<category><![CDATA[dav glass]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[newbie]]></category>
		<category><![CDATA[slashdot]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=22</guid>
		<description><![CDATA[In this post I&#8217;ll show you how to create an expanding/collapsing menu like Slashdot left menu used to be, using the YUI library and Dav Glass YUI effects widget. The HTML markup for our menu is : &#60;div id=&#34;menu&#34;&#62; &#60;h1 id=&#34;menu-title&#34;&#62;Menu&#60;/h1&#62; &#60;div id=&#34;menu-links&#34;&#62; &#60;ul&#62; &#60;li&#62;Home&#60;/li&#62; &#60;li&#62;About&#60;/li&#62; &#60;li&#62;CSS&#60;/li&#62; &#60;/ul&#62; &#60;/div&#62; &#60;/div&#62; We use 2 div tags, [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll show you how to create an expanding/collapsing menu like <a href="http://slashdot.org">Slashdot</a> left menu used to be, using the <a href="http://developer.yahoo.com/yui">YUI library</a> and <a href="http://blog.davglass.com/">Dav Glass</a> <a href="http://blog.davglass.com/files/yui/effects/">YUI effects widget</a>.</p>
<p><span id="more-22"></span><br />
The HTML markup for our menu is :</p>
<pre class="brush: xhtml">
&lt;div id=&quot;menu&quot;&gt;
			&lt;h1 id=&quot;menu-title&quot;&gt;Menu&lt;/h1&gt;
			&lt;div id=&quot;menu-links&quot;&gt;
				&lt;ul&gt;
					&lt;li&gt;Home&lt;/li&gt;
					&lt;li&gt;About&lt;/li&gt;
					&lt;li&gt;CSS&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/div&gt;
		&lt;/div&gt;
</pre>
<p>We use 2 <strong>div</strong> tags, one for holding the menu itself and the other one which contains the links in an <strong>unordered list</strong> and 1 <strong>h1</strong> tag for the title.</p>
<p>The CSS for the menu :</p>
<pre class="brush: css">
/** width of the menu */
#menu{
				width: 180px;
			}

/** the main title */
			#menu h1{
				line-height: 35px;
				color: #fff;
				/** simulate link */
				cursor: pointer;
				font-weight: bold;
				/** background image will change when menu expands/collapses */
				background: #666 url(images/block-arrow-expanded.gif) no-repeat scroll 30px 13px;
			}

/** the links */
			#menu-links li{
				line-height: 35px;
				border-bottom:1px solid #ddd;
				background-color: #eee;
			}
</pre>
<p>Please pay attention to the background for the #menu h1. It contains the image, which will change when the menu collapses or expands. When the menu collapses we&#8217;ll be using the block-arrow-collapsed.gif image and when the menu expands we&#8217;ll be using the block-arrow-expanded.gif image. You can find the images in the <a href="http://htmlblog.net/demo/yui-menu-slashdot/yui-menu.zip">sample demo file</a> in the images directory.</p>
<p>To do the collapsing/expanding effects, we need to include the following javascript files beforehand :</p>
<pre class="brush: xhtml">
&lt;!-- js --&gt;
&lt;script type=&quot;text/javascript&quot;  src=&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/animation/animation-min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/tools-min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/effects-min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>We use Dav Glass <a href="http://blog.davglass.com/files/yui/tools/">YAHOO.Tools package</a> and his <a href="http://blog.davglass.com/files/yui/effects/">effects widget</a> along with yahoo-dom-event-animation <a href="http://yuiblog.com/blog/2008/07/16/combohandler/">aggregate file</a> which are hosted on Yahoo servers.</p>
<p>Finally the javascript to do the magical stuff goes like that :</p>
<pre class="brush: javascript">
&lt;script type=&quot;text/javascript&quot;&gt;
			YAHOO.util.Event.addListener(&#039;menu-title&#039;, &#039;click&#039;, function(){
				if(YAHOO.util.Dom.getStyle(&#039;menu-links&#039;, &#039;display&#039;) == &#039;block&#039;){
					new YAHOO.widget.Effects.BlindUp(&#039;menu-links&#039;, {seconds: 0.2});
					YAHOO.util.Dom.setStyle(&#039;menu-title&#039;, &#039;background-image&#039;, &#039;url(images/block-arrow-collapsed.gif)&#039;);
				}
				else{
					new YAHOO.widget.Effects.BlindDown(&#039;menu-links&#039;, {seconds: 0.2});
					YAHOO.util.Dom.setStyle(&#039;menu-title&#039;, &#039;background-image&#039;, &#039;url(images/block-arrow-expanded.gif)&#039;);
				}
			});
		&lt;/script&gt;
</pre>
<p>In line 3 of the above listing, we wait when the user clicks on the menu-title container and we check the display attribute of our links. If the links are not currently displayed then we display them by using Dav&#8217;s <a href="http://blog.davglass.com/files/yui/docs/?type=effects">BlindDown effect</a> with a duration of 0.2 seconds ;-).</p>
<pre class="brush: javascript">
new YAHOO.widget.Effects.BlindDown(&#039;menu-links&#039;, {seconds: 0.2});
</pre>
<p>We also change the background image for the menu title by using the <a href="http://developer.yahoo.com/yui/dom">YAHOO.util.Dom.setStyle</a> method:</p>
<pre class="brush: javascript">

YAHOO.util.Dom.setStyle(&#039;menu-title&#039;, &#039;background-image&#039;, &#039;url(images/block-arrow-expanded.gif)&#039;);
</pre>
<p>If the links are visible then we do the contrary, i.e we use the BlindUp effect and use the collapsed gif as background image.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/expanding-collapsing-javascript-menu/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

