<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>The House of AnimeJB &#187; Javascript</title>
	<atom:link href="http://www.animejb.net/category/tips-tricks/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.animejb.net</link>
	<description>The House of AnimeJB</description>
	<pubDate>Mon, 20 Oct 2008 19:20:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
		<!-- podcast_generator="podPress/8.8" -->
		<copyright>&#xA9; </copyright>
		<managingEditor>cal@animejb.net ()</managingEditor>
		<webMaster>cal@animejb.net()</webMaster>
		<category></category>
		<ttl>1440</ttl>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary>The House of AnimeJB</itunes:summary>
		<itunes:author></itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name></itunes:name>
			<itunes:email>cal@animejb.net</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://www.animejb.net/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://www.animejb.net/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>The House of AnimeJB</title>
			<link>http://www.animejb.net</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Dynamic Style Sheets</title>
		<link>http://www.animejb.net/2006/06/29/dynamic-style-sheets</link>
		<comments>http://www.animejb.net/2006/06/29/dynamic-style-sheets#comments</comments>
		<pubDate>Thu, 29 Jun 2006 16:29:44 +0000</pubDate>
		<dc:creator>Calophi</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.animejb.net/2006/06/29/dynamic-style-sheets/</guid>
		<description><![CDATA[This isn&#8217;t about rotating through alternate stylesheets or importing them, or even changing an inline style on an element through Javascript.  Oh no.  This is about creating an actually stylesheet element ON THE FLY.
The reason for this is because for a bit I was just trying to create a long string with the [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t about rotating through alternate stylesheets or importing them, or even changing an inline style on an element through Javascript.  Oh no.  This is about creating an actually stylesheet element ON THE FLY.</p>
<p>The reason for this is because for a bit I was just trying to create a long string with the style tags and rules inside it, and then just pop it in the innerHTML of the body.  (Hey, I&#8217;m no Guru, I have a lot to learn!) Needless to say, this caused a few issues.</p>
<p><span id="more-45"></span></p>
<p>At first I tried to use <a href="http://www.howtocreate.co.uk/tutorials/javascript/domstylesheets">DOM Stylesheets</a> to serve my purposes, but I soon found that although they work in Mozilla and IE (though IE works funny and has different functions to use), the <code>document.stylesheets</code> object and it&#8217;s functions are woefully supported in other browsers, Safari in particular.</p>
<p>My next attempt was a tad more successful - I used <code>document.createElement("style")</code>, appended the rules to it as a TextNode, and then appended the style to the <code>&lt;head&gt;</code>.  I then learned that IE does not like to append TextNodes to style elements.</p>
<p>So, after a bit of research I found a way to get IE to insert the text into the style.  It works in the latest-greatest Mozilla, IE, Safari, and Opera.  Not sure about older versions.  Just have it run <code>onLoad()</code> and make an example <code>div</code> to test it out.</p>
<pre>
var myCSS = "div{background-color: blue}";
var myStyle = document.createElement("style");
	myStyle.setAttribute("type", "text/css");

//only IE uses style.styleSheet, the rest use style.sheet
if(myStyle.styleSheet){
	//Many browsers won't let you change the style's cssText, but IE does.
	myStyle.styleSheet.cssText = myCSS;
} else {
	//this is the standard way to do it, which IE does not support.
	myCSS = document.createTextNode(myCSS);
	myStyle.appendChild(myCSS);
}

document.getElementsByTagName("head")[0].appendChild(myStyle);
</pre>
<p>Obviously if you don&#8217;t want things to blow up in more archaic browsers, you&#8217;re going to want to do a detect for <code>document.createElement</code> before running this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.animejb.net/2006/06/29/dynamic-style-sheets/feed</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript XPath Support</title>
		<link>http://www.animejb.net/2006/06/29/javascript-xpath-support</link>
		<comments>http://www.animejb.net/2006/06/29/javascript-xpath-support#comments</comments>
		<pubDate>Thu, 29 Jun 2006 16:02:20 +0000</pubDate>
		<dc:creator>Calophi</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[web]]></category>

		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://www.animejb.net/2006/06/29/javascript-xpath-support/</guid>
		<description><![CDATA[At work some of my tasks have led me to fooling around with new interface ideas.  I figured this is a good way to get up to scratch with AJAX and related ideas.
Now if you&#8217;re pulling in XML with AJAX you know that it can be a perfect pain to parse the file.  [...]]]></description>
			<content:encoded><![CDATA[<p>At work some of my tasks have led me to fooling around with new interface ideas.  I figured this is a good way to get up to scratch with AJAX and related ideas.</p>
<p>Now if you&#8217;re pulling in XML with AJAX you know that it can be a perfect pain to parse the file.  You&#8217;ve got to make sure that the file is converted into a document element (and the methods for doing so are unfortunately not cross-browser), and even afterwards there&#8217;s no cross-browser method to finding the tags you want - at least not one that will give you clean code.  Basically, your choices are:</p>
<ul>
<li><code>getElementsByTagName()</code> - it works, but the function is long, and you&#8217;ll have more loops and nests than you can shake a stick at.  Also, you&#8217;re limited to tags.</li>
<li>Functions such as <code>firstChild</code> and <code>childNodes</code> - which again, leads to long code and lots of nesting.  Plus, using these you don&#8217;t even know what the tags are you&#8217;re messing with, and heaven forbid you change the XML schema a bit, if you didn&#8217;t well-document your javascript it could take you a bit to find the lines you need to alter.</li>
<li>XPath and XSLT transformations - which are sadly not cross-browser and in some cases don&#8217;t even exist in certain browsers.</li>
</ul>
<p><span id="more-44"></span></p>
<p>That third option is what this post is really all about.  After doing some research I have found a few lovely developers who created a wrapper for Internet Explorer to help it behave similarly to Mozilla, thus creating nice cross-browser XML parsers.  Here are the three bigger ones.</p>
<ul>
<li><a href="https://sourceforge.net/projects/sarissa/">Sarissa</a> is my personal favorite of the three.  It&#8217;s a cross browser library that handles making document objects, <code>xmlHTTPRequest</code>, xPath parsing, XML to XSLT transformations, and converting XML into strings.  There is a lot of documentation on it, the forums are fairly active, it&#8217;s an active project, AND besides working for Mozilla and IE, it also partically supports Safari and Opera (which have incomplete native functionality).</li>
<li><a href="http://glazkov.com/blog/archive/2004/04/06/168.aspx">Glazkov&#8217;s XPath Parser</a> is by far the easiest of the three to use.  It lets you use XPath parsing to traverse through the HTML DOM.  I was pretty pleased with it and even managed to make a few wrapper functions for it to make it even easier to use.  Unfortuantely, through, it only works with objects that are in your normal document&#8217;s DOM - that is, it won&#8217;t work on an XML type document.  Bummage.  It&#8217;s also been put in hiatus.  Still, if you&#8217;re only using it to go through your own DOM, it&#8217;s the best one to go with.</li>
<li><a href="http://goog-ajaxslt.sourceforge.net/">Google AJAXSLT</a> - I&#8217;m really only including this because it&#8217;s Google.  It does, from what I can tell, AJAX calls, XPath parsing, and XML to XSLT transformations. The project itself isn&#8217;t terribly well documented and has been stagnant since October 2005.  However people seem to enjoy it and they use something similar to this for <a href="http://www.google.com/apis/homepage/guide.html#XML">Google Homepages</a>, and they&#8217;ve said recently that the project isn&#8217;t abandoned, just not a priority.  So if you can figure out how to use it, it&#8217;s probably pretty neat.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.animejb.net/2006/06/29/javascript-xpath-support/feed</wfw:commentRss>
		</item>
		<item>
		<title>Reg Ex for Script Tags</title>
		<link>http://www.animejb.net/2006/05/12/reg-ex-for-script-tags</link>
		<comments>http://www.animejb.net/2006/05/12/reg-ex-for-script-tags#comments</comments>
		<pubDate>Fri, 12 May 2006 16:09:48 +0000</pubDate>
		<dc:creator>Calophi</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Regular Expressions]]></category>

		<category><![CDATA[regex]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.animejb.net/2006/05/12/reg-ex-for-script-tags/</guid>
		<description><![CDATA[I thought it might be nice to have a little archive of Javascript Regular Expressions for other people coming through.
This one is for pulling &#60;script&#62; tags out of a string.  It should match any case, account for attributes in the opening tag, and match any code including line breaks in between the tags.
First up, [...]]]></description>
			<content:encoded><![CDATA[<p>I thought it might be nice to have a little archive of Javascript Regular Expressions for other people coming through.</p>
<p>This one is for pulling <code>&lt;script&gt;</code> tags out of a string.  It should match any case, account for attributes in the opening tag, and match any code including line breaks in between the tags.</p>
<p>First up, a code to jut match an opening <code>&lt;script&gt;</code> tag, because any open <code>&lt;script&gt;</code> tag can screw up a page, so you might want to take care of just that:</p>
<pre>/<[Ss]*?script(s[Ss]*?)?>/gi</pre>
<p>Next, a tag to grab a <code>&lt;script&gt;</code> tag from beginning to end, so that you can protect all the text, or replace it, or what have you.</p>
<pre>/<[Ss]*?script(s[Ss]*?)?>[Ss]*?<[Ss]*?/script(s[Ss]*?)?>/gi</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.animejb.net/2006/05/12/reg-ex-for-script-tags/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
