<?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; exercise</title>
	<atom:link href="http://blog.softlayer.com/tag/exercise/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>Giving From (and For) the Heart</title>
		<link>http://blog.softlayer.com/2012/giving-from-and-for-the-heart/</link>
		<comments>http://blog.softlayer.com/2012/giving-from-and-for-the-heart/#comments</comments>
		<pubDate>Mon, 24 Dec 2012 18:26:24 +0000</pubDate>
		<dc:creator>Guest Blog</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[AHA]]></category>
		<category><![CDATA[American Heart]]></category>
		<category><![CDATA[awareness]]></category>
		<category><![CDATA[charity]]></category>
		<category><![CDATA[Dallas]]></category>
		<category><![CDATA[exercise]]></category>
		<category><![CDATA[fundraising]]></category>
		<category><![CDATA[giving]]></category>
		<category><![CDATA[heart]]></category>
		<category><![CDATA[Houston]]></category>
		<category><![CDATA[walking]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10323</guid>
		<description><![CDATA[This time of year is often referred to as &#8220;The Season of Giving,&#8221; and we thought we&#8217;d share two SLayers&#8217; stories about their involvement in the American Heart Association Heart Walk. Like last year, we split up into fundraising teams for the AHA with a goal of raising $100,000. In addition to those fundraising efforts, [...]]]></description>
			<content:encoded><![CDATA[<p class="attribution">This time of year is often referred to as &#8220;The Season of Giving,&#8221; and we thought we&#8217;d share two SLayers&#8217; stories about their involvement in the American Heart Association <a href="http://www.heartwalk.org/">Heart Walk</a>. Like <a href="http://blog.softlayer.com/2011/american-heart-association-fundraiser-marketing/">last year</a>, we split up into fundraising teams for the AHA with a goal of raising $100,000. In addition to those fundraising efforts, SoftLayer also encouraged employees to get active and get involved in the annual Heart Walks in Houston and Dallas. Here&#8217;s our on-location coverage from two team captains who attended those events this year:</p>
<h3>Dallas</h3>
<p>My name is Fabrienne Curtis, and I work in the Accounting Department at SoftLayer. I joined a team with thirty other people (from several different departments) to raise money for the American Heart Association, and because I love to help and work on community projects, I volunteered to be a team captain. Our team had a ton of great ideas for fundraisers, so we set an ambitious goal of raising $12,400 ($400 per person). When the dust settled, I&#8217;m proud to report that we me that goal with a total team tally of $12,488 (which SoftLayer then matched).</p>
<p>Beyond the fundraising, participating in the Dallas Heart Walk at Victory Park was a highlight this year. No one on my team knew that this walk had a personal meaning to me &#8230; I lost my dad to congestive heart failure and wanted to walk in his behalf. When I got to the Heart Walk, I was touched. There was a &#8220;Survivor Wall&#8221; and there were several signs where you could share who you&#8217;re walking on behalf of. If not for SoftLayer, I probably wouldn&#8217;t have participated in the Heart Walk, so as I wrote on the wall and created a sign for my dad, I thought about how good it felt to work for a company that truly cares about the well-being of its employees.</p>
<p><img class="centered" src="http://farm9.staticflickr.com/8348/8241436799_a6772e5299.jpg" alt="SoftLayer Photo Booth"/></p>
<p>SoftLayer added a little flair to the event by setting up a photo booth for people to take pictures and take home, and with the help of Don Hunter, Hao Ho and my husband Jerry, 679 photos were taken!</p>
<p><img class="centered" src="http://farm9.staticflickr.com/8345/8242505416_1b1951bd9b.jpg" alt="SoftLayer Photo Booth"/></p>
<p>Here are some pictures I snapped from the 2012 Dallas Heart Walk:</p>
<div class="polaroid"><img class="centered" src="http://farm9.staticflickr.com/8482/8241436675_a11ce27692.jpg" alt="SoftLayer Heart Walk"/></p>
<div class="pic-caption"><strong>The Start!</strong></div>
</div>
<div class="polaroid"><img class="centered" src="http://farm9.staticflickr.com/8486/8242505484_6633faa817.jpg" alt="SoftLayer Heart Walk"/></p>
<div class="pic-caption"><strong>The SoftLayer &#8220;Uniform&#8221;</strong></div>
</div>
<div class="polaroid"><img class="centered" src="http://farm9.staticflickr.com/8349/8241436623_c57511ab73.jpg" alt="SoftLayer Heart Walk"/></p>
<div class="pic-caption"><strong>The Crowd</strong></div>
</div>
<div class="polaroid"><img class="centered" src="http://farm9.staticflickr.com/8209/8241436853_50344b1181.jpg" alt="SoftLayer Heart Walk"/></p>
<div class="pic-caption"><strong>Victorious!</strong></div>
</div>
<p>Thank you SoftLayer for having a heart! If you want more coverage of this years event, check out this <a href="http://animoto.com/play/otf64C3AkcrG6iuouvCuIw">Dallas Heart Walk 2012</a> video and click through to our <a href="http://www.flickr.com/photos/softlayer/sets/72157632160245027/">Dallas Heart Walk Flickr album</a>.</p>
<p>-Fabrienne</p>
<h3>Houston</h3>
<p>Dallas didn&#8217;t get to have all of the fun when it comes to the AHA Heart Walk, and I made sure to document the Houston goings-on to share with our avid SoftLayer Blog readers. From bake sales to ice cream socials, the Houston office was diligent about donating money and raising heart-health awareness for months prior to the 2012 walk, and those months were extremely eventful. Like Fabrienne, I jumped at the opportunity to be one of 18 team captains at SoftLayer, and considering the fact that cardiovascular disease is the number one killer of Americans, I was inspired to get everyone involved.</p>
<p>I&#8217;ll be the first to admit that I am not in the best of shape, so a five-kilometer walk through a course at Reliant Stadium would be pretty challenging. My team had been tirelessly preparing for the 5k &#8220;mini-marathon&#8221; walk, and as November approached, you could sense the excitement and enthusiasm brewing. Walking only one mile can add up to two hours to your lifespan, so in the process of preparing for the walk, we added quite a few hours to our collective lives. When the big day finally arrived, we were ready:</p>
<div class="polaroid"><img class="centered" src="http://farm9.staticflickr.com/8354/8304766736_c38e26994b.jpg" alt="SoftLayer Heart Walk"/></p>
<div class="pic-caption"><strong>The Houston Heart Walk SLayers</strong></div>
</div>
<p>Given that our day started at an unbelievable 7:00am on a Saturday, most of our participants were tired-eyed and ready to chow down on the free burritos and fruit provided by SoftLayer, and by the time we fired up the photo booth and broke out the goofy props, everyone was wide awake. It&#8217;s like they say, &#8220;Give a man a fish and he&#8217;ll eat for a day &#8230; Give a man fun props and a camera, and he&#8217;ll have a blast (and pictures that can be used against him.&#8221; Actually, I don&#8217;t know if &#8220;they&#8221; say that, but it&#8217;s true:</p>
<p><img class="centered" src="http://farm9.staticflickr.com/8501/8304766782_e1988e25bc.jpg" alt="SoftLayer Heart Walk"/></p>
<p>Before we knew it, a gunshot of glitter and colorful confetti got the crowd of people moving down the 3.1-ish mile track, and we were hooting and cheering, pumped to represent our company! By mile two, my legs were a little wobbly and the sun was scorching, I could see that our dog, Rikku (whom had been carried the entire way) looked was confused about why I was putting her through the exhausting task of being comfortably in my arms as we herded through the people like cattle.</p>
<p><img class="centered" src="http://farm9.staticflickr.com/8084/8304766902_5877e92e34.jpg" alt="SoftLayer Heart Walk"/></p>
<p>AHA water stations and mile markers reminded us that we were doing it for the best cause ever: The people we love and the people of the past that have been lost due to heart disease. It&#8217;s a safe bet that if you don&#8217;t know someone directly affected by heart disease, you will eventually. The American Heart Association organizes these fundraisers and walks every year across the world to gather donations and raise awareness so that one day, we may be able to conquer this silent killer. With their donations, they&#8217;re able to participate in research for preventative treatment, provide education to children to avoid obesity and fund medical research that could one day breakthrough and save lives.</p>
<p>All in all it was a wonderful experience, one that I&#8217;ll definitely be sure to be a part of next year.</p>
<p>-Cassandra</p>
<p><img class="centered" src="http://farm9.staticflickr.com/8492/8304766934_637d1aa380.jpg" alt="SoftLayer Heart Walk"/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/giving-from-and-for-the-heart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Exercise in Innovation</title>
		<link>http://blog.softlayer.com/2011/an-exercise-in-innovation/</link>
		<comments>http://blog.softlayer.com/2011/an-exercise-in-innovation/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 14:00:47 +0000</pubDate>
		<dc:creator>Lance Crosby</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[Executive Blog]]></category>
		<category><![CDATA[Funny]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[creative]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[employees]]></category>
		<category><![CDATA[exercise]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[innovation]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[invent]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/2011/</guid>
		<description><![CDATA[Some of the best ideas come from people who think &#8220;outside of the box.&#8221; SoftLayer was born in a living room six years ago when we decided to look at the staid hosting industry from a new perspective. We said, &#8220;We don&#8217;t want to build a company to meet customers&#8217; current needs. We want to [...]]]></description>
			<content:encoded><![CDATA[<p>Some of the best ideas come from people who think &#8220;outside of the box.&#8221; SoftLayer was born in a living room six years ago when we decided to look at the staid hosting industry from a new perspective. We said, &#8220;We don&#8217;t want to build a company to meet customers&#8217; current needs. We want to build a company to meet the needs our customers don&#8217;t even know they have yet,&#8221; and that&#8217;s one of the biggest reasons the SoftLayer platform has IPv6, KVM over IP, private network, out-of-band management and standardized pod-based data centers.</p>
<p>Only people with a certain level of &#8220;crazy&#8221; can recognize opportunities for innovation, and because SoftLayer&#8217;s motto is &#8220;Innovate or Die,&#8221; to incubate innovation, we have to <a href="http://blog.softlayer.com/2011/3-bars-3-questions-softlayer-culture/">create an environment</a> that enables employees to take their &#8220;crazy&#8221; and run with it. Speaking of &#8220;crazy,&#8221; meet Phil.</p>
<p>Phil <a href="http://www.youtube.com/watch?v=Iiq-iKxykJ8">plays guitar</a>, tests software in <a href="http://www.youtube.com/watch?v=XC4G9qcih0s">non-standard ways</a>, and has <a href="http://cdn.softlayer.com/innerlayer/phil.jpg">a bobble-head of himself</a>. Some would say he marches to the beat of a different drummer &ndash; a drummer that may or may not be overdosing on caffeine.</p>
<p>Phil was tasked with a 12-week project: If SoftLayer is built for what our customers are going to need tomorrow, figure out what customers will need after &#8220;tomorrow.&#8221; He&#8217;d have access to people and resources up and down the organization to build his idea, and the experiment is set up to incubate his innovation:</p>
<ol>
<li>Because there are no bad ideas in brainstorming, anyone helping Phil should do so without questioning the logic or &#8220;sanity&#8221; of what he asking for help with.</li>
<li>Phil can spend up to 20% of his work hours building his idea.</li>
<li>Anyone who helps Phil can spend up to 10% of his/her work hours to build his idea.</li>
<li>Phil can have space in H2 to build his idea.</li>
<li>Regardless of apparent success or failure, the project will conclude at the end of 12 weeks. From there, we&#8217;ll evaluate the &#8220;good&#8221; and &#8220;not as good&#8221; ideas from the experiment.</li>
</ol>
<p>It&#8217;d be impossible to guarantee the success of any kind of project like this because it&#8217;s a little like catching lightning in a bottle, but I was interested to see what kinds of operational changes he came up with over the course of the three months. We might see the evolution of the next brilliant idea in hosting, or we&#8217;d see a lot of hilariously terrible ideas.</p>
<p>Then I saw his first installment:</p>
<div class="yt560"><iframe width="560" height="349" src="http://www.youtube.com/embed/36XXIowcP64" frameborder="0" allowfullscreen></iframe></div>
<p>By the time I got to &#8220;circumstantiate,&#8221; I had the phone in my hand to call off the project. What I didn&#8217;t expect was Phil&#8217;s tearful pleading to take the idea down a different path. They say you don&#8217;t get a second chance to make a first impression, and despite the fact that this first impression was pretty awful, I decided to give him another shot (with a much more limited scope):</p>
<ol>
<li>Apparently there <em>are</em> bad ideas in brainstorming, but anyone who helps Phil on his &#8220;new path&#8221; should <em>try</em> to be supportive.</li>
<li>Phil can spend up to 5% of his work hours building his idea.</li>
<li>Phil can&#8217;t take anyone else from SoftLayer away from their jobs during work hours.</li>
<li>Phil can have space in the Houston office to build his idea.</li>
<li>The project is scheduled to run for 12 weeks. There&#8217;s no guarantee that it&#8217;ll make it through next week.</li>
</ol>
<p>If you have ideas for Phil, feel free to contribute. He&#8217;d probably appreciate the help.</p>
<p>-<a href="http://twitter.com/lavosby">@lavosby</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/an-exercise-in-innovation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
