<?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>Daniel Baldwin &#187; jquery plugins</title>
	<atom:link href="http://www.danielcbaldwin.com/tag/jquery-plugins/feed" rel="self" type="application/rss+xml" />
	<link>http://www.danielcbaldwin.com</link>
	<description>Web Developer and Technology Enthusiast</description>
	<lastBuildDate>Thu, 27 May 2010 00:03:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Website as a jQuery Plugin</title>
		<link>http://www.danielcbaldwin.com/technology/websie-as-a-jquery-plugin</link>
		<comments>http://www.danielcbaldwin.com/technology/websie-as-a-jquery-plugin#comments</comments>
		<pubDate>Thu, 02 Jul 2009 05:54:29 +0000</pubDate>
		<dc:creator>dbald</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery plugins]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.stilito.com/?p=120</guid>
		<description><![CDATA[I recently had to build a site that ran mainly off of jQuery and I had the whole thing working from one script.js file that just had a lot of functions in it with some global functions defined at the top. The more I looked at this mess of a file the more I felt [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to build a site that ran mainly off of jQuery and I had the whole thing working from one script.js file that just had a lot of functions in it with some global functions defined at the top. The more I looked at this mess of a file the more I felt disappointed with myself that I had allowed myself to code so horribly.</p>
<p>So I went on a mission to turn the entire site into an object. I tried many different ways, including Javascript&#8217;s built in prototyping, but nothing seemed to turn out as nicely as I would have hoped. So I had the crazy idea of turning the entire site&#8217;s code into a jQuery plugin. Well it has worked out very well and even though it is a it of a wierd thing to do I have taken to making site that use alot of javascript into jQuery plugins.</p>
<p>The problem for me is that what was outlined on the jQuery documentation wasn&#8217;t all that helpful and I found that using existing plugins to figure out how the plugins were being built was alot more helpful but also confusing as there seems to be a nearly unlimited amount of ways to make a plugin. So after searching around for a while and a bunch of trial and error this is what I ended up with:</p>
<pre class="brush: jscript;">/*** Sample jQuery Plugin*/
 (function($) {
    function Sample() {};

    $.extend(Sample.prototype, {
        settings: {
            base_url: ''
        },

        init: function() {
            this.sampleFunction();
        },

        sampleFunction: function() {
            /* Sample Function Code */
        }
    });
    //Plugin End
    /**	*	Event Handlers	*/
    $(document).ready(function() {
        if ($.sample == undefined) {
            $.sample = new Sample();
        }
        $.sample.init();
    });

})(jQuery);</pre>
<p>I find that I like to call the plugin after the site, e.g. jquery.danielbaldwin.js, and I name the function accordingly. I have found that having all the javascript for a site in one object has helped me to build sites that are more complex, can have persistent variables easily, I can set settings that can be changed just by changing a 1 to a 0, and I feel like my code within the object becomes so much cleaner and more legible.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.danielcbaldwin.com%2Ftechnology%2Fwebsie-as-a-jquery-plugin&amp;linkname=Website%20as%20a%20jQuery%20Plugin"><img src="http://www.danielcbaldwin.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.danielcbaldwin.com/technology/websie-as-a-jquery-plugin/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
