<?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>Think Bohemian &#187; javascript</title>
	<atom:link href="http://www.thinkbohemian.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thinkbohemian.com</link>
	<description>Secede from Convention in Life and Code</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:13:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stack Overflow Style Notifications &#8211; Using Jquery</title>
		<link>http://www.thinkbohemian.com/2010/04/22/stack-overflow-style-notifications-using-jquery/</link>
		<comments>http://www.thinkbohemian.com/2010/04/22/stack-overflow-style-notifications-using-jquery/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 15:03:58 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[announcement]]></category>
		<category><![CDATA[announcements]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[dismiss]]></category>
		<category><![CDATA[dismissible]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[jquery cookie]]></category>
		<category><![CDATA[notification]]></category>
		<category><![CDATA[notify]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=401</guid>
		<description><![CDATA[Explore Stack Overflows usability in this tutorial, and delve into one way to re-create their dismissible notifications using jquery and cookies. Brought to you by ThinkBohemian and WhySpam.Me.]]></description>
			<content:encoded><![CDATA[<p>Have you seen <a href="http://stackoverflow.com">Stack Overflow</a>? Besides the great content, they have excellent user interface elements that flow seamlessly together. When you visit, an orange notification bar instantly jumps out at you, yet is easily dismissed. I thought this was a great example of notifications done right, so I wondered how I might achieve a similar effect.</p>
<p>First lets  take a look into my approach, and then I&#8217;ll talk about my implementation.</p>
<p style="text-align: center;"><a href="http://www.thinkbohemian.com/wp-content/uploads/2010/04/stack-overflow-notification-demo.png"><img class="size-full wp-image-402 aligncenter" title="stack-overflow-notification-demo" src="http://www.thinkbohemian.com/wp-content/uploads/2010/04/stack-overflow-notification-demo.png" alt="Stack overflow notification demo" width="454" height="197" /></a></p>
<p style="text-align: center;">
<p style="text-align: center;"><a class="download-button button" href="http://www.thinkbohemian.com/wp-content/uploads/2010/04/StackOverflowStyleNotification.zip"><span>Download Files</span></a><a class="demo-button button" href="http://www.thinkbohemian.com/wp-content/uploads/2010/04/stack-overflow-style-notification.html" target="_blank"><span> View Demo</span></a></p>
<p style="text-align: left;">
<p style="text-align: left;">
<h3 style="text-align: left;">The Approach</h3>
<p style="text-align: left;">The notifications use an animation to grab the users  attention. For the animation I decided to use the <a href="http://jquery.com/">jquery</a> javascript library. It is very easy to use and has several pre-built animations such as <strong>fadeIn</strong> and <strong>fadeOut</strong>.</p>
<p style="text-align: left;">Once a user dismisses a  notification they should never see it again. To remember when a user dismisses the notification, I decided to use <a href="http://en.wikipedia.org/wiki/HTTP_cookie">http cookies</a>.  These cookies allow us to save a value in the user&#8217;s browser, so when the user clicks dismiss they create a cookie on their local machine. Then the next time they visit the webpage, the page will see that they already have the cookie, and the notification will not be displayed.</p>
<p style="text-align: left;">Alternatively, if the webpage required a log-in, then I could have stored this data in a database and associated it with a user, but by utilizing cookies I can apply this technique to any web page without the need for any server side scripting (PHP, Ruby on Rails, etc.).</p>
<p style="text-align: left;">After looking into several ways to get and set cookies I decided to use the <a href="http://plugins.jquery.com/project/cookie">jquery cookies   plugin</a> which allowed me to dynamically set cookies without a page refresh.</p>
<p style="text-align: left;">Now that you know my approach to the problem lets take a look at the implementation.</p>
<h3 style="text-align: left;">The Implementation</h3>
<p style="text-align: left;">For the fade in fade out animation I used <a href="http://jquery.com/">Jquery</a>. You can use the GoogleAPI copy of the library by placing this code in your webpage:</p>
<pre id="line512"> &lt;script src="<a href="view-source:http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js</a>" type="text/javascript"&gt;&lt;/script&gt;
</pre>
<p style="text-align: left;">Next I downloaded the <a href="http://plugins.jquery.com/project/cookie">jquery cookies plugin</a> and included it in my webpage. To create a cookie named <strong>notificationBar</strong> and give it the value &#8220;<strong>closed</strong>&#8221; we can use the plugin and execute this command:</p>
<pre>$.cookie('notificationBar', 'closed');
</pre>
<p>After we have created the <strong>notificationBar</strong> cookie we can get its value by executing this command:<strong><br />
</strong></p>
<pre>$.cookie('notificationBar');
</pre>
<p style="text-align: left;">this command will now return the value &#8220;<strong>closed&#8221;.<br />
</strong></p>
<p style="text-align: left;">Next I added the html for the notification that will be displayed:</p>
<pre>&lt;div id = "topannounce" class = "announce" style = "display:none;"&gt;
   This Is a Notification from &lt;a href = "http://thinkbohemian.com" target = "_blank"&gt;ThinkBohemian&lt;/a&gt;
    &lt;a href = "#" onclick = "$.cookie('notificationBar', 'closed');
        $('#topannounce').fadeOut('slow')"&gt;X&lt;/a&gt;
 &lt;/div&gt;
</pre>
<p>By default it is hidden using:</p>
<pre>style = "display:none;"</pre>
<p>Using <a href="http://jquery.com/">jquery</a> we can <strong>fadeIn</strong> the notification unless the <strong>notificationBar</strong> cookie has been set to &#8220;<strong>closed</strong>&#8220;.  To accomplish this I added these lines of javascript to the page:</p>
<pre>&lt;script type="text/javascript"&gt;
 $(document).ready(function(){
   if ($.cookie('notificationBar') != 'closed') {
     $('#topannounce').fadeIn('slow');
   }
 });
 &lt;/script&gt;
</pre>
<p>Then I styled my HTML with a little CSS, and the effect was complete. My webpage has its very own dismissible notification bar:  <a href="http://www.thinkbohemian.com/wp-content/uploads/2010/04/stack-overflow-style-notification.html">View the demo of the notification in action</a>.</p>
<p><strong>Richard Schneeman</strong>: <a href="http://twitter.com/thinkbohemian">@ThinkBohemian</a></p>
<p>I used this effect to notify visitors to  WhySpam.Me, my <a href="http://whyspam.me">disposable email</a> service,  about the launch of <a href="http://shadyemail.com">ShadyEmail.com</a>, the fun way to hide your email and make it questionably suspicious.</p>
<p>&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2010/04/22/stack-overflow-style-notifications-using-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DOM Navigation Javascript Cheat Sheet</title>
		<link>http://www.thinkbohemian.com/2009/12/30/javascript-cheat-sheet/</link>
		<comments>http://www.thinkbohemian.com/2009/12/30/javascript-cheat-sheet/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 18:52:53 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=208</guid>
		<description><![CDATA[This is a cheatsheet i wrote, so i don&#8217;t have to remember some simple javascript DOM stuff
http://pastie.org/761588
Also check out this sweet page of DOM attributes you can get with javascript http://www.howtocreate.co.uk/tutorials/javascript/domstructure

Sample Dom-
&#60;body&#62;
&#60;h1&#62; Hello World&#60;/h1&#62;
&#60;div id="america"&#62;
 I am an &#60;em&#62; american&#60;/em&#62;, but I wish I was &#60;span id="superman"&#62;superman&#60;/span&#62;.&#60;/div&#62;
&#60;form&#62;
 &#60;input onclick="guess();" type="button" value="What Am I?" /&#62;
 &#60;/form&#62;
&#60;/div&#62;
&#60;/body&#62;

Sample [...]]]></description>
			<content:encoded><![CDATA[<p>This is a cheatsheet i wrote, so i don&#8217;t have to remember some simple javascript DOM stuff</p>
<p><a href="http://pastie.org/761588">http://pastie.org/761588</a></p>
<p>Also check out this sweet page of DOM attributes you can get with javascript <a href="http://www.howtocreate.co.uk/tutorials/javascript/domstructure">http://www.howtocreate.co.uk/tutorials/javascript/domstructure</a></p>
<hr />
<pre><span style="text-decoration: underline;">Sample Dom</span>-
&lt;body&gt;
&lt;h1&gt; Hello World&lt;/h1&gt;
&lt;div id="america"&gt;
 I am an &lt;em&gt; american&lt;/em&gt;, but I wish I was &lt;span id="superman"&gt;superman&lt;/span&gt;.&lt;/div&gt;
&lt;form&gt;
 &lt;input onclick="guess();" type="button" value="What Am I?" /&gt;
 &lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;

<span style="text-decoration: underline;">Sample JS</span>

var element = document;
 alert(element.lastChild.nodeName);// will return "HTML"
 alert(element.lastChild.nodeValue); // will return "null"

var element = document.getElementById("america");
alert(document.getElementById("america").parentNode.nodeName); // will return 'body'
alert(document.getElementById("america").nodeName ) ; // will return 'div
alert(document.getElementsByTagName("h1")[0].firstChild); // will return " Hello World"

document.getElementById("superman").firstChild // will return text "superman"
<span style="text-decoration: underline;">Valid Selectors</span>
parentNode            // returns immediate parent node
childNodes            // returns an array of child nodes
firstChild            // gets first child of element
lastChild             // gets last child of element
getElementsByTagName    // gets element by tag name, such as "div" for &lt;div&gt; and "p" for &lt;p&gt; and "h1" for &lt;h1&gt;
getElementById          // gets element by id such as 'Element:something' for &lt;div id="something"&gt;
getAttributeNode        // gets the attributes of element getAttributeNode("id") returns id attribute
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2009/12/30/javascript-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Global Javascript Variables and You</title>
		<link>http://www.thinkbohemian.com/2009/10/17/global-javascript-variables-and-you/</link>
		<comments>http://www.thinkbohemian.com/2009/10/17/global-javascript-variables-and-you/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 23:31:52 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[clickable]]></category>
		<category><![CDATA[flag]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[table row]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=123</guid>
		<description><![CDATA[Just found out today that you can attach a javascript variable to the  window effectively making it a variable global to the window. You can define it like this:
window.myboolean = false ;
And then you can access the same variable anywhere in your window. Pretty Cool Huh? The reason I needed a global variable in the [...]]]></description>
			<content:encoded><![CDATA[<p>Just found out today that you can attach a javascript variable to the  <strong>window </strong>effectively making it a variable global to the window. You can define it like this:</p>
<pre>window.myboolean = false ;</pre>
<p>And then you can access the same variable anywhere in your window. Pretty Cool Huh? The reason I needed a global variable in the first place was due to some neat javascript hackery. In some of my tables, i have <a href="http://www.ruby-forum.com/topic/183073#800473">made an entire row clickable </a>, by adding <strong>onclick = &#8220;window.location.href = &#8216;http://whateveriwant.com&#8217; &#8221; </strong>to the <strong>&lt;tr&gt; </strong>element, and setting it&#8217;s style to render a cursor when moused over. I then paired this with rails <strong>url_for</strong> helper to give me a gmail esque feel. The user can click any part of the table row, not just a link, and they will be redirected. Sweet.</p>
<pre>&lt;tr  onclick = "window.location.href =  '&lt;%= url_for :controller =&gt; 'manage', :id =&gt; whymail.id, :type =&gt; "whymail", :action =&gt; 'show' %&gt;' "  style = "cursor:pointer:" &gt;
    &lt;td&gt; My Content &lt;/td&gt;
&lt;/tr&gt;</pre>
<p>While clickable rows is a neat little trick,  what happens when you want to put a button or a checkbox in your table row to really get a gmail feel? When you click your button or your select box, you&#8217;re also clicking in the table row, so you automatically tell the browser to redirect to a different url. Make Sense?</p>
<pre>&lt;tr  onclick = "window.location.href =  '&lt;%= url_for manage_spam_url(id)  %&gt;' "  style = "cursor:pointer:" &gt;
    &lt;td&gt; My Content &lt;/td&gt;
    &lt;td&gt; &lt;%= button_to_remote "Delete", :url =&gt; spam_survey_url(:id =&gt; whymail.id) , :update =&gt; "partial_update" %&gt;&lt;/td&gt;
&lt;/tr&gt;</pre>
<p>So in the above example even if you clicked on the <strong>Delete</strong> button then browser will still redirect to <strong>manage_spam_url </strong>because you still clicked on the table row. Therein lies the rub, and here comes the global javascript variables. To keep the table row redirecting us we can set a variable flag. First we put a <a href="http://en.wikipedia.org/wiki/Ternary_operator">ternary operator </a>in the  table row like this:</p>
<pre>&lt;tr  onclick = "window.location.href = window.myboolean ? '#' : '&lt;%= url_for manage_spam_url(id) %&gt;' "  style = "cursor:pointer:" &gt;</pre>
<p>and we can set our flag in the header like this:</p>
<pre>&lt;script type="text/javascript" charset="utf-8"&gt;
    window.myboolean = false ;
&lt;/script&gt;</pre>
<p>Then in our button we can set the flag to true when it gets pressed:</p>
<pre>&lt;%= button_to_remote "Delete", :url =&gt; spam_survey_url(:id =&gt; whymail.id) , :update =&gt; "partial_update", :loading =&gt; "<strong>window.myboolean = true;</strong>",  :complete =&gt;"<strong>window.myboolean=false;</strong>" %&gt;</pre>
<p>And after the javascript from the button loads we set the flag back to false. Its possible that this is serious over kill. But if anyone finds a better way to do this, let me know. Till then happy global javascripting!!</p>
<pre></pre>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2009/10/17/global-javascript-variables-and-you/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
