<?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; jquery</title>
	<atom:link href="http://www.thinkbohemian.com/category/jquery/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>Custom jQuery UI Rails Button Form Helper</title>
		<link>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/</link>
		<comments>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 02:22:14 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[form helper]]></category>
		<category><![CDATA[jquery ui]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=97</guid>
		<description><![CDATA[Today I got a little bored with my standard rails buttons

Not bad&#8230;but could use a little pizazz. So I decided to take a crack at jQuery UI. A great javascript and style framework that promised to be easy to use and provides theme-able styles.
Once you&#8217;ve got jQuery UI integrated nicely into your rails project (note [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Today I got a little bored with my standard rails buttons</p>
<p style="text-align: center;"><img class="aligncenter" title="generate secure email button" src="../wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.55.48-PM.png" alt="generate secure email button" width="148" height="28" /></p>
<p style="text-align: left;">Not bad&#8230;but could use a little pizazz. So I decided to take a crack at <a href="http://jqueryui.com/">jQuery UI</a>. A great javascript and style framework that promised to be easy to use and provides theme-able styles.</p>
<p style="text-align: left;">Once you&#8217;ve got jQuery UI integrated nicely into your rails project (note i had to change my url paths in the stylesheet), you can style your submit button easily by adding some classes just like this:</p>
<pre style="text-align: left;">&lt;%= f.submit "Generate Secure Email", :class =&gt; "ui-corner-all ui-state-default " %&gt;</pre>
<p style="text-align: center;"><img class="size-full wp-image-101 alignnone" title="Untitled-3" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Untitled-3.jpg" alt="Untitled-3" width="152" height="38" /></p>
<p style="text-align: left;">Though, this isn&#8217;t 100% what I was looking for, it&#8217;s a good start. When we hover over the button, it changes color, and when we press it, our rails form submits. Though you&#8217;ll notice that the cursor doesn&#8217;t change when you hover over the button and we haven&#8217;t put an icon in it yet. To get the correct behavior i hard coded in a button:</p>
<pre style="text-align: left;">&lt;button id="user_submit" class = "ui-corner-all  ui-state-default"  type="submit" name="commit"&gt;Generate Secure Email&lt;/button&gt;</pre>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-102" title="Screen shot 2009-10-12 at 9.06.33 PM" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-9.06.33-PM.png" alt="Screen shot 2009-10-12 at 9.06.33 PM" width="169" height="36" /></p>
<p style="text-align: left;">This solved the button styling and behavior, but we still don&#8217;t have our icon. After browsing the inter webs i found a nice page of <a href="http://http://www.filamentgroup.com/examples/buttonFrameworkCSS/">jQuery-UI button demos</a> and I managed to modify my code to include a nice icon:</p>
<pre style="text-align: left;">&lt;button id="user_submit" class = "ui-corner-all fg-button ui-state-default fg-button-icon-left" type="submit" name="commit"&gt;&lt;span&gt;&lt;/span&gt;Generate Secure Email&lt;/button&gt;</pre>
<p style="text-align: center;"><img class="aligncenter" title="jQuery UI Button with rails" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.54.35-PM.png" alt="jQuery UI Button with rails" width="185" height="38" /></p>
<p style="text-align: left;">Perfect! It works like a dream, but it&#8217;s not very rails-esq. Lets turn this into a reusable chunk of code by making a helper method to extend form builder. In app/helpers/application_helper.rb</p>
<pre style="text-align: left;">class ActionView::Helpers::FormBuilder
    def button_with_icon(text , icon)
     object_name = self.object_name
     return "&lt;button id='#{object_name}_submit' class = 'ui-corner-all fg-button ui-state-default fg-button-icon-left' type='submit' name='commit'&gt;&lt;span class='ui-icon ui-icon-#{icon}'&gt;&lt;/span&gt;#{text}&lt;/button&gt;"
    end
end</pre>
<p style="text-align: left;">Now In my View I can put:</p>
<pre style="text-align: left;">&lt;%=  f.button_with_icon("Generate Secure Email", "mail-closed") %&gt;</pre>
<p style="text-align: left;">And I get my perfectly formatted button complete with an Icon!</p>
<p style="text-align: center;"><img class="alignnone" title="jQuery UI Button with rails" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.54.35-PM.png" alt="jQuery UI Button with rails" width="185" height="38" /></p>
<hr style="text-align: center;" />
<p style="text-align: left;">Note:</p>
<pre style="text-align: left;">&lt;% form_for :person, @person, :url =&gt; { :action =&gt; "create" } do |f| %&gt;
    &lt;%= f.object_name %&gt;
&lt;% end %&gt;</pre>
<p style="text-align: left;">will print out &#8220;person&#8221;, thats why in the helper we call  self.object_name on the <a href="http://caboo.se/doc/classes/ActionView/Helpers/FormBuilder.html">form_builder class.</a> Pretty cool huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
