<?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>Purple Ivy Website Design and Consulting &#187; Development Tips</title>
	<atom:link href="http://www.purpleivy.net/topics/development-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.purpleivy.net</link>
	<description>Elegant, Organic, and Original Design</description>
	<lastBuildDate>Fri, 05 Mar 2010 14:33:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Including JQuery Multiple Times</title>
		<link>http://www.purpleivy.net/2010/03/05/including-jquery-multiple-times/</link>
		<comments>http://www.purpleivy.net/2010/03/05/including-jquery-multiple-times/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:33:41 +0000</pubDate>
		<dc:creator>Sha</dc:creator>
				<category><![CDATA[Development Tips]]></category>

		<guid isPermaLink="false">http://www.purpleivy.net/?p=101</guid>
		<description><![CDATA[At work I ran across a strange problem that often comes up in content management systems.  The scenario works like this:
The content management system uses JQuery in its latest version but not in earlier versions
A skin designer uses JQuery in the design of a skin
A plugin developer uses JQuery in the implementation of a plugin
Someone [...]]]></description>
			<content:encoded><![CDATA[<p>At work I ran across a strange problem that often comes up in content management systems.  The scenario works like this:</p>
<p>The content management system uses JQuery in its latest version but not in earlier versions</p>
<p>A skin designer uses JQuery in the design of a skin</p>
<p>A plugin developer uses JQuery in the implementation of a plugin</p>
<p>Someone who writes custom content for a page wants to use JQuery for a page</p>
<p>All these different people want to use JQuery &#8211; but the JQuery framework does not function properly if it is included more than once on a web page.  There&#8217;s also no conditional include in HTML (or any include functionality at all, which I&#8217;ve always thought to be a glaring omission).</p>
<p>I wrote a wrapper that you can include instead of JQuery that doesn&#8217;t include JQuery if it&#8217;s already there. It&#8217;s based up on a <a title="JQuery Include Wrapper" href="http://stackoverflow.com/questions/274899/clean-way-of-having-jquery-includes-with-asp-net-mvc/274906#274906" target="_blank">post by FlySwat </a>but the problem with FlySwat&#8217;s is that you have to put some extra code in front of your JQuery code every time. To use my version of the wrapper, all you have to do is use a different function other than $(document).ready to start your scripts at page ready time.</p>
<p>Here&#8217;s my &#8220;jquery.js&#8221; which you can put on a page as often as you like:</p>
<blockquote>
<pre>
if (typeof(loadJSInclude) == 'undefined') {
 function loadJSInclude(scriptPath, callback)
 {
   var scriptNode = document.createElement('SCRIPT');
   scriptNode.type = 'text/javascript';
   scriptNode.src = scriptPath;

   var headNode = document.getElementsByTagName('HEAD');
   if (headNode[0] != null)
      headNode[0].appendChild(scriptNode);

   if (callback != null)    
   {
     scriptNode.onreadystagechange = callback;            
     scriptNode.onload = callback;
   }
 }

 function loadJQuery(task) {
   if (typeof(jquery) == "undefined")
   loadJSInclude('/js/jquery-1.4.1.min.js', function() {
     $(document).ready(task)
   });
   else
     $(document).ready(task());
 }
}    
</pre>
</blockquote>
<p>And then, to start your JQuery operations, use loadJQuery()  instead of $(document).ready()</p>
<blockquote>
<pre>loadJQuery(function () {
  .. your jquery stuff here ..
  $('#boomboom').click( function() {
  alert("BOOM!");
  });
);
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.purpleivy.net/2010/03/05/including-jquery-multiple-times/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
