<?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>SoftLayer Blog &#187; JavaScript</title>
	<atom:link href="http://blog.softlayer.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Wed, 15 May 2013 15:33:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Tips and Tricks – Building a jQuery Plugin (Part 2)</title>
		<link>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/</link>
		<comments>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 15:25:43 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[exercise]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10619</guid>
		<description><![CDATA[jQuery plugins don&#8217;t have to be complicated to create. If you&#8217;ve stumbled upon this blog in pursuit of a guide to show you how to make a jQuery plugin, you might not believe me &#8230; It seems like there&#8217;s a chasm between the &#8220;haves&#8221; of jQuery plugin developers and the &#8220;have nots&#8221; of future jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery plugins don&#8217;t have to be complicated to create. If you&#8217;ve stumbled upon this blog in pursuit of a guide to show you how to make a jQuery plugin, you might not believe me &#8230; It seems like there&#8217;s a chasm between the &#8220;haves&#8221; of jQuery plugin developers and the &#8220;have nots&#8221; of future jQuery developers, and there aren&#8217;t very many bridges to get from one side to the other. In <a href="http://blog.softlayer.com/2012/tips-and-tricks-building-a-jquery-plugin-part-1/">Part 1</a> of our &#8220;Building a jQuery Plugin&#8221; series, we broke down how to build the basic structure of a plugin, and in this installment, we&#8217;ll be adding some usable functionality to our plugin. </p>
<p>Let&#8217;s start with the jQuery code block we created in Part 1:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                myVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This is&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// this will be the default value of this var</span>
                anotherVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;our awesome&quot;</span><span style="color: #339933;">,</span>
                coolVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;plugin!&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                ourString <span style="color: #339933;">=</span> myVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> anotherVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> coolVar<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> ourString<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We want our plugin to do a little more than return, &#8220;This is our awesome plugin!&#8221; so let&#8217;s come up with some functionality to build. For this exercise, let&#8217;s create a simple plugin that allows truncates a blob of text to a specified length while providing the user an option show/hide the rest of the text. Since the most common character length limitation on the Internet these days is Twitter&#8217;s 140 characters, we&#8217;ll use that mark in our example.</p>
<p>Taking what we know about the basic jQuery plugin structure, let&#8217;s create the foundation for our new plugin &mdash; <code>slPlugin2</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span>
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;collapse&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you can see, we&#8217;ve established four default variables:</p>
<ul>
<li><code>length</code>: The length of the paragraph we want before we truncate the rest.</li>
<li><code>moreLength</code>: What we append to the paragraph when it is truncated. This will be the link the user clicks to expand the rest of the text.</li>
<li><code>lessLink</code>: What we append to the paragraph when it is expanded. This will be the link the user clicks to collapse the rest of the text.</li>
<li><code>trailingText</code>: The typical ellipses to append to the truncation.</li>
</ul>
<p>In our jQuery plugin example from Part 1, we started our function with <code>this.each(function() {</code>, and for this example, we&#8217;re going to add a return for <code>this</code> to maintain chainability. By doing so, we&#8217;re able to manipulate the segment with methods. For example, if we started our function with <code>this.each(function() {</code>, we&#8217;d call it with this line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ourParagraph'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slPlugin2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If we start the function with <code>return this.each(function() {</code>, we have the freedom to add further manipulation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ourParagraph'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slPlugin2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>With such a simple change, we&#8217;re able to add method calls to make one massive dynamic function. </p>
<p>Let&#8217;s flesh out the actual function a little more. We&#8217;ll add a substantial bit of code in this step, but you should be able to follow along with the changes via the comments:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span> 
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;collapse&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// return this keyword for chainability</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourText <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// the element we want to manipulate</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourHtml <span style="color: #339933;">=</span> ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//get the contents of ourText!</span>
            <span style="color: #006600; font-style: italic;">// let's check if the contents are longer than we want</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ourHtml.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> truncSpot <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">,</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// the location of the first space (so we don't truncate mid-word) where we will end our truncation.</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// make sure to ignore the first space IF the text starts with a space</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>truncSpot <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// the part of the text that will not be truncated, starting from the beginning</span>
       <span style="color: #003366; font-weight: bold;">var</span> firstText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> truncSpot<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// the part of the text that will be truncated, minus the trailing space</span>
       <span style="color: #003366; font-weight: bold;">var</span> secondText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>truncSpot<span style="color: #339933;">,</span> ourHtml.<span style="color: #660066;">legnth</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Are you still with us? I know it seems like a lot to take in, but each piece is very straightforward. The <code>firstText</code> is the chunk of text that will be shown: The first 140 characters (or whatever <code>length</code> you define). The <code>secondText</code> is what <em>will</em> be truncated. We have two blobs of text, and now we need to make them work together:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span> 
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read less&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// return this keyword for chainability</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourText <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// the element we want to manipulate</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourHtml <span style="color: #339933;">=</span> ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//get the contents of ourText!</span>
            <span style="color: #006600; font-style: italic;">// let's check if the contents are longer than we want</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ourHtml.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> truncSpot <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">,</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// the location of the first space (so we don't truncate mid-word) where we will end our truncation.</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// make sure to ignore the first space IF the text starts with a space</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>truncSpot <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// the part of the text that will not be truncated, starting from the beginning</span>
       <span style="color: #003366; font-weight: bold;">var</span> firstText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> truncSpot<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// the part of the text that will be truncated, minus the trailing space</span>
       <span style="color: #003366; font-weight: bold;">var</span> secondText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>truncSpot<span style="color: #339933;">,</span> ourHtml.<span style="color: #660066;">legnth</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// perform our truncation on our container ourText, which is technically more of a &quot;rewrite&quot; of our paragraph, to our liking so we can modify how we please. It's basically saying: display the first blob then add our trailing text, then add our truncated part wrapped in span tags (to further modify)</span>
       ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>firstText <span style="color: #339933;">+</span> options.<span style="color: #660066;">trailingText</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;span class=&quot;slPlugin2&quot;&gt;'</span> <span style="color: #339933;">+</span> secondText <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// but wait! The secondText isn't supposed to show until the user clicks &quot;read more&quot;, right? Right! Hide it using the span tags we wrapped it in above.</span>
       ourText.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slPlugin2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Our function now truncates text to the specified length, and we can call it from our page simply:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.slPlugin2.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
$(document).ready(function() {  
    $('#slText').slPlugin2();  
});
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Out of all the ways to truncate text via jQuery, this has to be my favorite. It&#8217;s feature-rich while still being fairly easy to understand. As you might have noticed, we haven&#8217;t touched on the &#8220;read more&#8221; and &#8220;read less&#8221; links or the expanding/collapsing animations yet, but we&#8217;ll be covering those in Part 3 of this series. Between now and when Part 3 is published, I challenge you to think up how you&#8217;d add those features to this plugin as homework. </p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Web Development &#8211; JavaScript Packaging</title>
		<link>http://blog.softlayer.com/2013/web-development-javascript-packaging/</link>
		<comments>http://blog.softlayer.com/2013/web-development-javascript-packaging/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 20:15:05 +0000</pubDate>
		<dc:creator>Philip Thompson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[efficient]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[organization]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[version control]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10401</guid>
		<description><![CDATA[If you think of JavaScript as the ugly duckling of programming languages, think again! It got a bad rap in the earlier days of the web because developers knew enough just to get by but didn&#8217;t really respect it like they did Java, PHP or .Net. Like other well-known and heavily used languages, JavaScript contains [...]]]></description>
			<content:encoded><![CDATA[<p>If you think of JavaScript as the ugly duckling of programming languages, think again! It got a bad rap in the earlier days of the web because developers knew enough just to get by but didn&#8217;t really respect it like they did Java, PHP or .Net. Like other well-known and heavily used languages, JavaScript contains various data types (String, Boolean, Number, etc.), objects and functions, and it is even capable of inheritance. Unfortunately, that functionality is often overlooked, and many developers seem to implement it as an afterthought: &#8220;Oh, we need to add some neat jQuery effects over there? I&#8217;ll just throw some inline JavaScript here.&#8221; That kind of implementation perpetuates a stereotype that JavaScript code is unorganized and difficult to maintain, but it doesn&#8217;t have to be! I&#8217;m going to show you how easy it is to maintain and organize your code base by packaging your JavaScript classes into a single file to be included with your website.</p>
<p>There are a few things to cover before we jump into code: </p>
<ol>
<li><strong>JavaScript Framework</strong> &#8211; <a href="http://mootools.net/">Mootools</a> is my framework of choice, but you can use whatever <a href="http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks">JavaScript framework</a> you&#8217;d like.</li>
<li><strong>Classes</strong> &#8211; Because I see JavaScript as another programming language that I respect (and is capable of object-oriented-like design), I write classes for EVERYTHING. Don&#8217;t think of your JavaScript code as something you use once and throw away. Write your code to be generic enough to be reused wherever it&#8217;s placed. Object-oriented design is great for this! Mootools makes object-oriented design easy to do, so this point reinforces the point above.</li>
<li><strong>Class Files</strong> &#8211; Just like you&#8217;d organize your PHP to contain one class per file, I do the exact same thing with JavaScript. <em>Note: Each of the class files in the example below uses the class name appended with <code>.js</code>.</em></li>
<li><strong>Namespacing</strong> &#8211; I will be organizing my classes in a way that will only add a single property &mdash; PT &mdash; to the global namespace. I won&#8217;t get into the details of namespacing in this blog because I&#8217;m sure you&#8217;re already thinking, &#8220;The code! The code! Get on with it!&#8221; You can namespace whatever is right for your situation.</li>
</ol>
<p>For this example, our classes will be food-themed because &#8230; well &#8230; I enjoy food. Let&#8217;s get started by creating our base object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
---
name: PT
description: The base class for all the custom classes
authors: [Philip Thompson]
provides: [PT]
...
*/</span>
<span style="color: #003366; font-weight: bold;">var</span> PT <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We now have an empty object from which we&#8217;ll build all of our classes. We&#8217;ll go I will go into more details later about the comment section, but let&#8217;s build our first class: <strong>PT.Ham</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
---
name: PT.Ham
description: The ham class
authors: [Philip Thompson]
requires: [/PT]
provides: [PT.Ham]
...
*/</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    PT.<span style="color: #660066;">Ham</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Custom code here...</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As I mentioned in point three (above), PT.Ham should be saved in the file named PT.Ham.js. When we create second class, <strong>PT.Pineapple</strong>, we&#8217;ll store it in PT.Pineapple.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
---
name: PT.Pineapple
description: The pineapple class
authors: [Philip Thompson]
requires: [/PT]
provides: [PT.Pineapple]
...
*/</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    PT.<span style="color: #660066;">Pineapple</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Custom code here...</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Our final class for this example will be <strong>PT.Pizza</strong> (I&#8217;ll let you guess the name of the file where PT.Pizza lives). Our PT.Pizza class will require that PT, PT.Ham and PT.Pineapple be present.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
---
name: PT.Pizza
description: The pizza class
authors: [Philip Thompson]
requires: [/PT, /PT.Ham, /PT.Pineapple]
provides: [PT.Pizza]
...
*/</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    PT.<span style="color: #660066;">Pizza</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Custom code here that uses PT.Ham and PT.Pineapple...</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Before we go any further, let&#8217;s check out the comments we include above each of the classes. The comments are formatted for <a href="http://www.yaml.org/">YAML</a> &mdash; YAML Ain&#8217;t Markup Language (you gotta love recursive acronyms). These comments allow our parser to determine how our classes are related, and they help resolve dependencies. YAML&#8217;s pretty easy to learn and you only need to know a few basic features to use it. The YAML comments in this example are essential for our JavaScript package-manager &mdash; <a href="https://github.com/anutron/packager">Packager</a>. I won&#8217;t go into all the details about Packager, but simply mention a few commands that we&#8217;ll need to build our single JavaScript file.</p>
<p>In addition to the YAML comments in each of the class files, we also need to create a YAML file that will organize our code. This file &mdash; <strong>package.yml</strong> for this example &mdash; is used to load our separate JavaScript classes:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PT&quot;</span>
description<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Provides our fancy PT classes&quot;</span>
authors<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;[Philip Thompson]&quot;</span>
version<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1.0.0&quot;</span>
sources<span style="color: #339933;">:</span>
    <span style="color: #339933;">-</span> js<span style="color: #339933;">/</span>PT.<span style="color: #660066;">js</span>
    <span style="color: #339933;">-</span> js<span style="color: #339933;">/</span>PT.<span style="color: #660066;">Ham</span>.<span style="color: #660066;">js</span>
    <span style="color: #339933;">-</span> js<span style="color: #339933;">/</span>PT.<span style="color: #660066;">Pineapple</span>.<span style="color: #660066;">js</span>
    <span style="color: #339933;">-</span> js<span style="color: #339933;">/</span>PT.<span style="color: #660066;">Pizza</span>.<span style="color: #660066;">js</span></pre></div></div>

<p>package.yml shows that all of our PT* files are located in the js directory, one directory up from the package.yml file. Some of the properties in the YAML file are optional, and you can add much more detail if you&#8217;d like, but this will get the job done for our purposes. </p>
<p>Now we&#8217;re ready to turn back to Packager to build our packaged file. Packager includes an option to use PHP, but we&#8217;re just going to do it command-line. First, we need to register the new package (package.yml) we created for PT. If our JavaScript files are located in <code>/path/to/web/directory/js</code>, the package.yml file is in <code>/path/to/web/directory</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>packager register <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>web<span style="color: #000000; font-weight: bold;">/</span>directory</pre></div></div>

<p>This finds our package.yml file and registers our PT package. Now that we have our package registered, we can build it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>packager build <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>web<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>js<span style="color: #000000; font-weight: bold;">/</span>PT.all.js</pre></div></div>

<p>The Packager sees that our PT package is registered, so it looks at each of the individual class files to build a single large file. In the comments of each of the class files, it determines if there are dependencies and warns you if any are not found. </p>
<p>It might seem like a lot of work when it&#8217;s written out like this, but I can assure you that when you go through the process, it takes no time at all. The huge benefit of packaging our JavaScript is evident as soon as you start incorporating those JavaScript classes into your website &#8230; Because we have built all of our class files into a single file, we don&#8217;t need to include each of the individual JavaScript files into our website (much less include the inline JavaScript declarations that make you cringe). To streamline your implementation even further if you&#8217;re using your JavaScript package in a production deployment, I recommend that you <a href="http://blog.softlayer.com/2011/html5-javascript-web-development-part-i/">&#8220;minify&#8221;</a> your code as well.</p>
<p>See &#8230; Organized code is no longer just for server-side only languages. Treat your JavaScript kindly, and it will be your friend!</p>
<p>Happy coding!</p>
<p>-Philip</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/web-development-javascript-packaging/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using SoftLayer Object Storage to Back Up Your Server</title>
		<link>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/</link>
		<comments>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/#comments</comments>
		<pubDate>Thu, 27 Dec 2012 21:40:01 +0000</pubDate>
		<dc:creator>Ronald Steelman</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[object storage]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SolusVM]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9795</guid>
		<description><![CDATA[Before I came to my senses and moved my personal servers to SoftLayer, I was one of many victims of a SolusVM exploit that resulted in the wide-scale attack of many nodes in my previous host&#8217;s Chicago data center. While I&#8217;m a firm believer in backing up my data, I could not have foreseen the [...]]]></description>
			<content:encoded><![CDATA[<p>Before I came to my senses and moved my personal servers to SoftLayer, I was one of many victims of a SolusVM exploit that resulted in the wide-scale attack of many nodes in my previous host&#8217;s Chicago data center. While I&#8217;m a firm believer in backing up my data, I could not have foreseen the situation I was faced with: Not only was my server in one data center compromised with all of its data deleted, but my backup server in one of the host&#8217;s other data centers was also attacked &#8230; This left me with old, stale backups on my local computer and not much else. I quickly relocated my data and decided that I should use <a href="http://www.softlayer.com/cloudlayer/storage/">SoftLayer Object Storage</a> to supplement and improve upon my backup and disaster recovery plans.</p>
<p>With <a href="https://github.com/softlayer/softlayer-object-storage-python">SoftLayer Object Storage Python Client</a> set up and the SoftLayer Object Storage Backup script &mdash; <a href="http://sldn.softlayer.com/blog/klandreth/Deglazing-slbackuppy-Usage-Object-Storage-Kitchen">slbackup.py</a> &mdash; in hand, I had the tools I needed to build a solid backup infrastructure easily. On Linux.org, I contributed an article about how to <a href="http://www.linux.org/article/view/mysql-backups-using-softlayer-object-storage">perform MySQL backups</a> with those resources, so the database piece is handled, but I also need to back up my web files, so I whipped up another quick <code>bash</code> script to run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The path the backups will be dumped to</span>
<span style="color: #007800;">DUMP_DIR</span>=<span style="color: #ff0000;">&quot;/home/backups/&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Path to the web files to be backed up</span>
<span style="color: #007800;">BACKUP_PATH</span>=<span style="color: #ff0000;">&quot;/var/www/sites /&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Back up folder name (mmddyyyy)</span>
<span style="color: #007800;">BACKUP_DIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`date +%m%d%Y`</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Backup File Name</span>
<span style="color: #007800;">DUMP_FILE</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`date +%m_%d_%Y_%H_%M_%S`</span>_site_files&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># SL container name</span>
<span style="color: #007800;">CONTAINER</span>=<span style="color: #ff0000;">&quot;site_backups&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create backup dir if doesn't exist</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcvpf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DUMP_FILE</span>.tar.gz <span style="color: #007800;">$BACKUP_PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make sure the archive exists</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DUMP_FILE</span>.tar.gz <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>slbackup.py <span style="color: #660033;">-s</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONTAINER</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">30</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Remove the backup stored locally</span>
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Success</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>/<span style="color: #007800;">$DUMP_FILE</span>.tar.gz does not exist.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>It&#8217;s not the prettiest <code>bash</code> script, but it gets the job done. By tweaking a few variables, you can easily generate backups for any important directory of files and push them to your SoftLayer Object Storage account. If you want to change the retention time of your backups to be longer or shorter, you can change the <code>30</code> after the <code>–r</code> in the line below to the number of days you want to keep each backup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>slbackup.py <span style="color: #660033;">-s</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONTAINER</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">30</span></pre></div></div>

<p>I created a script for each website on my server, and I set a CRON (crontab –e) entry to run each one on Sundays staggered by 5 minutes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">5</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site1.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000;">10</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site2.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000;">15</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site3.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

<p>If you&#8217;re looking for an easy way to automate and solidify your backups, this little bit of code could make life easier on you. Had I taken the few minutes to put this script together prior to the attack I experienced at my previous host, I wouldn&#8217;t have lost any of my data. It&#8217;s easy to get lulled into &#8220;backup apathy&#8221; when you don&#8217;t <em>need</em> your backups, but just because nothing *has* happened to your data doesn&#8217;t mean nothing *can* happen to your data.</p>
<p>Take it from me &#8230; Be over-prepared and save yourself a lot of trouble.</p>
<p>-Ronald</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks &#8211; Building a jQuery Plugin (Part 1)</title>
		<link>http://blog.softlayer.com/2012/tips-and-tricks-building-a-jquery-plugin-part-1/</link>
		<comments>http://blog.softlayer.com/2012/tips-and-tricks-building-a-jquery-plugin-part-1/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 20:40:09 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[creating]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[lazyload]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Select2]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9780</guid>
		<description><![CDATA[I&#8217;ve written several blogs detailing the use of different jQuery plugins (like Select2, LazyLoad and equalHeights), and in the process, I&#8217;ve noticed an increasing frustration among the development community when it comes to building jQuery plugins. The resources and documentation I&#8217;ve found online have not as clear and easy as they could be, so in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written several blogs detailing the use of different jQuery plugins (like <a href="http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/">Select2</a>, <a href="http://blog.softlayer.com/2012/tips-and-tricks-jquery-lazy-load-plugin/">LazyLoad</a> and <a href="http://blog.softlayer.com/2012/tips-and-tricks-jquery-equalheights-plugin/">equalHeights</a>), and in the process, I&#8217;ve noticed an increasing frustration among the development community when it comes to building jQuery plugins. The resources and documentation I&#8217;ve found online have not as clear and easy as they could be, so in my next few posts, I&#8217;ll break down the process to make jQuery plugin creation simple and straightforward. In this post, we&#8217;ll cover the basic structure of a plugin and where to insert your own functionality, and in Part 2, we&#8217;ll pick a simple task and add on to our already-made structure.</p>
<p>Before I go any further, it&#8217;s probably important to address a question you might be asking yourself: &#8220;Why would I want to make my own plugin?&#8221; The best reason that comes to my mind is portability. If you&#8217;ve ever created a large-scale project, take a look back into your source code and note how many of the hundreds of lines of jQuery code you could put into a plugin to reuse on a different project. You probably invested a lot of time and energy into that code, so it doesn&#8217;t make sense to reinvent the wheel if you ever need that functionality again. If that&#8217;s not enough of a reason for you, I can also tell you that if you develop your own jQuery plugin, you&#8217;ll level-up in cool points, and the jQuery community will love you.</p>
<p>For this post, let&#8217;s create a jQuery plugin that simply returns, &#8220;This is our awesome plugin!&#8221; Our first step involves putting together the basic skeleton used by every plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// Awesome plugin stuff goes here</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is your template &mdash; your starting point. Practice it. Remember it. Love it. The &#8220;<code>slPlugin</code>&#8221; piece is what I chose to name this plugin. It&#8217;s best to name your plugin something unique &#8230; I always run a quick Google search to ensure I don&#8217;t duplicate the name of a plugin I (or someone else) might need to use in a project alongside my plugin. In this case, we&#8217;re calling the example plugin slPlugin because SoftLayer is awesome, and I like naming my plugins after awesome things. I&#8217;ll save this code in a file called jquery.slPlugin.js.</p>
<p>Now that we have our plugin&#8217;s skeleton, let&#8217;s add some default values for variables:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                myVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;default&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// this will be the default value of this var</span>
                anotherVar<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
                coolVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;this is cool&quot;</span><span style="color: #339933;">,</span>                
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s look at the changes we made between the first example and this one. You&#8217;ll notice that in our second line we added &#8220;options&#8221; to become  <code>$.fn.slPlugin = function(options) {</code>. We do this because our function is now accepting arguments, and we need to let the function know that. The next difference you come across is the <code>var defaults</code> blurb. In this section, we&#8217;re providing default values for our variables. If you don&#8217;t define values for a given variable when you call the plugin, these default values will be used.</p>
<p>Now let&#8217;s have our plugin return the message we want to send:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                myVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This is&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// this will be the default value of this var</span>
                anotherVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;our awesome&quot;</span><span style="color: #339933;">,</span>
                coolVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;plugin!&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                ourString <span style="color: #339933;">=</span> myVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> anotherVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> coolVar<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> ourString<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We&#8217;ve defined our default values for our variables, concatenated our variables and we&#8217;ve added a return under our variable declaration. If our jQuery plugin is included in a project and no values are provided for our variables, slPlugin will return, &#8220;This is our awesome plugin!&#8221; </p>
<p>It seems rather rudimentary at this point, but we have to crawl before we walk. This introductory post is laying the groundwork of coding a jQuery plugin, and we&#8217;ll continue building on this example in the next installment of this series. As you&#8217;ve seen with the LazyLoad, equalHeights and Select2, there are much more complicated things we can do with our plugin, and we&#8217;ll get there. Sneak Preview: In the next installment, we&#8217;ll be creating and implementing a truncation function for our plugin &#8230; Get excited!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/tips-and-tricks-building-a-jquery-plugin-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks &#8211; jQuery Select2 Plugin</title>
		<link>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/</link>
		<comments>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 19:50:27 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[Select2]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9467</guid>
		<description><![CDATA[Web developers have the unique challenge of marrying coding logic and visual presentation to create an amazing user experience. Trying to find a balance between those two is pretty difficult, and it&#8217;s easy to follow one or the other down the rabbit hole. What&#8217;s a web developer to do? I&#8217;ve always tried to go the [...]]]></description>
			<content:encoded><![CDATA[<p>Web developers have the unique challenge of marrying coding logic and visual presentation to create an amazing user experience. Trying to find a balance between those two is pretty difficult, and it&#8217;s easy to follow one or the other down the rabbit hole. What&#8217;s a web developer to do?</p>
<p>I&#8217;ve always tried to go the &#8220;work smarter, not harder&#8221; route, and when it comes to balancing functionality and aesthetics, that usually means that I look around for plugins and open source projects that meet my needs. In the process of sprucing up an form, I came across <a href="http://ivaynberg.github.com/select2/">jQuery Select2</a>, and it quickly became one of my favorite plugins for form formatting. With minimal scripting and little modification, you get some pretty phenomenal results. </p>
<p>We&#8217;ve all encountered drop-down selection menus on web forms, and they usually look like this:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/select.jpg" alt="Option Select"/></p>
<p>Those basic drop-downs meet a developer&#8217;s need for functionality, but they aren&#8217;t winning any beauty pageants. Beyond the pure aesthetic concerns, when a menu contains dozens (or hundreds) of selectable options, it becomes a little unwieldy. That&#8217;s why I was so excited to find Select2.</p>
<p>With Select2, you can turn the old, plain, boring-looking select boxes into beautiful, graceful and more-than-functional select widgets:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/selectpretty.jpg" alt="Pretty Option Select"/></p>
<p>Not only is the overall presentation of the data improved, Select2 also includes an auto-complete box. A user can narrow down the results quickly ad easily, and if you&#8217;ve got some of those endlessly scrolling select boxes of country names or currencies, your users will absolutely notice the change (and love you for it).</p>
<p>What&#8217;s even sexier than the form facelift is that you can add the plugin to your form in a matter of minutes.</p>
<p>After we <a href="https://github.com/ivaynberg/select2/tags">download Select2</a> and upload it to our box, we add our the jQuery library and scripts to the <code>&lt;head&gt;</code> of our document:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;select2.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>For the gorgeous styling, we&#8217;ll also add Select2&#8242;s included style sheet:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;select2.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Before we close our <code>&lt;head&gt;</code> tag, we invoke the Select2 function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#selectPretty&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">select2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>At this point, Select2 is locked and load, and we just have to add the <code>#selectPretty</code> ID to the <code>select</code> element we want to improve:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selectPretty&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option1&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option2&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">2</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option3&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">3</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option4&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">4</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Notice: the <code>selectPretty</code> ID is what we defined when we invoked the Select2 function in our <code>&lt;head&gt;</code> tag.</p>
<p>With miniscule coding effort, we&#8217;ve made huge improvements to the presentation of our usually-boring select menu. It&#8217;s so easy to implement that even the most black-and-white coding-minded web developers can add some pizzazz to their next form without having to get wrapped up in styling!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks &#8211; jQuery Lazy Load Plugin</title>
		<link>http://blog.softlayer.com/2012/tips-and-tricks-jquery-lazy-load-plugin/</link>
		<comments>http://blog.softlayer.com/2012/tips-and-tricks-jquery-lazy-load-plugin/#comments</comments>
		<pubDate>Wed, 26 Sep 2012 14:00:25 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[HMTL]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[page load]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9346</guid>
		<description><![CDATA[In the late 90&#8242;s, web pages presented their information in a relatively structured fashion, with little concern on how &#8220;pretty&#8221; the content looked. To a certain extent, that was a result of available technology and resources being a little more limited, but much of the reason was probably because we had no idea what was [...]]]></description>
			<content:encoded><![CDATA[<p>In the late 90&#8242;s, web pages presented their information in a relatively structured fashion, with little concern on how &#8220;pretty&#8221; the content looked. To a certain extent, that was a result of available technology and resources being a little more limited, but much of the reason was probably because we had no idea what was possible. We&#8217;ve come a long way, my friend. These days, it&#8217;s tough to spend an hour online without coming across a gorgeous web site with huge animations, a pallet of every color possible, full-width backgrounds and high definition detail.</p>
<p>Those sites may be aesthetically pleasing, but they can be a big pain from a developer&#8217;s perspective. </p>
<p>How much load does all of that stuff put on the server every time that web page is visited? As developers, it&#8217;s our job to think about both what the visitor sees AND the visitor&#8217;s experience in seeing it. Even the most beautiful sites will be ignored if a page takes too long to load. We spend hours optimizing every detail so users can fluidly browse without having to wait. It was in one of these optimization sessions that I discovered &#8220;lazy load.&#8221; </p>
<p>To be honest, I wasn&#8217;t too fond of the word &#8220;lazy&#8221; in the name, and I especially wasn&#8217;t fond of having to explain to my boss that *I* wasn&#8217;t being lazy &#8230; The jQuery plugin  is *named* &#8220;<a href="http://www.appelsiini.net/projects/lazyload">Lazy Load</a>.&#8221; Lazy Load effectively allows large pieces of content to stay in the backlog until they&#8217;re needed. To give you an example of what that looks like, let&#8217;s say you have a website with three humungous images, but they&#8217;re all in different locations. Instead of pushing the entire load onto the user when they first land on your page, we can break them up and have them load only when the user goes to view them. We&#8217;re not reducing the size of the web page; we&#8217;re merely helping it work smarter.</p>
<p>Without Lazy Load, a normal web page loads each item when its page is visited. If a website has videos, music, images and some neat user interactivity applications, each of those items will load at the same time: </p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/lazyload.jpg" alt="Lazy Load Illustration"/></p>
<p>If you take into consideration how large each of those items are, you can sense the problem. The user only has so much bandwidth to load these items, and something&#8217;s gotta give. Usually, it means long loading times. We can&#8217;t control how fast each user&#8217;s ISP is, but we <em>can</em> reorder our items and let Lazy Load help us prioritize items and load the page more efficiently.</p>
<p>After we snag <a href="https://raw.github.com/tuupola/jquery_lazyload/master/jquery.lazyload.js">Lazy Load on Github</a> (jquery.lazyload.js), we put our jQuery scripts in the <code>&lt;head&gt;</code> of our page:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.lazyload.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now that the plugin is available to us, we need to determine what we want to load lazily. Images are probably one of the most bothersome page elements, so let&#8217;s apply Lazy Load to the images we load in the <code>belazy</code> class. In the <code>&lt;head&gt;</code> of your page (or in the footer if you prefer your JavaScript entries there), you&#8217;ll add:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img.belazy&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">lazyload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>As a result of that function, all image tags with a class of <code>belazy</code> will have Lazy Load run on them. This helps us ensure that we&#8217;re not loading ALL of our images lazily. Now we need to choose which images we want to apply Lazy Load to.</p>
<p>Let&#8217;s say the image tag of the largest image on one of our page looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bighonkingimage.png&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>To have the lazyload function apply to it, we just have to make a couple tweaks:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;belazy&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bighonkingimage.png&quot;</span> data-original<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bighonkingimage.png&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>We added <code>class="belazy"</code> to trigger the lazyload function, and we added <code>data-original="bighonkingimage.png"</code> to line up with the formatting required by the newest version of Lazy Load (it&#8217;s simply a repeat of the source).</p>
<p>When a user visits our page, bighonkingimage.png will load only when it&#8217;s needed!</p>
<p>Pretty neat, eh?</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/tips-and-tricks-jquery-lazy-load-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks &#8211; jQuery equalHeights Plugin</title>
		<link>http://blog.softlayer.com/2012/tips-and-tricks-jquery-equalheights-plugin/</link>
		<comments>http://blog.softlayer.com/2012/tips-and-tricks-jquery-equalheights-plugin/#comments</comments>
		<pubDate>Thu, 06 Sep 2012 20:05:31 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[divs]]></category>
		<category><![CDATA[equalHeights]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9190</guid>
		<description><![CDATA[Last month, I posted a blog about dynamically resizing divs with jQuery, and we received a lot of positive feedback about it. My quest to avoid iframes proved to be helpful, so I thought I&#8217;d share a few more esoteric jQuery tips and tricks that may be of use to the developers and designers in [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, I posted a blog about <a href="http://blog.softlayer.com/2012/no-iframes-dynamically-resize-divs-with-jquery/">dynamically resizing divs with jQuery</a>, and we received a lot of positive feedback about it. My quest to avoid iframes proved to be helpful, so I thought I&#8217;d share a few more esoteric jQuery tips and tricks that may be of use to the developers and designers in the audience. As I thought back about other challenges I&#8217;ve faced as a coder, a great example came to mind: Making divs equal height, regardless of the amount of content inside.</p>
<p>I haven&#8217;t seen many elegant div-based solutions for that relatively simple (and common) task, so I&#8217;ve noticed that many people struggle with it. Often, developers will turn back to the &#8220;Dark Side&#8221; of using tables to format the content since all columns would have the same height as the tallest column by default:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/jquery1.png" alt="JQuery Tutorial"/></p>
<p>It was easy theme table columns and to achieve the coveted 100% height that many designers seek, but emulating that functionality with divs proves to be much more difficult. A div is like the Superman of HTML elements (faster-loading, more flexible, more dynamic, etc.), and while it has super powers, it also has its own Kryptonite-like weaknesses &#8230; The one relevant to this blog post being that floating three div elements next to each other isn&#8217;t going to give you the look of a table:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/jquery2.png" alt="JQuery Tutorial"/></p>
<p>Each of the three divs has its own height, so if you&#8217;re doing something as simple as applying background colors, you&#8217;re going to wind up with an aesthetically unpleasing result: It&#8217;s going to look funky.</p>
<p>You could get into some nifty HTML/CSS workarounds, but many frustrated theme creators and designers will tell you that if your parent elements don&#8217;t have a height of a 100%, you&#8217;re just wasting coding lines. Some complex solutions create the illusion of all three divs being the same height (which is arguably better than setting fixed heights), but that complexity can be difficult to scale and repeat if you need to perform similar tasks throughout your site or your application. The easiest way to get the functionality you want and the simplicity you need: The <a href="http://www.cssnewbie.com/download/jquery.equalheights.js">jQuery equalHeights</a> plugin!</p>
<p>With a few class declarations in your existing HTML, you get the results you want, and with equalHeights, you can also specify the minimum and maximum parameters so it will create scrollable divs if the tallest element happens to be higher than your specified maximum.</p>
<h3>How to Use jQuery equalHeights</h3>
<p>First and foremost, include your JQuery lirbraries in the <code>&lt;HEAD&gt;</code> of your document:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;jquery.equalheights.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The equalHeights plugin is not a hosted library, so you have to host the file on your server (<a href="http://www.cssnewbie.com/download/jquery.equalheights.js">here&#8217;s the link again</a>).</p>
<p>With the required libraries called in our document, it&#8217;s time to make the magic happen in your HTML.</p>
<p><strong>Create Your Divs</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divHeight&quot;</span>&gt;</span>This DIV is medium sized, not too big and not too small, but just right.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divHeight&quot;</span>&gt;</span>This DIV has a lot of useful content and media that the user can interact with, thus it's very tall.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divHeight&quot;</span>&gt;</span>This DIV is tiny. Period.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>To have them line up next to each other, you&#8217;d have them <code>float:left;</code> in your CSS, and now you need to apply the equalHeights function.</p>
<p><strong>Call the equalHeights Plugin</strong><br />
In order for the script to recognize the height of the tallest element, you&#8217;d need to call <code>$(document).ready</code> just before the <code>&lt;/body&gt;</code> tag on your page. This will ensure that the page loads before the function runs. </p>
<p>The call looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.divHeight&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">equalHeights</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>If you want to specify a minimum and maximum (i.e. The div should be at least this tall and should be no taller than [adds scrollbar if the div size exceeds] the maximum), just add the parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.divHeight&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">equalHeights</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The initial call does not change the appearance of the divs, but the time it takes to do the resizing is so miniscule that users will never notice. After that call is made and the height is returned, each div with the class of <code>divHeight</code> will inherit the the same height, and your divs will be nice and pretty:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/jquery3.png" alt="JQuery Tutorial"/></p>
<p>This trick saved me a lot of headache and frustration, so hopefully it will do the same for you too!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/tips-and-tricks-jquery-equalheights-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Meet Memcached: A Developer&#8217;s Best Friend</title>
		<link>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/</link>
		<comments>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 17:10:31 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opportunity]]></category>
		<category><![CDATA[potential]]></category>
		<category><![CDATA[rich media]]></category>
		<category><![CDATA[snippits]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=8765</guid>
		<description><![CDATA[Whether you&#8217;re new to software development or you&#8217;ve been a coder since the punchcard days, at some point, you&#8217;ve probably come across horrendous performance problems with your website or scripts. From the most advanced users &#8212; creating scripts so complex that their databases flooded with complex JOINs &#8212; to the novice users &#8212; putting SQL [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you&#8217;re new to software development or you&#8217;ve been a coder since the punchcard days, at some point, you&#8217;ve probably come across horrendous performance problems with your website or scripts. From the most advanced users &mdash; creating scripts so complex that their databases flooded with complex JOINs &mdash; to the novice users &mdash; putting SQL calls in loops &mdash; database queries <em>can</em> be your worst nightmare as a developer. I hate to admit it, but I&#8217;ve experienced some these nightmares first-hand as a result of some less-than-optimal coding practices when writing some of my own scripts. Luckily, I&#8217;ve learned how to use <a href="http://memcached.org/">memcached</a> to make life a little easier. </p>
<h3>What is Memcached?</h3>
<p>Memcached is a free and open source distributed memory object caching system that allows the developer to store any sort of data in a temporary cache for later use, so they don&#8217;t have to re-query it. By using memcached, a tremendous performance load can be decreased to almost nil. One of the most noteworthy features of the system is that it doesn&#8217;t cache EVERYTHING on your site/script; it only caches data that is sure to be queried often. Originally developed in 2003 by Brad Fitzpatrick to improve the site performance of LiveJournal.com, memcached has grown tremendously in popularity, with some of the worlds biggest sites &mdash; Wikipedia, Flickr, Twitter, YouTube and Craigslist &mdash; taking advantage of the functionality.</p>
<h3>How Do I Use Memcache?</h3>
<p>After installing the memcached library on your server (available at <a href="http://memcached.org/">http://memcached.org/</a>), it&#8217;s relatively simple to get started:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// Set up connection to Memcached</span>
  <span style="color: #000088;">$memcache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Memcached<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'host'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11211</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Connect to database here</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Check the cache for your query</span>
  <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM memcached_test WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// if the data exists in the cache, get it!</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Got it from the cache!'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// data didn't exist in the cache</span>
    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM memcached_test WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// though we didn't find the data this time, cache it for next time!</span>
  <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// Stores the result of the query for 30 seconds</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'In the cache now!'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Querying the cache is very similar to querying any table in your database, and if that data isn&#8217;t cached, you&#8217;ll run a database query to get the information you&#8217;re looking for, and you can add that information to the cache for the next query. If another query for the data doesn&#8217;t come within 30 seconds (or whatever window you specify), memcached will clear it from the cache, and the data will be pulled from the database.</p>
<p>So come on <a href="http://sldn.softlayer.com">developers</a>! Support memcached and faster load times! What other tools and tricks do you use to make your applications run more efficiently?</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New SoftLayer.com Design: Build the Future</title>
		<link>http://blog.softlayer.com/2012/new-softlayer-com-design-build-the-future/</link>
		<comments>http://blog.softlayer.com/2012/new-softlayer-com-design-build-the-future/#comments</comments>
		<pubDate>Tue, 05 Jun 2012 18:15:41 +0000</pubDate>
		<dc:creator>Brad Lucido</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[team]]></category>
		<category><![CDATA[typography]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=8258</guid>
		<description><![CDATA[If you&#8217;ve been reading the SoftLayer Blog via an RSS feed or if you find yourself navigating directly to the portal to manage your SoftLayer account, you might not have noticed that the our main website has been updated again &#8212; and in dramatic fashion. Last fall we gave the site a slight refresh &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been reading the SoftLayer Blog via an RSS feed or if you find yourself navigating directly to the portal to manage your SoftLayer account, you might not have noticed that the our main website has been updated again &mdash; and in dramatic fashion. Last fall we <a href="http://blog.softlayer.com/2011/softlayer-com-website-refresh/">gave the site a slight refresh</a> &#8230; This time, we did a total rework.</p>
<p>We took the site in a new visual direction, with graphics and messaging to complement our mantra of customers using our platform to create their vision &mdash; to build the future.</p>
<p><a href="http://www.softlayer.com"><img class="centered" src="http://cdn.softlayer.com/innerlayer/slblackhome.png" alt="SoftLayer Homepage"/></a></p>
<p>The new look &mdash; referred to as &#8220;SoftLayer at Night&#8221; by my fellow SoftLayer developer friend, Seth Thornberry &mdash; was designed to reflect our core identity, and it retires the faithful red, white and grey theme that has served us well for more than three years. The new style has received rave reviews from customers, partners and employees, and even if there has been some criticism &mdash; everyone has an opinion nowadays &mdash; we can generally chalk it up to people simply not liking change.</p>
<p style="margin-bottom:5px; padding-bottom:0;"><strong>Highlights of the Redesign:</strong></p>
<ul style="margin-top:0; padding-top:0;">
<li>A dramatic new home page design, including visually rich &#8220;hero images&#8221; (where you see &#8220;The InnerLayer&#8221; heading if you&#8217;re reading this on the SoftLayer Blog)<br />
<a href="http://www.softlayer.com/about"><img style="margin: 20px auto;" class="centered" src="http://cdn.softlayer.com/innerlayer/slblackhero.png" alt="SoftLayer Homepage Hero Image"/></a></li>
<li>Expanded main navigation menus at the top of each page<br />
<a href="http://www.softlayer.com"><img style="margin: 20px auto;" class="centered" src="http://cdn.softlayer.com/innerlayer/slblacktopnav.png" alt="SoftLayer Homepage Top Nav"/></a></li>
<li>A new lower-order navigation system on the left of all content pages</li>
<p><a href="http://www.softlayer.com/dedicated-hosting"><img style="margin: 20px auto;" class="centered" src="http://cdn.softlayer.com/innerlayer/slblacksidenav.png" alt="SoftLayer Homepage Side Nav"/></a></li>
<li>[For typographically inclined] The new design also leverages <a href="http://blog.softlayer.com/2012/web-development-html5-web-fonts/">web fonts</a> functionality to incorporate &#8220;Benton Sans,&#8221; the corporate font used in print, interactive and other marketing communications.<br />
<a href="http://www.softlayer.com/cloudlayer"><img style="margin: 20px auto;" class="centered" src="http://cdn.softlayer.com/innerlayer/slblackfont.png" alt="SoftLayer Homepage Side Nav"/></a></li>
</ul>
<p>The new design was executed in-house, and our workflow was pretty traditional &#8230; We like to roll up our sleeves. Page templates were created as PSD files and then hand-coded in HTML, PHP, JavaScript and CSS on top of the same framework we use for the SoftLayer Customer Portal. </p>
<p>During the development process, we used our new <a href="http://git-scm.com/">GIT code repository</a> to facilitate the merging of all of our code onto our staging server. Since it was our first time to use GIT in a major way, there was a bit of a learning curve. The first few merges had to be reworked after finding a few errors in commit messages, but after we got a little practice, the subsequent merges went off without a hitch. The final staging merge was a breeze, and given the struggles we&#8217;ve had with SVN in past projects, this was a huge relief.</p>
<p>When it came time for the design&#8217;s official launch, we ran into a hiccup related to our automatic regression testing system and problems with cached CSS files, but these issues were quickly resolved, and the new-look SoftLayer.com went live. </p>
<p>It took a lot of hard work from (and a lot of caffeine for) a number of people to get the new site out the door, so I&#8217;d like to make sure credit goes where it&#8217;s due. Our lead designer Carlos (&#8220;Los&#8221;) Ruiz did a majority of the design work, and the implementation of that design fell to Dennis Dolliver (Website Developer), Charles King (SEO Manager) and me. I should also send a shout-out to the entire marketing team who jumped in to help to proof content, test pages and keep everyone sane.</p>
<p>What do you think of the new design? Stay tuned for more website improvements and additions!</p>
<p>-Brad</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/new-softlayer-com-design-build-the-future/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTML5 &#8211; Compatibility for All?</title>
		<link>http://blog.softlayer.com/2012/html5-compatibility-for-all/</link>
		<comments>http://blog.softlayer.com/2012/html5-compatibility-for-all/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 18:10:05 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opportunity]]></category>
		<category><![CDATA[potential]]></category>
		<category><![CDATA[rich media]]></category>
		<category><![CDATA[snippits]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=7712</guid>
		<description><![CDATA[Many of us remember when Flash was the &#8220;only&#8221; way to enhance user experience and create rich media interactivity. It was a bittersweet integration, though &#8230; Many users didn&#8217;t have the browser compatibility to use it, so some portion of your visitors were left in the dark. Until recently, that user base was relatively small [...]]]></description>
			<content:encoded><![CDATA[<p>Many of us remember when <a href="http://get.adobe.com/flashplayer/">Flash</a> was the &#8220;only&#8221; way to enhance user experience and create rich media interactivity. It was a bittersweet integration, though &#8230; Many users didn&#8217;t have the browser compatibility to use it, so some portion of your visitors were left in the dark. Until recently, that user base was relatively small &mdash; the purists who didn&#8217;t want Flash or the people whose hardware/software couldn&#8217;t support it. When Apple decided it wouldn&#8217;t enable Flash on the iPhone/iPad, web developers around the world groaned. A HUGE user base (that&#8217;s growing exponentially) couldn&#8217;t access the rich media and interactive content.</p>
<p>In the last year or so, Adobe released <a href="http://www.bgr.com/2011/09/09/adobe-finally-brings-flash-to-iphone-and-ipad/">Flash Media Server</a> to circumvent the Apple-imposed restrictions, but the larger web community has responded with a platform that will be both compatible and phenomenally functional: HTML5. </p>
<p>HTML5 allows us to do things we&#8217;ve never been able to do before (at least without the hassle of plugins, installations and frustration). Gone are the limitations that resigned HTML to serving as a simple framework for webpages &#8230; Now developers can push the limits of what they thought possible. As the platform has matured, some developers have even taken it upon themselves to prototype exactly where this generation of scripting is heading by creating Flash-free browser games. </p>
<p>Yes, you read that right: Games you can actually play on your browser, WITHOUT plugins. </p>
<p>From simple <a href="http://stewd.io/pong/">Pong</a> clones that use browser windows as the paddles and ball to adventure-based Zelda-like massively multiplayer online role playing games (MMORPGs) like <a href="http://browserquest.mozilla.org/">BrowserQuest</a>, it&#8217;s pretty unbelievable to see the tip of the iceberg of possibilities enabled by HTML5 &#8230; Though it does seem a bit ironic to say that a Pong clone is such a great example of the potential of the HTML5 platform. Click on the screenshot below to check out BrowserQuest and tell me it doesn&#8217;t amaze you:</p>
<p><a href="http://browserquest.mozilla.org/" target="blank"><img class="centered" src="http://cdn.softlayer.com/innerlayer/browserquest.jpg" alt="Browser Quest"/></a></p>
<p>With an ingenious combination of CSS, JavaScript and HTML5, developers of BrowserQuest have been able to accomplish something that no one has ever seen (nor would ever even have thought possible). Developers are now able to generate dynamic content by injecting JavaScript into their HTML5 canvasses:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> handleKeyDown<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	keys<span style="color: #009900;">&#91;</span>evt<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> handleKeyUp<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	keys<span style="color: #009900;">&#91;</span>evt<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// disable vertical scrolling from arrows :)</span>
document<span style="color: #339933;">.</span>onkeydown<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span> event<span style="color: #339933;">.</span>keyCode<span style="color: #339933;">!=</span><span style="color: #cc66cc;">38</span> <span style="color: #339933;">&amp;&amp;</span> event<span style="color: #339933;">.</span>keyCode<span style="color: #339933;">!=</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Look familiar? The game-making process (not syntax!) appears eerily similar to that of any other popular language. The only difference: You don&#8217;t need to install this game &#8230; You just open your browser and enjoy.</p>
<p>Using a popular port of Box2D, a physics simulator, making pure browser-based games is as simple as &#8220;Make. Include. Create.&#8221; Here&#8217;s a snippit:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">//Make your canvas</span>
<span style="color: #339933;">&lt;</span>canvas id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;game&quot;</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;600&quot;</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;400&quot;</span><span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span>  
&nbsp;
<span style="color: #666666; font-style: italic;">//include your js physics files</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create your world</span>
<span style="color: #000000; font-weight: bold;">function</span> createWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// here we create our world settings for collisions</span>
	<span style="color: #000000; font-weight: bold;">var</span> worldAABB <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2AABB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	worldAABB<span style="color: #339933;">.</span>minVertex<span style="color: #339933;">.</span>Set<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	worldAABB<span style="color: #339933;">.</span>maxVertex<span style="color: #339933;">.</span>Set<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// set gravity vector</span>
	<span style="color: #000000; font-weight: bold;">var</span> gravity <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2Vec2<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> doSleep <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// init our world and return its value</span>
	<span style="color: #000000; font-weight: bold;">var</span> world <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2World<span style="color: #009900;">&#40;</span>worldAABB<span style="color: #339933;">,</span> gravity<span style="color: #339933;">,</span> doSleep<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> world<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>We may be a few years away from building full-scale WoW-level MMORPGs with HTML5, but I think seeing this functionality in native HTML will be a sigh of relief to those that&#8217;ve missed out on so much Flash goodness. While developers are building out the next generation of games and apps that will use HTML5, you can keep yourself entertained (and waste hours of time) with the HTML5 port of <a href="http://chrome.angrybirds.com">Angry Birds</a>! </p>
<p><a href="http://chrome.angrybirds.com"><img class="centered" src="http://cdn.softlayer.com/innerlayer/angrybirdsbrowser.jpg" alt="Angry Birds"/></a></p>
<p>HTML5 is not immune to some browser compatibility issues with older versions, but as it matures and becomes the standard platform for web development, we&#8217;re going to see what&#8217;s to come in our technology&#8217;s immediate future: Pure and simple compatibility for all.</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/html5-compatibility-for-all/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
