<?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>eklog &#187; JavaScript</title>
	<atom:link href="http://www.ekstasis.net/log/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ekstasis.net/log</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 29 Nov 2011 16:15:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scrolling overlays</title>
		<link>http://www.ekstasis.net/log/javascript/scrolling-overlays.html</link>
		<comments>http://www.ekstasis.net/log/javascript/scrolling-overlays.html#comments</comments>
		<pubDate>Sun, 20 Nov 2011 00:00:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=601</guid>
		<description><![CDATA[If you have pop-up overlays with content that necessitates scrollbars, there&#8217;s no scrollbar functionality when viewed on a mobile phone. If you feel the finger drag functionality is not obvious enough, you can add up and down buttons to assist with the scrolling. The jQuerires: The CSS: The HTMLs: See example:]]></description>
			<content:encoded><![CDATA[<p>If you have pop-up overlays with content that necessitates scrollbars, there&#8217;s no scrollbar functionality when viewed on a mobile phone. If you feel the finger drag functionality is not obvious enough, you can add up and down buttons to assist with the scrolling.</p>
<p>The jQuerires:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function() {
	$('.pagination').children().wrapAll('&lt;div class=&quot;content&quot;/&gt;;');
	$('.next').click(function() {
		moveContent($('.pagination').scrollTop() + $('.pagination').height() - 9);
	});
	$('.previous').click(function() {
		moveContent($('.pagination').scrollTop() - $('.pagination').height() + 9);
	});
	function moveContent(newTop) {
		$('.pagination').scrollTop(newTop);
	}
});
</pre>
<p>The CSS:</p>
<pre class="brush: css; title: ; notranslate">
.pagination {
     width: 300px;
     height: 300px;
     overflow: hidden;
     position:relative;
     border: 1px solid #eee;
     padding: 5px;
}
.content {
    position:absolute;
}
.next, .previous {
    color: black;
    background: #D6D6D6;
    padding: 5px;
    cursor: pointer;
}
</pre>
<p>The HTMLs:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;span class=&quot;next&quot;&gt;next&lt;/span&gt;
&lt;span class=&quot;previous&quot;&gt;previous&lt;/span&gt;

&lt;div class=&quot;pagination&quot;&gt;
&lt;h1&gt;Whatever&lt;/h1&gt;
&lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus&lt;/p&gt;
&lt;/div&gt;
</pre>
<p>See example:<br />
<iframe style="width: 100%; height: 300px;" src="http://jsfiddle.net/matsstuff/4pPQU/1/embedded/result/" frameborder="0" width="320" height="240"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/scrolling-overlays.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Styling drop-downs</title>
		<link>http://www.ekstasis.net/log/css/select-styling.html</link>
		<comments>http://www.ekstasis.net/log/css/select-styling.html#comments</comments>
		<pubDate>Wed, 02 Nov 2011 19:07:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=541</guid>
		<description><![CDATA[Here&#8217;s how to style the options for a select drop-down. It uses some javaScript to add a class to the select options to match each option, and to add the selected option&#8217;s class to the select element itself. The CSS: The jQueries:]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how to style the options for a select drop-down. It uses some javaScript to add a class to the select options to match each option, and to add the selected option&#8217;s class to the select element itself.</p>
<p>The CSS:</p>
<pre class="brush: css; title: ; notranslate">
.store-countries {
    padding-left: 20px;
    background-position: 4px 2px;
    background-repeat: no-repeat;
}
.store-countries option {
    padding: 0 0 0 24px;
    background-position: 2px 4px;
    background-repeat: no-repeat;
}
.store-countries option.Belgium {
    background-image: url(../images/icons/flags/be.gif);
}
.store-countries option.France {
    background-image: url(../images/icons/flags/fr.gif);
}
.store-countries option.Germany {
    background-image: url(../images/icons/flags/de.gif);
}
</pre>
<p>The jQueries:</p>
<pre class="brush: jscript; title: ; notranslate">
function dropDownCountries() {
    $('.store-countries').find('option').each(function() {
        var country = $j(this).val();
        $(this).addClass(country);
    });

    var selectedFlag = $('.store-countries').find('option:selected').css('background-image');
    $('.store-countries').css('background-image',selectedFlag)

    $('.store-countries').change( function() {
        var selectedFlag = $('.store-countries').find('option:selected').css('background-image');
        $('.store-countries').css('background-image',selectedFlag)
    });
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/css/select-styling.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Highlight current page</title>
		<link>http://www.ekstasis.net/log/javascript/highlight-current-page.html</link>
		<comments>http://www.ekstasis.net/log/javascript/highlight-current-page.html#comments</comments>
		<pubDate>Tue, 25 Oct 2011 18:11:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=526</guid>
		<description><![CDATA[Here&#8217;s a handy script to highlight a menu link when the link&#8217;s URL matches the current location (i.e. the browser&#8217;s address bar url). You create regexp to match current url pathname and remove trailing slash if present (as it could collide with the link in navigation in case trailing slash wasn&#8217;t present there.) Then grab [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy script to highlight a menu link when the link&#8217;s URL matches the current location (i.e. the browser&#8217;s address bar url).</p>
<p>You create regexp to match current url pathname and remove trailing slash if present (as it could collide with the link in navigation in case trailing slash wasn&#8217;t present there.)</p>
<p>Then grab every link from the navigation and test its normalized href against the url pathname regexp and add a classname &#8216;current&#8217; if it matches.</p>
<pre class="brush: jscript; title: ; notranslate">
function menuCurrentHighlight(){
    var url = window.location.pathname,
    urlRegExp = new RegExp(url.replace(/\/$/,'') + &quot;$&quot;);
	/* create regexp to match current url pathname and remove trailing slash if present: */
    if( $('ul a').length&gt;0 ) {
	    $('ul a').each(function(){
		// test its normalized href against the url pathname regexp
		if(urlRegExp.test(this.href.replace(/\/$/,''))){
		    $(this).addClass('current');
		}
	    });
	};
};
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/highlight-current-page.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More jQuery snippets</title>
		<link>http://www.ekstasis.net/log/javascript/morejquery-snippets.html</link>
		<comments>http://www.ekstasis.net/log/javascript/morejquery-snippets.html#comments</comments>
		<pubDate>Sat, 15 Oct 2011 18:31:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=529</guid>
		<description><![CDATA[Inject HTMLs: Chaining: Create a function: Check for something: Find a Selected Phrase and Manipulate It: Add Pseudo-Selector Support in IE: Manage Search Box Values: Easily Respond to Event Data: jQuery passes an event parameter into all bound/triggered functions, which is commonly called e: Encode HTML Entities: Open External Links in a New Window: How [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: jscript; title: ; notranslate">
function onLoadDoThis() {
    alert('Page is loaded!');
}
$(document).ready(onLoadDoThis);
// $(onLoadDoThis); is the same thing
</pre>
<p><br/><br />
<hr/><br/></p>
<pre class="brush: jscript; title: ; notranslate">
//Instead of
$(document).ready(function() {
    //document ready
});
//Use
$(function(){
    //document ready
});
</pre>
<pre class="brush: jscript; title: ; notranslate">
//To run the script before the DOM has loaded (&amp; without $ conflict):
(function($){
	...
})(jQuery);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Inject HTMLs:</p>
<pre class="brush: jscript; title: ; notranslate">
var myList = $('.myList');
var myListItems = '&lt;ul&gt;';

for (i = 0; i &lt; 1000; i++) {
    myListItems += '&lt;li&gt;This is list item ' + i + '&lt;/li&gt;';
}

myListItems += '&lt;/ul&gt;';
myList.html(myListItems);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Chaining:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#myTable')
    .find('.firstColumn')
        .css('background','red')
    .end()
    .find('.lastColumn')
        .css('background','blue');
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Create a function:</p>
<pre class="brush: jscript; title: ; notranslate">
$.fn.makeRed = function() {
    return $(this).css('background', 'red');
}

$('#myTable').find('.firstColumn').makeRed().append('hello');
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Check for something:</p>
<pre class="brush: jscript; title: ; notranslate">
if( $(&quot;.active&quot;).length != 0 ){
	//Now the code here will only be executed if there is at least one active element
}
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Find a Selected Phrase and Manipulate It:</p>
<pre class="brush: jscript; title: ; notranslate">
//First define your search string, replacement and context:
var phrase = &quot;your search string&quot;;  var replacement = &quot;new string&quot;;
var context = $(body);

context.html(
	context.html().replace('/'+phrase+'/gi', replacement);
);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Add Pseudo-Selector Support in IE:</p>
<pre class="brush: jscript; title: ; notranslate">
//add hover support:
function hoverOn(){
	var currentClass = $(this).attr('class').split(' ')[0]; //Get first class name
	$(this).addClass(currentClass + '-hover');
}
function hoverOff(){
	var currentClass = $(this).attr('class').split(' ')[0]; //Get first class name
	$(this).removeClass(currentClass + '-hover');
}
$(&quot;.nav-item&quot;).hover(hoverOn,hoverOff);

//add first-child support:
jQuery.fn.firstChild = function(){
	return this.each(function(){
		var currentClass = $(this).attr('class').split(' ')[0]; //Get first class name
		$(this).children(&quot;:first&quot;).addClass(currentClass + '-first-child');
	});
}
$(&quot;.searchform&quot;).firstChild();
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Manage Search Box Values:</p>
<pre class="brush: jscript; title: ; notranslate">
//set default value:
$(&quot;#searchbox&quot;)
	.val('search?');
	.focus(function(){this.val('')})
	.blur(function(){
		(this.val() === '')? this.val('search?') : null;
	});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Easily Respond to Event Data: jQuery passes an event parameter into all bound/triggered functions, which is commonly called e:</p>
<pre class="brush: jscript; title: ; notranslate">
//We can get X/Y coordinates on click events:
$(&quot;a&quot;).click(function(e){
	var clickX = e.pageX;
	var clickY = e.pageX;
});

//Or detect which key was pressed:
$(&quot;window&quot;).keypress(function(e){
	var keyPressed = e.which;
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Encode HTML Entities:</p>
<pre class="brush: jscript; title: ; notranslate">
var text = $(&quot;#someElement&quot;).text();
var text2 = &quot;Some &lt;code&gt; &amp; such to encode&quot;;
//you can define a string or get the text of an element or field

var html = $(text).html();
var html2 = $(text2).html();
//Done - html and html2 now hold the encoded values!
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Open External Links in a New Window:</p>
<pre class="brush: jscript; title: ; notranslate">
$('a[rel$='external']').click(function(){
	this.target = &quot;_blank&quot;;
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>How to tell when images have loaded:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#myImage').attr('src', 'image.jpg').load(function() {
    alert('Image Loaded');
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Creating an HTML Element and keeping a reference</p>
<pre class="brush: jscript; title: ; notranslate">
var newDiv = $(&quot;&lt;div /&gt;&quot;);

newDiv.attr(&quot;id&quot;, &quot;myNewDiv&quot;).appendTo(&quot;body&quot;);

/* Now whenever I want to append the new div I created,
   I can just reference it from the &quot;newDiv&quot; variable */

var e = $(&quot;&lt; a /&gt;&quot;, { href: &quot;#&quot;, class: &quot;a-class another-class&quot;, title: &quot;...&quot;, css: {
        color: &quot;#FF0000&quot;,
        display: &quot;block&quot;
    }});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Nesting Filters:</p>
<pre class="brush: jscript; title: ; notranslate">
.filter(&quot;:not(:has(.selected))&quot;)
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Toggle states:</p>
<pre class="brush: jscript; title: ; notranslate">
function onState(){
    // do something
}

function offState(){
    // do something else
}

$('div').toggle( offState, onState );
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Preventing an animation from repeating:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;#someElement&quot;).hover(function(){
    $(&quot;div.desc&quot;, this).stop(true,true).fadeIn();
},function(){
    $(&quot;div.desc&quot;, this).fadeOut();
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Preloading images:</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery.preloadImages = function()
{
  for(var i = 0; i&quot;).attr(&quot;src&quot;, arguments[i]);
  }
};

// Usage
$.preloadImages(&quot;image1.gif&quot;, &quot;/path/to/image2.png&quot;, &quot;some/image3.jpg&quot;);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Timer callback functions:</p>
<pre class="brush: jscript; title: ; notranslate">
window.setTimeout(function() {
 $('#id').empty();
}, 1000);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Adding to the width with every click:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;#box&quot;).one( &quot;click&quot;, function () {
    $( this ).css( &quot;width&quot;,&quot;+=200&quot; );
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Calculate which element is the highest:</p>
<pre class="brush: jscript; title: ; notranslate">
    var t=0;
    var t_elem;
    var elem = $('.whattever');
    $(&quot;*&quot;,elem).each(function () {
	$this = $(this);
	if ( $this.outerHeight() &gt; t ) {
	    t_elem=this;
	    t=$this.outerHeight();
	}
    });
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Using jQuery for browser sniffing:</p>
<pre class="brush: jscript; title: ; notranslate">
if ($.browser.mozilla &amp;&amp; $.browser.version.indexOf('1.8.') &gt; -1) {
  $('body').addClass('ff2');
}

// add a body class for firefox 3.0 only
if($.browser.mozilla &amp;&amp; $.browser.version.substr(0,5)==&quot;1.9.0&quot;) {
  $('body').addClass('ff3');
}
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Increment or decrease an input quantity with plus &#038; minus &#8216;buttons&#8217;:</p>
<pre class="brush: jscript; title: ; notranslate">
function changeProductQuantity() {
        $('#form1').find(&quot;.plus&quot;).click(function(e)
	{
	    e.preventDefault();
            var currentVal = parseInt($('#form1').find('#qty').val());
            if (currentVal != NaN)
            {
                $('#form1').find('#qty').val(currentVal + 1);
            }
        });

        $('#product_addtocart_form').find('.minus').click(function(e)
	{
	    e.preventDefault();
            var currentVal = parseInt($('#form').find('#qty').val());
            if (currentVal != NaN &amp;&amp; currentVal &gt; 0)
            {
                $('#form1').find('#qty').val(currentVal - 1);
            }
        });
};
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Basic JSON:</p>
<pre class="brush: jscript; title: ; notranslate">
var json = [
    { &quot;red&quot;: &quot;#f00&quot; },
    { &quot;green&quot;: &quot;#0f0&quot; },
    { &quot;blue&quot;: &quot;#00f&quot; }
];

$.each(json, function() {
  $.each(this, function(name, value) {
    /// do stuff
    console.log(name + '=' + value);
  });
});
//outputs: red=#f00 green=#0f0 blue=#00f
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Example of using an argument:</p>
<pre class="brush: jscript; title: ; notranslate">
function showHeight(ele, h) {
      $(&quot;div&quot;).text(&quot;The height for the &quot; + ele +
                    &quot; is &quot; + h + &quot;px.&quot;);
    }
    $(&quot;#getp&quot;).click(function () {
      showHeight(&quot;paragraph&quot;, $(&quot;p&quot;).height());
    });
    $(&quot;#getd&quot;).click(function () {
      showHeight(&quot;document&quot;, $(document).height());
    });
    $(&quot;#getw&quot;).click(function () {
      showHeight(&quot;window&quot;, $(window).height());
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/morejquery-snippets.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scroll to show more</title>
		<link>http://www.ekstasis.net/log/javascript/scroll-to-show-more.html</link>
		<comments>http://www.ekstasis.net/log/javascript/scroll-to-show-more.html#comments</comments>
		<pubDate>Tue, 11 Oct 2011 20:24:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=561</guid>
		<description><![CDATA[This handy script allows you to show/hide a div. - if the revealed div content appears &#8216;below&#8217; the bottom of the browser window &#8211; i.e normally part of the div would not appear inside the fold &#8211; the page is scrolled up so that as much as possible of the div is displayed. - it [...]]]></description>
			<content:encoded><![CDATA[<p>This handy script allows you to show/hide a div.<br />
- if the revealed div content appears &#8216;below&#8217; the bottom of the browser window &#8211; i.e normally part of the div would not appear inside the fold &#8211; the page is scrolled up so that as much as possible of the div is displayed.<br />
- it uses {height: 0} to ensure SEO spiders don&#8217;t penalise hidden text.</p>
<p>To activate:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
	expandableInfo('hiddenInfo', 'activation-button');
});
</pre>
<p>*where #hiddenInfo is the ID of the div to be revealed and #activation-button is the ID of the link to reveal the extra content.</p>
<pre class="brush: jscript; title: ; notranslate">
var currentPos = null;

function expandableInfo(moreId, moreButton){
    var moreDivID = $('#'+moreId); //Id of expandable content div
    var moreButtonId = $('#'+moreButton); //Id of button for this content div
    var moreTextLink = $(moreButtonId).text(); //Link Text
    var moreHeight = moreDivID.height(); // Get the height of expandable content div

	//Set the expandable content height to 0 / Hidden!
        moreDivID.css({ height : 0 });

	//Scroll down past the header
	function scrollWinDown(){

		currentPos = $('html,body').scrollTop(); //Store Current position before we scroll
		var divPos = $(moreDivID).offset().top; // Position of div from top
		var buttonPos = $(moreButtonId).offset().top; //Position of button from top
		var amountToScroll = buttonPos - 50; // Distance to Scroll

		if ($(window).height() &gt; divPos + moreHeight &amp;&amp; currentPos ===0){
			//console.log('no need to scroll you!');
		}else{
			if (currentPos === 0){ //If user hasnt scrolled yet
				$('html,body').animate({scrollTop: moreHeight}, 500); //Move just the height of the div
			}else{
				$('html,body').animate({scrollTop: amountToScroll}, 500); // Move to the top of button
			}
		}
	}

	//Scroll down upto the header
	function scrollWinUp(){
		$('html,body').animate({scrollTop: currentPos}, 500); //Take user back to where they were
	}

	//More open and close functionality
	$(moreButtonId).click(
            function(){
                    if(moreDivID.hasClass('open')) // If the content is already on display
                    {
                            moreDivID.stop().animate({ height: 0 });  //hide it
                            moreDivID.removeClass('open'); // and remove the class
                            $(this).text(moreTextLink); // and change the text back
                            scrollWinUp();
			    return false;
                    }else{ // Otherwise
                            moreDivID.stop().animate({ height: moreHeight }); //Show the div
                            moreDivID.addClass('open'); //add the class
                            $(this).text('Close'); // change the text
			    scrollWinDown();
                            return false;
                    }
            }

    );

}
</pre>
<p>This code was devised by <a href="http://www.hannahstothard.co.uk/">Hannah</a>. Amazing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/scroll-to-show-more.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Javascript Show Hide</title>
		<link>http://www.ekstasis.net/log/javascript/simple-javascript-show-hide.html</link>
		<comments>http://www.ekstasis.net/log/javascript/simple-javascript-show-hide.html#comments</comments>
		<pubDate>Sat, 01 Oct 2011 22:30:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=217</guid>
		<description><![CDATA[This snippet will show / hide content and change the link or button text. If javascript is turned off the content is displayed. It is helpful to set the cursor to pointer, underline the span and add a hove effect with CSS to aid usability. An alternative method, to stop the initial flash of content, [...]]]></description>
			<content:encoded><![CDATA[<p>This snippet will show / hide content and change the link or button text. If javascript is turned off the content is displayed.</p>
<pre class="brush: jscript; title: ; notranslate">[/javascript]
function toggleText(id) {
	$('#toggleText').hide();
	$('#displayText').click(function() {
		$('#toggleText').slideToggle();
		var text = $j(this).text() == 'View the content' ? 'Hide the content' : 'View the content';
		$(this).text(text);
	});
}
1</pre>
<pre class="brush: xml; title: ; notranslate">
&lt;p id=&quot;toggleText&quot;&gt;Lorem ipsum, flotsum jetsum, and then some blah blah blah&lt;/p&gt;

&lt;span id=&quot;displayText&quot;&gt;Hide info&lt;/span&gt;
</pre>
<p>It is helpful to set the cursor to pointer, underline the span and add a hove effect with CSS to aid usability. An alternative method, to stop the initial flash of content, would be to use a link instead of a span (with return false or e.preventDefault in the javascript) and set the #displayText to display: none with CSS. The link would take the user to the content in a separate page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/simple-javascript-show-hide.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checkbox link</title>
		<link>http://www.ekstasis.net/log/css/checkbox-link.html</link>
		<comments>http://www.ekstasis.net/log/css/checkbox-link.html#comments</comments>
		<pubDate>Wed, 07 Sep 2011 21:15:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=573</guid>
		<description><![CDATA[Turning a checkbox into a &#8216;clickable&#8217; label 1. Wrap the checkbox in a label: 2: Hide the checkbox and style the label: 3. Check the box when the label is clicked:]]></description>
			<content:encoded><![CDATA[<p>Turning a checkbox into a &#8216;clickable&#8217; label</p>
<p>1. Wrap the checkbox in a label:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label&gt;Save for later &lt;input type=&quot;checkbox&quot; value=&quot;1&quot; name=&quot;list&quot; class=&quot;checkbox&quot; /&gt;&lt;/label&gt;
</pre>
<p>2: Hide the checkbox and style the label:</p>
<pre class="brush: css; title: ; notranslate">
.save-for-later {
	cursor: pointer;
}
.save-for-later input {
	display: none;
}
.checked {
	text-shadow: 1px -1px 1px rgba(68,68,68,0.4);
	position: relative;
	top: 1px;
	left: 1px;
}
</pre>
<p>3. Check the box when the label is clicked:</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery(function() {
    labelCheck();
});

function labelCheck() {
    $(&quot;#container .save-for-later&quot;).each( function(){
	$(this).find('input:checkbox').change(function() {
	    $(this).parent().toggleClass('checked');
	});
    });
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/css/checkbox-link.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery snippets</title>
		<link>http://www.ekstasis.net/log/javascript/jquery-snippets-2.html</link>
		<comments>http://www.ekstasis.net/log/javascript/jquery-snippets-2.html#comments</comments>
		<pubDate>Mon, 22 Aug 2011 21:09:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=567</guid>
		<description><![CDATA[Alter the first paragraph: Count list: Using the .hover() method: Change dimensions of an element: $(this) refers to all jQuery objects while this refers to the calling object in javascript. For example, we want to use .each and fadeIn() of jQuery after a selector such as below, since fadeIn() is a jQuery effect function, we [...]]]></description>
			<content:encoded><![CDATA[<p>Alter the first paragraph:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;h2 + p&quot;).addClass(&quot;Large&quot;);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Count list:</p>
<pre class="brush: jscript; title: ; notranslate">
var myList = $('.myList');

for (i = 0; i &lt; 1000; i++) {
    myList.append('This is list item ' + i);
}
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Using the .hover() method:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;p&quot;).hover(function () {
    $(this).css({'background-color' : 'yellow', 'font-weight' : 'bolder'});
}, function () {
    var cssObj = {
      'background-color' : '#ddd',
      'font-weight' : '',
      'color' : 'blue'
    }
    $(this).css(cssObj);
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Change dimensions of an element:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;div&quot;).click(function() {
    $(this).css({
      width: function(index, value) {
        return parseFloat(value) * 1.2;
      },
      height: function(index, value) {
        return parseFloat(value) * 1.2;
      }

    });
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>$(this) refers to all jQuery objects while this refers to the calling object in javascript.  For example, we want to use .each and fadeIn() of jQuery after a selector such as below,</p>
<pre class="brush: jscript; title: ; notranslate">
$('div#product').each(function(){
	$(this).fadeIn()
})
</pre>
<p>since fadeIn() is a jQuery effect function, we use $(this) but if we are not dealing with jQuery objects we use this instead.</p>
<pre class="brush: jscript; title: ; notranslate">
$('.product').each(function(){
	var myClass = this.className; // provided you have multiple class product
})
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Click on each word in paragraph:</p>
<pre class="brush: jscript; title: ; notranslate">
var words = $(&quot;p:first&quot;).text().split(&quot; &quot;);
var text = words.join(&quot;&lt;/span&gt; &lt;span&gt;&quot;);
$(&quot;p:first&quot;).html(&quot;&lt;span&gt;&quot; + text + &quot;&lt;/span&gt;&quot;);
$(&quot;span&quot;).click(function () {
    $(this).css(&quot;background-color&quot;,&quot;yellow&quot;);
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Remove a word in a text:</p>
<pre class="brush: jscript; title: ; notranslate">
var el = $('#id');
el.html(el.html().replace(/word/ig, &quot;&quot;));
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Replace a div:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#thatdiv').replaceWith('&lt;p&gt;Your new content goes here&lt;/p&gt;');
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Append text:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#lal').append(&quot;&lt;b&gt;lol&lt;/b&gt;&quot;);
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Combine more than one effects in jQuery to animate and remove:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;#myButton&quot;).click(function() {
         $(&quot;#myDiv&quot;).fadeTo(&quot;slow&quot;, 0.01, function(){ //fade
             $(this).slideUp(&quot;slow&quot;, function() { //slide up
                 $(this).remove(); //then remove from the DOM
             });
         });
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Test if something is hidden using jQuery:</p>
<pre class="brush: jscript; title: ; notranslate">
if($(element).is(&quot;:visible&quot;) == &quot;true&quot;) {
       //The element is Visible
}
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Center an element on the Screen:</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery.fn.center = function () {
    this.css(&quot;position&quot;,&quot;absolute&quot;);
    this.css(&quot;top&quot;, ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + &quot;px&quot;);
    this.css(&quot;left&quot;, ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + &quot;px&quot;);
    return this;
}
</pre>
<p>//Use the above function as:<br />
$(element).center();</p>
<p><br/><br />
<hr/><br/></p>
<p>Smooth Scrolling:</p>
<pre class="brush: jscript; title: ; notranslate">
$('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
      &amp;&amp; location.hostname == this.hostname) {
       var $target = $(this.hash);
       $target = $target.length &amp;&amp; $target || $('[name=' + this.hash.slice(1) +']');
       if ($target.length) {
           $target.ScrollTo(400);
           return false;
       }
    };
 });
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Equal Height Columns:</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery.fn.equalHeight = function () {
	var tallest = 0;
	this.each(function() {
		tallest = ($(this).height() &gt; tallest)? $(this).height() : tallest;
	});
	return this.height(tallest);
}

//Now you can call equalHeight
$(&quot;.content-column&quot;).equalHeight();
</pre>
<p><br/><br />
<hr/><br/></p>
<pre class="brush: jscript; title: ; notranslate">
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight &gt; tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

//Usage:
$(document).ready(function() {
    equalHeight($(&quot;.recent-article&quot;));
    equalHeight($(&quot;.footer-col&quot;));
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Extending jQuery with a custom selector:</p>
<pre class="brush: jscript; title: ; notranslate">
//extend the jQuery functionality
$.extend($.expr[':'], {  

    //name of your special selector
    moreThanAThousand : function (a){
        //Matching element
        return parseInt($(a).html()) &gt; 1000;
    }
});  

$(document).ready(function() {
    $('td:moreThanAThousand').css('background-color', '#ff0000');
});
</pre>
<pre class="brush: jscript; title: ; notranslate">
$.extend($.expr[&quot;:&quot;], {
    over100pixels: function (e)
    {
        return $(e).height() &gt; 100;
    }
});

$(&quot;.box:over100pixels&quot;).click(function ()
{
    alert(&quot;The element you clicked is over 100 pixels height&quot;);
});
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Access iFrame Elements:</p>
<pre class="brush: jscript; title: ; notranslate">
var iFrameDOM = $(&quot;iframe#someID&quot;).contents();
//Now you can use find() to access any element in the iframe:

iFrameDOM.find(&quot;.message&quot;).slideUp();
//Slides up all elements classed 'message' in the iframe
</pre>
<p><br/><br />
<hr/><br/></p>
<p>Fade in page:</p>
<pre class="brush: jscript; title: ; notranslate">
var $container = $(&quot;body&quot;);
$container.hide().fadeIn(400);

$(&quot;a&quot;).live('click', function(e) {
	e.preventDefault();
	$container.fadeOut(400, function() {
		document.location = this.href;
	});
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/jquery-snippets-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototype basics</title>
		<link>http://www.ekstasis.net/log/javascript/prototype-basics.html</link>
		<comments>http://www.ekstasis.net/log/javascript/prototype-basics.html#comments</comments>
		<pubDate>Thu, 19 May 2011 20:00:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=552</guid>
		<description><![CDATA[&#60;script type=&#34;text/javascript&#34; src=&#34;http://www.google.com/jsapi&#34;&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34;&#62;google.load(&#34;prototype&#34;, &#34;1.6.0.2&#34;);&#60;/script&#62; The $() function document.getElementById("id_of_element").style.color = "#ffffff"; The $() function reduces the code to: $("id_of_element").setStyle({color: '#ffffff'}); Find by ID &#60;script type=&#34;text/javascript&#34;&#62; function test_byid() { $(&#34;first&#34;).toggleClassName(&#34;highlight&#34;); } &#60;/script&#62; &#60;p&#62; &#60;span id=&#34;first&#34;&#62;My ID is first&#60;/span&#62;&#60;br/&#62; &#60;a href=&#34;javascript:test_byid();&#34;&#62;Test function test_byid&#60;/a&#62; &#60;/p&#62; Find by Class &#60;script type=&#34;text/javascript&#34;&#62; function test_byclass() { $$(&#34;second&#34;).each(function(elmt) { elmt.toggleClassName(&#34;highlight&#34;) }); [...]]]></description>
			<content:encoded><![CDATA[<p><code></p>
<p>&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot;&gt;google.load(&quot;prototype&quot;, &quot;1.6.0.2&quot;);&lt;/script&gt;
  </p>
<p></code></p>
<hr/>
<h2>The $() function</h2>
<p><code><br />
document.getElementById("id_of_element").style.color = "#ffffff";<br />
</code><br/><br />
The $() function reduces the code to:<br/><br />
<code><br />
   $("id_of_element").setStyle({color: '#ffffff'});<br />
</code>
</p>
<hr/>
<h2>Find by ID</h2>
<p><code> &lt;script type=&quot;text/javascript&quot;&gt;<br />
  function test_byid() {<br />
       $(&quot;first&quot;).toggleClassName(&quot;highlight&quot;);<br />
  }<br />
  &lt;/script&gt;</code></p>
<p><code>&lt;p&gt;<br />
       &lt;span id=&quot;first&quot;&gt;My ID is first&lt;/span&gt;&lt;br/&gt;<br />
       &lt;a href=&quot;javascript:test_byid();&quot;&gt;Test function test_byid&lt;/a&gt;<br />
       &lt;/p&gt;</code>
</p>
<hr/>
<h2>Find by Class</h2>
<p><code><br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
  function test_byclass() {<br />
  $$(&quot;second&quot;).each(function(elmt) { <br />
  elmt.toggleClassName(&quot;highlight&quot;) <br />
  });<br />
  }<br />
  &lt;/script&gt;</code></p>
<p><code>&lt;p&gt;<br />
  &lt;span class=&quot;second&quot;&gt;My class is second&lt;/span&gt;&lt;br/&gt;<br />
  &lt;input type=&quot;button&quot; onClick=&quot;test_byclass();&quot; value=&quot;Test function test_byclass&quot; /&gt;<br />
  &lt;/p&gt;</code></p>
<hr/>
<h2>Find by Tag</h2>
<p><code><br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
  function test_bytag() {<br />
$$(&quot;em&quot;).each(function(elmt) { <br />
elmt.toggleClassName(&quot;highlight&quot;) <br />
});<br />
}<br />
&lt;/script&gt;<br />
</code></p>
<p><code>&lt;p&gt;&lt;em&gt;I'm in a em&lt;/em&gt;&lt;br/&gt;<br />
  &lt;input type=&quot;button&quot; onClick=&quot;test_bytag();&quot; value=&quot;Test function test_bytag&quot; /&gt;<br />
  &lt;/p&gt;</code></p>
<hr/>
<h2>Click Events</h2>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
  document.observe('dom:loaded', function() {<br />
  &nbsp; $(&quot;click&quot;).observe(&quot;click&quot;, function() { <br />
  &nbsp; &nbsp; alert('Clicked!'); <br />
  &nbsp; });<br />
  });<br />
  &lt;/script&gt;</code></p>
<p><code>&lt;p&gt;&lt;span id=&quot;click&quot;&gt;Click me!&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
  Event.observe(document, 'dom:loaded', function() {<br />
&nbsp; $(&quot;clickme2highlightID&quot;).observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; $(&quot;clickme2highlightID&quot;).toggleClassName(&quot;highlight&quot;);<br />
&nbsp; });<br />
});<br />
&lt;/script&gt;</code></p>
<p><code>&lt;p&gt;&lt;span id=&quot;clickme2highlightID&quot;&gt;Click me to highlight ID&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
Event.observe(document, 'dom:loaded', function() {<br />
&nbsp; $(&quot;clickme2highlightID2&quot;).observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; $(&quot;clickme2highlightanotherID&quot;).toggleClassName(&quot;highlight&quot;);<br />
&nbsp; });<br />
});<br />
&lt;/script&gt;<br />
&lt;p&gt;&lt;span id=&quot;clickme2highlightanotherID&quot;&gt;Highlight me (ID)&lt;/span&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;span id=&quot;clickme2highlightID2&quot;&gt;Click me (ID) to highlight another ID&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
Event.observe(document, 'dom:loaded', function() {<br />
&nbsp; $$(&quot;.clickme2highlightAClass2&quot;).each(function(elmt) { <br />
&nbsp; &nbsp; elmt.observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; &nbsp; $(&quot;clickAClass2HighlightMe&quot;).toggleClassName(&quot;highlight&quot;);<br />
&nbsp; &nbsp; });<br />
&nbsp; });<br />
});</p>
<p>&lt;/script&gt;<br />
&lt;p&gt;&lt;span id=&quot;clickAClass2HighlightMe&quot;&gt;Highlight me (ID)&lt;/span&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;span class=&quot;clickme2highlightAClass2&quot;&gt;Click me (Class) to highlight an ID&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
Event.observe(document, 'dom:loaded', function() {<br />
&nbsp; $(&quot;clickme2highlightID3&quot;).observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; $$(&quot;.clickme2highlightaClass&quot;).each(function(elmt) {<br />
&nbsp; &nbsp; &nbsp; elmt.toggleClassName(&quot;highlight&quot;);<br />
&nbsp; &nbsp; });<br />
&nbsp; });<br />
});<br />
&lt;/script&gt;<br />
&lt;p&gt;&lt;span class=&quot;clickme2highlightaClass&quot;&gt;Highlight me (Class)&lt;/span&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;span id=&quot;clickme2highlightID3&quot;&gt;Click me (ID) to highlight a class&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
  document.observe('dom:loaded', function() {<br />
&nbsp; $(&quot;clickme2highlightSomeClasses&quot;).observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; $$(&quot;.someClasses&quot;).each(function(elmt) { <br />
&nbsp; &nbsp; &nbsp; elmt.toggleClassName(&quot;highlight&quot;)<br />
&nbsp; &nbsp; });<br />
&nbsp; });<br />
});<br />
&lt;/script&gt;</code></p>
<p><code>&lt;p&gt;<br />
  &lt;span class=&quot;someClasses&quot;&gt;My class is 'someClass'&lt;/span&gt; - &lt;span class=&quot;someClasses&quot;&gt;and so is mine&lt;/span&gt;&lt;br/&gt;<br />
  &lt;input type=&quot;button&quot; id=&quot;clickme2highlightSomeClasses&quot; value=&quot;Click me to highlight some classes&quot; /&gt;<br />
  &lt;/p&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
document.observe('dom:loaded', function() {<br />
&nbsp; $$(&quot;.clickme2highlightSomeID&quot;).each(function(elmt) { <br />
&nbsp; &nbsp; elmt.observe(&quot;click&quot;, function() { <br />
&nbsp; &nbsp; &nbsp; $(&quot;someID&quot;).toggleClassName(&quot;highlight&quot;); <br />
&nbsp; &nbsp; });<br />
&nbsp; });<br />
});<br />
&lt;/script&gt;</p>
<p>&lt;p&gt;<br />
&lt;span id=&quot;someID&quot;&gt;My ID is 'someID'&lt;/span&gt;&lt;br/&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;clickme2highlightSomeID&quot; value=&quot;My class is clickme2highlightSomeID&quot; /&gt; - &lt;input type=&quot;button&quot; class=&quot;clickme2highlightSomeID&quot; value=&quot;So is mine&quot; /&gt;<br />
&lt;/p&gt;</code></p>
<hr/>
<h2>Filter What You Find</h2>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
  document.observe('dom:loaded', function() {<br />
  &nbsp; $(&quot;click2&quot;).observe(&quot;click&quot;, function() { <br />
  &nbsp; &nbsp; $$(&quot;span:first-child&quot;).each(function(elmt) { <br />
  &nbsp; &nbsp; &nbsp; elmt.toggleClassName(&quot;highlight&quot;) <br />
  &nbsp; &nbsp; });<br />
  &nbsp; });<br />
  });<br />
  &lt;/script&gt;</code></p>
<p><code>&lt;p id=&quot;click2&quot;&gt;Click to highlight first span&lt;/p&gt;<br />
  &lt;p&gt;&lt;span&gt;First span&lt;/span&gt; &lt;span&gt;Second span&lt;/span&gt;&lt;/p&gt;</code></p>
<hr/>
<h2>The $$() function</h2>
<p>In prototype, unlike jQuery, it&#8217;s important to consider the $$ function returns an array</p>
<p><code>// an array of element references <br />
  $(&quot;img1&quot;, &quot;img2&quot;, &quot;img3&quot;)<br />
  // an array of all input elements inside ID 'commentform' <br />
  $$(&quot;#commentform input&quot;) <br />
  // an array of all links with the class 'external' <br />
  $$(&quot;a.external&quot;)</code></p>
<h2>Testing for an element</h2>
<p><code>var elt = $('exampleDiv');<br />
  if (elt)<br />
  elt.update('Div content updated!');<br/><br />
&lt;script type=&quot;text/javascript&quot;&gt;<br/><br />
var elt = $('foo');<br/><br />
if (elt.hasClassName('hover')) {  // does not reach this<br/><br />
}<br/><br />
 elt.addClassName('hover');<br/><br />
 if (elt.hasClassName('hover')) {  // does reach this<br/><br />
 } <br/><br />
&lt;/script&gt;</code>
</p>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt; <br/><br />
  var elt = $('foo');   <br/>              elt.observe('mouseover', function(e) {<br/>                  this.addClassName('hover'); <br/>             });  <br/>               elt.observe('mouseout', function(e) {<br/>                  this.removeClassName('hover');<br/>              }); <br/>         &lt;/script&gt;</code></p>
<h2>Set Styles</h2>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt; <br/>              var elt = $('foo'); <br/>                 var styles = {    <br/>               size       : '18px',    <br/>               fontWeight : 'bold',   <br/>                background : '#f00',    <br/>               padding    : '10px'<br/>               } <br/>                 elt.setStyle(styles); <br/>          &lt;/script&gt;</code></p>
<p>Note: Some CSS properties (such as float) are reserved words, and must therefore be quoted in the style hash. For example, you would use styles = { &#8216;float&#8217; : &#8216;left&#8217;; }</p>
<h2>Get Dimentions</h2>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />              var elt         = $('foo');<br />                 // retrieve required dimensions              var eltDims     = elt.getDimensions();<br />              var browserDims = document.viewport.getDimensions();<br />                 // calculate the center of the page using the browser and element dimensions<br />              var top  = (browserDims.height - eltDims.height) / 2;<br />              var left = (browserDims.width - eltDims.width) / 2;<br />                 // set the style of the element so it is centered<br />              var styles = {<br />                  position : 'absolute',<br />                  top      : top + 'px',<br />                  left     : left + 'px'<br />              };<br />                 elt.setStyle(styles);<br />          &lt;/script&gt;</code></p>
<ul>
<li>update() – Used to update the inner HTML of the target element. </li>
<li>select(), up(), down(), previous() and next() – Used to find other elements in the DOM relative to the target element.</li>
<li>insert() – Used to add a new element to the DOM relative to the target element.</li>
<li>remove()</li>
<li>hide() and show() </li>
</ul>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[<br />
  Event.observe(window, 'load', function() {<br />
  var homeImg1 = $('homeimg1');<br />
  if(homeImg1.hasClassName('darkImg'))<br />
{<br />
$$('.page').first().addClassName('darkImgPage');<br />
}<br />
Cufon.set('fontFamily', 'Futura_BT_Light'); <br />
Cufon.replace('#home_nav .home_nav_links em');<br />
});<br />
// ]]&gt;&lt;/script&gt;</code></p>
<hr/>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[<br />
  Event.observe(window, 'load', function() {<br />
  var homeImg1 = $('homeimg1');<br />
  if(homeImg1.hasClassName('darkImg'))<br />
  {<br />
  $$('.page').first().addClassName('darkImgPage');<br />
  }<br />
  Cufon.set('fontFamily', 'Futura_BT_Light'); <br />
  Cufon.replace('#home_nav .home_nav_links em');<br />
  });<br />
  // ]]&gt;&lt;/script&gt;</code></p>
<hr/>
<h2>Using each in a loop</h2>
<div id="foo1">
<ul>
<li>Element 1</li>
<li>Element 2</li>
<li>Element 3</li>
<li>Element 4</li>
<li>Element 5</li>
<li>Element 6</li>
</ul></div>
<div id="output"></div>
<p><a href="http://www.phpriot.com/articles/prototype-data-types/5">http://www.phpriot.com/articles/prototype-data-types/5</a></p>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
function doSomething(item, i)<br />
{<br />
var output = $('output');</p>
<p>if (i == 2)<br />
return; // &quot;continue&quot;</p>
<p>output.update(output.innerHTML + '&lt;br /&gt;' + item.innerHTML);</p>
<p>if (i == 3)<br />
throw new $break;<br />
}</p>
<p>$$('#foo li').each(doSomething);<br />
&lt;/script&gt;</code></p>
<h2>Other Enumerable Methods</h2>
<p>There are a number of other methods that can be used with enumerable objects at <a href="http://prototypejs.org/api/enumerable">http://prototypejs.org/api/enumerable</a>.</p>
<h2>Invoke</h2>
<p>.invoke() allows you to call a single function on each element in the enumerable.<br/><br/><br />
        //hide all elements by using invoke() to apply the hide() method.<br/><br />
        <code>$$('#foo li').invoke('hide').</code><br/><br />
        //remove the active class name from all elements<br/><br />
        <code>$$('#foo li').invoke('removeClassName', 'active').</code><br/><br />
// of course, this works on Prototype extensions<br/><br />
<code>$('navBar', 'adsBar', 'footer').invoke('hide')</code><br/></p>
<p>// because Prototype extensions return the element itself you can also chain &#8216;invoke&#8217; calls:<br/><br />
<code>$$('#windows div.close').invoke('addClassName', 'active').invoke('show');</code></p>
<hr/>
<div>
<ul id="foo2">
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
</ul></div>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
function onItemClick(e)<br />
{<br />
var item = Event.element(e);</p>
<p>item.setStyle({ backgroundColor : '#fc0' });<br />
item.update('Clicked!');<br />
}</p>
<p>$$('#foo2 li').each(function(item) {<br />
item.observe('click', onItemClick);<br />
});<br />
&lt;/script&gt;</code></p>
<hr/>
<div>
<ul id="foo3">
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
</ul></div>
<p>With Event.findElement() you specify a tag name as the second argument</p>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
function onItemClick(e)<br />
{<br />
var list = Event.findElement(e, 'ul');</p>
<p>list.setStyle({ border : '2px solid #fc0'});<br />
}</p>
<p>$$('#foo3 li').each(function(item) {<br />
item.observe('click', onItemClick);<br />
});<br />
&lt;/script&gt;</code></p>
<p>Event.findElement() can only find ancestor elements based on their tag name. For more targeted search combine Event.element() with the up() method:</p>
<div class="outer">
<div class="inner">
<ul id="foo4">
<li>Click Me</li>
<li>Click Me</li>
<li>Click Me</li>
</ul></div>
</p></div>
<p>        &lt;div class=&quot;outer&quot;&gt;<br />
&nbsp; &lt;div class=&quot;inner&quot;&gt;<br />
&nbsp; &nbsp; &lt;ul id=&quot;foo4&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;Click Me&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;Click Me&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;Click Me&lt;/li&gt;<br />
&nbsp; &nbsp; &lt;/ul&gt;<br />
&nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>&lt;script type=&quot;text/javascript&quot;&gt;<br />
function onItemClick(e)<br />
&nbsp; {<br />
&nbsp; var item = Event.element(e);<br />
&nbsp; var outer = item.up(&#8216;div.outer&#8217;);</p>
<p>&nbsp; outer.setStyle({ backgroundColor : &#8216;#cf9&#8242; });<br />
&nbsp; }</p>
<p>$$(&#8216;#foo li&#8217;).each(function(item) {<br />
&nbsp; item.observe(&#8216;click&#8217;, onItemClick);<br />
});<br />
&lt;/script&gt;</p>
<div id="foo5">
            Click me
  </div>
<p>        &lt;div id=&quot;foo5&quot;&gt;<br />
Click me<br />
&lt;/div&gt;</p>
<p>&lt;script type=&quot;text/javascript&quot;&gt;<br />
function onFooClick(e)<br />
{<br />
var element = Event.element(e);</p>
<p>alert(&#8216;You clicked the element!&#8217;);</p>
<p>element.stopObserving(&#8216;click&#8217;, onFooClick);<br />
element.update(&#8216;Clicking me now does nothing&#8217;);<br />
}</p>
<p>$(&#8216;foo5&#8242;).observe(&#8216;click&#8217;, onFooClick);<br />
&lt;/script&gt;</p>
<ul>
<li>
<h3>Tutorials</h3>
</li>
<li><a href="http://www.phpriot.com/articles/beginning-with-prototype">Eight Weeks of Prototype</a></li>
<li><a href="http://www.saschakimmel.com/2009/05/tutorial-how-to-use-prototypejs-on-your-site/">www.saschakimmel.com/2009/05/tutorial-how-to-use-prototypejs-on-your-site/</a></li>
<li><a href="http://24ways.org/2005/easy-ajax-with-prototype">24ways.org/2005/easy-ajax-with-prototype</a></li>
<li><a href="http://www.saschakimmel.com/tag/prototypejs/">www.saschakimmel.com/tag/prototypejs/</a></li>
<li>
<h3>Plugin Portals</h3>
</li>
<li><a href="http://www.prototype-plugins.com/">prototype-plugins.com</a></li>
<li><a href="http://ajaxian.com/by/topic/prototype">ajaxian.com/by/topic/prototype</a></li>
<li><a href="http://scripteka.com/">scripteka.com</a></li>
<li>
<h3>Widgets</h3>
</li>
<li><a href="http://protofish.procurios.nl/">protofish</a> &#8211; &#8216;Suckerfish type&#8217; dropdown</li>
<li><a href="http://www.deensoft.com/lab/protoflow/">protoflow</a> &#8211; Slider &#8217;3D&#8217; Carousel</li>
<li><a href="http://www.nickstakenburg.com/projects/lightview/">lightview</a> &#8211; Slider &#8217;3D&#8217; Carousel</li>
<li><a href="http://www.beauscott.com/2008/03/02/helpballoonjs-version-20/">helpballoonjs</a> &#8211; Tooltip</li>
<li><a href="http://dhonishow.de/">dhonishow.de</a> &#8211; Slideshow</li>
<li>
<h3>UI Libraries</h3>
</li>
<li><a href="http://livepipe.net/">livepipe.net</a></li>
<li><a href="http://www.prototype-ui.com/">prototype-ui.com</a> &#8211; Based on Prototype 1.6</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/prototype-basics.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Behavioural separation and jQuery</title>
		<link>http://www.ekstasis.net/log/javascript/behavioural-separation-and-jquery.html</link>
		<comments>http://www.ekstasis.net/log/javascript/behavioural-separation-and-jquery.html#comments</comments>
		<pubDate>Sun, 13 Jun 2010 19:47:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.ekstasis.net/log/?p=83</guid>
		<description><![CDATA[This is a presentation about unobtrusive jQuery. Contents: Progressive CSS Progressive JavaScripting Unobtrustive JavaScript Understand browsers and users Event Delegation Relationships Maintenance JQuery JQuery &#038; XML Here&#8217;s a download link: Behavioral separation and jQuery]]></description>
			<content:encoded><![CDATA[<p>This is a presentation about unobtrusive jQuery.<br/><br />
Contents:</p>
<ul>
<li>Progressive CSS</li>
<li>Progressive JavaScripting </li>
<li>Unobtrustive JavaScript</li>
<li>Understand browsers and users</li>
<li>Event Delegation</li>
<li>Relationships</li>
<li>Maintenance</li>
<li>JQuery</li>
<li>JQuery &#038; XML</li>
</ul>
<p>Here&#8217;s a download link: <a href="/imports/unobtrusive-jquery.pdf" title="click to download" />Behavioral separation and jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekstasis.net/log/javascript/behavioural-separation-and-jquery.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

