<?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>TopSecretProject &#187; How-To</title>
	<atom:link href="http://topsecretproject.finitestatemachine.com/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://topsecretproject.finitestatemachine.com</link>
	<description>Toby Hede on Technology</description>
	<lastBuildDate>Fri, 07 May 2010 08:37:12 +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>How-To: Load Javascript and CSS dynamically with jQuery</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:07:46 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery.wysiwyg]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=111</guid>
		<description><![CDATA[I&#8217;ve been working on a new project for Inspire Digital.
The project is going to allow site members to produce their own content.
Members have a WYSIWYG editor (using jquery.wysiwyg) for creating content with some basic HTML. I wanted to come up with a way for only those who need the files to download the files.
Previously in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new project for <strong>Inspire Digital</strong>.</p>
<p>The project is going to allow site members to produce their own content.</p>
<p>Members have a WYSIWYG editor (using <strong>jquery.wysiwyg</strong>) for creating content with some basic HTML. I wanted to come up with a way for only those who need the files to download the files.</p>
<p>Previously in this sort of situation I have simply included the script and css files within the form, but this is not valid HTML.</p>
<p>So &#8230;<strong> Loading Javascript and CSS dynamically with jQuery</strong> to the rescue!</p>
<p>Loading JavaScript is built-in to jQuery, but you need to create CSS elements yourself. </p>
<p>The approach places a class on the text area we want to be WYSIWYG, then we detect that class, load the CSS and JavaScript and initialise the editor. Easy!</p>
<pre>
<code>
$(document).ready( function() {
  if ($('.wysiwyg_editor')) {
    $("head").append("&lt;link&gt;");
    css = $("head").children(":last");
    css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "/javascripts/jwysiwyg/jquery.wysiwyg.css"
    });
    $.getScript("/javascripts/jwysiwyg/jquery.wysiwyg.js", function(){
         //wait before initialising to prevent intermittent load error
	 setTimeout("init_wysiwyg_editor()",250);
    });
  }
});
function init_wysiwyg_editor() {
  $(".wysiwyg_editor").wysiwyg();
}
</code>
</pre>
<p>The only gotcha I found was that calling <em>$(&#8220;.wysiwyg_editor&#8221;).wysiwyg();</em> would occasionally error with an undefined method unless I put a momentary timeout in before calling. I think this was the result of the browser making the call while still interpreting the freshly loaded script.</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
