<?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>Seagull Code Nodes &#187; API</title>
	<atom:link href="http://blog.joshuasiegal.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.joshuasiegal.com</link>
	<description></description>
	<lastBuildDate>Tue, 05 Oct 2010 06:25:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Sufferin Semantics! XML, HTML, jQuery, and MSIE</title>
		<link>https://blog.joshuasiegal.com/2010/sufferin-semantics-xml-html-jquery-msie/</link>
		<comments>https://blog.joshuasiegal.com/2010/sufferin-semantics-xml-html-jquery-msie/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 22:54:32 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[semantic]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.joshuasiegal.com/?p=168</guid>
		<description><![CDATA[So, in a recent project, I&#8217;m consuming xml data and pulling out some text for a description field on an html page.  I&#8217;ve got some basic stuff, text for title information, paths to asset files stored as node attributes, the usual.  But something is bugging me.  I&#8217;ve included some html in my descriptions, all formatted [...]]]></description>
			<content:encoded><![CDATA[<p>So, in a recent project, I&#8217;m consuming xml data and pulling out some text for a description field on an html page.  I&#8217;ve got some basic stuff, text for title information, paths to asset files stored as node attributes, the usual.  But something is bugging me.  I&#8217;ve included some html in my descriptions, all formatted according to xhtml standards, but it won&#8217;t be parsed by jQuery.</p>
<p>Dagnabit!  What is the point of combining xml and html standards if I can&#8217;t use them together all the time?  I know, you may be thinking, but xml is not html , no matter what you throw into your nodes.  You&#8217;re right, and this is exactly what jQuery tells us.  You can grab the text contents of any node, but if you have html tags in there, the <a title="jQuery API - text method" href="http://api.jquery.com/text/" target="_blank">.text()</a> method in jQuery will just look right past them.  As it should.  This works fine, for little snippets like my titles, but what if I want to put some (ostensibly) well-formatted html code in my data?  Further, what about all those applications where you want to store html snips in a database and read them out in XML?  How do you get around this?</p>
<p><span id="more-168"></span></p>
<p>For that, we&#8217;d want to use the <a title="jQuery API - html method" href="http://api.jquery.com/html/" target="_blank">.html()</a> method of jQuery, and for that, my friends, we suddenly get quite strict.  XML, according to jQuery, is not html, and so has no innerHTML quality for the .html() method to grab.  It doesn&#8217;t matter, says jQuery, if your html code is so well formatted that it can be parsed as xml&#8230;it&#8217;s just not possible to access an html-specific property that does not exist.</p>
<p>Like fun, I say!</p>
<p>But before we get to the solution, let&#8217;s heartlessly go over some available options:</p>
<p>1) We could punt on the whole jQuery thing and use Flash, which knows just what to do with a string of html parsed from within an xml node.  Furthermore, Flash has a nifty .htmlText property on its text fields, and although the formatting of said html pales compared to real css, it will faithfully render as html anything you tell it to, caveat codeur.  Since the project in question did involve some Flash, this was an option, but one of the points of the project was to take the same xml data and have both flash and jQuery parse it for different purposes, and thereby provide ease for content providers and improve accessibility.  So doing the whole thing in Flash was out.</p>
<p>2) We could escape the heck out of all our characters and turn the whole node into a mess of html character codes.  Un-fun to code and messy for the content people.  Also, I tried that and it rendered out a block of actual html onto my screen.  I&#8217;m sure I could have reconverted those characters back into actual html behind the scenes, but again, un-fun and a hassle.</p>
<p>3) Use a fancy xml consuming plugin or script.  There are some neat ones out there, and I tried one in particular that looked pretty good, but it seems they have a common issue &#8211; you have to know what tags you&#8217;re looking for in order to seek and replace within the script.  Some of them will hunt for anything that looks like an html tag in the string and convert that, but mostly these plugins seem like scripts that people wrote to perform functions for themselves, and then extracted and shared.  Which I applaud.  But these were not what I was looking for, and I found the implementation sometimes troublesome.</p>
<p>4)<strong> [Warning: bad solution]</strong> Hand jQuery a bag of grapes and say it&#8217;s &#8220;nature&#8217;s jellybeans&#8221; (at least that&#8217;s what my mom used to do to us).  It goes like so: grab your xml file with an <a title="jQuery API - ajax method" href="http://api.jquery.com/jQuery.ajax/" target="_blank">ajax()</a> call, and use the optional key/value pair:</p>
<blockquote><p>dataType: &#8220;html&#8221;</p></blockquote>
<p>And then you&#8217;d do ike so:</p>
<blockquote><p>$.ajax({ url: &#8220;myXMLdoc.xml&#8221;,<br />
dataType: &#8220;html&#8221;,<br />
success: function(xml){<br />
var myHtmlContent = $(&#8216;node&#8217;,xml).eq(id).find(&#8220;nodeName&#8221;).html();<br />
$(&#8220;#targetdiv&#8221;).html(myHtmlContent);<br />
}<br />
});</p></blockquote>
<p>&#8230;and there you have it!  Or, would&#8230;if&#8230;</p>
<p>&#8230;can you see where this is going?</p>
<p>&#8230;search your feelings, Luke&#8230;</p>
<p>&#8230;if only Internet Explorer handled the XMLHTTPRequest result like the rest of the world!  Like most Microsoft stuff, IE, with its <strong>own</strong> version of the XMLHTTPRequest (someone <a title="Microsoft XMLHTTPRequest documentation" href="http://msdn.microsoft.com/en-us/library/ms535874%28VS.85%29.aspx" target="_blank">correct me if I&#8217;m wrong on that</a>), wants to get too clever and won&#8217;t let you, the developer, tell it what kind of data you&#8217;d like to see (even if it&#8217;s either of several types that are verging toward common standard).  No siree!</p>
<p>Supposedly, recent versions of IE (7+) have their own XMLHTTPRequest, not the previous Microsoft HTTPRequest.  However, the Microsoft XMLHTTPRequest doesn&#8217;t behave like the other girls and boys, even in the recent versions of IE.  Now, this post didn&#8217;t start off to be a discussion of the supposed evils of Microsoft&#8217;s proprietary habits.  But who else has almost 11 million results on a <a title="google search: internet explorer sucks" href="http://www.google.com/#hl=en&amp;q=internet+explorer+sucks&amp;aq=f&amp;aqi=&amp;oq=&amp;fp=c26c79a56c95bda8" target="_blank">google search of how much they suck</a>?  Hint: not Chrome (3 M), Firefox (1 M), or Safari (1 M).  (Can&#8217;t evaluate Opera on this critrion because sadly a lot of people out there think that real, actual opera &#8211; the music &#8211; sucks too).  For comparison: &#8220;yanni sucks&#8221; (400 K), &#8220;death metal sucks&#8221; (700 K), &#8220;paris hilton sucks&#8221; (1 M), &#8220;the lions suck&#8221; (1 M), &#8220;tv sucks&#8221; (11 M), and &#8220;new york sucks&#8221; (12 M).  So, yeah.</p>
<p>Anyway, after that turgid digression, <em>finally,</em> we come to the solution.  And&#8230;</p>
<p>It&#8217;s simple!  Maybe I&#8217;m, like, the last one to figure this out, but you just use XML&#8217;s <a title="W3C XML CDATA" href="http://www.w3schools.com/XML/xml_cdata.asp" target="_blank">CDATA</a> declaration, and wrap it around our html code within our xml node.  If I had found that idea earlier, it would have saved me some time, but I would have missed a brain-scratching moment or ten for sure.</p>
<p>Anyway, this is fascinating to me for several reasons:</p>
<p>a) When oh when is Microsoft going to just give up and give us a truly standards-compliant web browser?  Maybe they should spin off a company whose software is intuitive and flexible and plays nice with others.  Oh wait, <a title="apple" href="http://www.apple.com/" target="_blank">they already did that</a>.</p>
<p>b) With the XHTML standard in full force, it seems totally silly that one would have to pass off perfectly valid XHTML within an xml document as CDATA.  Isn&#8217;t the whole point of XHTML to be able to one day have a semantic web, where code itself can be meaningful?  How far away are we when it&#8217;s trouble to get even well-formatted html out of my xml nodes without basically commenting it out?  In theory, that means I can&#8217;t parse through my html elements, which seems to go against the whole ethos of XHMTL.</p>
<p>Well, heck.  I remember when CSS was going to put an end to bad code.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.joshuasiegal.com/2010/sufferin-semantics-xml-html-jquery-msie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The jsFloater API</title>
		<link>https://blog.joshuasiegal.com/2009/the-jsfloater-api/</link>
		<comments>https://blog.joshuasiegal.com/2009/the-jsfloater-api/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 13:43:46 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[jsFloater]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[liquid]]></category>

		<guid isPermaLink="false">http://blog.joshuasiegal.com/?p=29</guid>
		<description><![CDATA[The API for jsFloater consists of 3 publicly available methods: floatHor, floatVer, and &#8211; you guessed it &#8211; floatHorVer.  The first of these will float an object horizontally; the second will float an object vertically, and the third will float an object both horizontally and vertically. Because web browsers are anchored to the top left [...]]]></description>
			<content:encoded><![CDATA[<p>The API for jsFloater consists of 3 publicly available methods: floatHor, floatVer, and &#8211; you guessed it &#8211; floatHorVer.  The first of these will float an object horizontally; the second will float an object vertically, and the third will float an object both horizontally and vertically.</p>
<p>Because web browsers are anchored to the top left of the window, you may want to use a combination of these three methods to achieve your desired results.  jsFloater allows you to define a minimum stage size, so that your elements won&#8217;t crash together if the user squashes the page size down by dragging the browser window&#8217;s bottom right corner to the middle of the screen, for example.  This minimum stage size is passed to the class constructor on instantiation.</p>
<p>There is a visual guide to the API available both in the <a title="download jsFloater" href="http://blog.joshuasiegal.com/2009/download-jsfloater/" target="_blank">downloadable zip file</a> and also for <a title="jsFloater visual API example online" href="http://joshuasiegal.com/jsFloater/" target="_blank">browsing on this site</a>.  You can mouse over the various objects in the visual API guide to reveal what method has been used to float them, which align mode they are employing, and what their current pixel x &#8211; y coordinates are.</p>
<p>jsFloater allows you several types of floating, in addition to the ability to &#8220;pad&#8221; or &#8220;stick&#8221; your floats, as will be expained below.  The types of floating are proportional (based off of the difference between the minimum stage size and current stage size) or Strict, meaning based only on the current stage size.</p>
<p><strong>The methods:</strong></p>
<p><span id="more-29"></span></p>
<p><strong><span style="text-decoration: underline;"><br />
constructor</span></strong></p>
<p>public function jsFloat(sIW:uint, sIH:uint):void</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">returns</span>: nothing</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">parameters</span>:</p>
<p style="padding-left: 60px;"><strong><span style="color: #0000ff;">sIW</span></strong>:uint &#8211; stage Initial Width.  This is also the stage minimum width you define based on your designs.<br />
<strong><span style="color: #0000ff;">sIH</span></strong>:uint &#8211; stage Initial Height.  This is also the stage miniumum height you define based on your designs.</p>
<p style="padding-left: 60px;">Both of these parameters will be used to calculate values in the proportional float modes and will also set the values for browser window resizes that are smaller than your minimum.</p>
<p><strong><span style="text-decoration: underline;"><br />
floatHor</span></strong></p>
<p>public function floatHor(obj:Object, align:String,  yStick:int, xPad:int, sW:Number, sH:Number):void</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">returns</span>: nothing.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">parameters</span>:</p>
<p style="padding-left: 60px;"><strong><span style="color: #0000ff;">obj:</span></strong>Object &#8211; the object passed to the method.  Can be sprite or movieclip as well.<span style="color: #0000ff;"><br />
<strong>align:</strong></span>String &#8211; the alignment mode.  Options are:<span style="color: #008080;"> </span><span style="color: #008080;"><br />
&#8220;left&#8221;</span> &#8211; aligns left, proportionate to minimum stage size<br />
<span style="color: #008080;"> &#8220;leftStrict&#8221;</span> &#8211; aligns left, based strictly on current window size<br />
<span style="color: #008080;">&#8220;right&#8221;</span> &#8211; aligns right, proportionate to minimum stage size<br />
<span style="color: #008080;">&#8220;rightStrict&#8221;</span> &#8211; aligns right, based strictly on current window size<br />
<span style="color: #008080;">&#8220;center&#8221;</span> &#8211; aligns center (horizontally) in the window<br />
<strong><span style="color: #0000ff;">yStick</span><span style="color: #0000ff;">:</span></strong>int &#8211; allows you to force the floated object to &#8220;stick&#8221; to a particular y value.  A horizontal float with a yStick of 0 will align vertically with the top of the browser window.  Negative values can be used, as well as your own math (provided it results in an integer).<br />
<strong><span style="color: #0000ff;">xPad</span><span style="color: #0000ff;">:</span></strong>int &#8211; allows you to pad your float values.  For example, if you are using an image that always needs to be 20 pixels from the right edge of the window, you would use the &#8220;rightStrict&#8221; mode and and xPad of 20.  Positive values for pads will move objects toward the center of the window (horiztontally, in this case), except when using the &#8220;center&#8221; mode, which moves positive values toward the right.  Negative values can be used, as well as your own math (provided it results in an integer).<br />
<strong><span style="color: #0000ff;">sW:</span></strong>Number &#8211; current stage width.<br />
<span style="color: #0000ff;"><strong>sH:</strong></span>Number &#8211; current stage height.</p>
<p><span style="text-decoration: underline;"><strong><br />
floatVer</strong></span></p>
<p>public function floatVer(obj:Object, align:String, xStick:int, yPad:int, sW:Number, sH:Number):void</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">returns</span>: nothing.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">parameters</span>:</p>
<p style="padding-left: 60px;"><strong><span style="color: #0000ff;">obj:</span></strong>Object &#8211; the object passed to the method.  Can be sprite or movieclip as well.<span style="color: #0000ff;"><br />
<strong>align:</strong></span>String &#8211; the alignment mode.  Options are:<span style="color: #008080;"> </span><span style="color: #008080;"><br />
&#8220;top&#8221;</span> &#8211; aligns top, proportionate to minimum stage size<br />
<span style="color: #008080;"> &#8220;topStrict&#8221;</span> &#8211; aligns top, based strictly on current window size<br />
<span style="color: #008080;">&#8220;bottom&#8221;</span> &#8211; aligns bottom, proportionate to minimum stage size<br />
<span style="color: #008080;">&#8220;bottomStrict&#8221;</span> &#8211; aligns bottom, based strictly on current window size<br />
<span style="color: #008080;">&#8220;middle&#8221;</span> &#8211; aligns middle (vertically) in the window<br />
<strong><span style="color: #0000ff;">xStick</span><span style="color: #0000ff;">:</span></strong>int &#8211; allows you to force the floated object to &#8220;stick&#8221; to a particular x value.  A vertical float with a xStick of 0 will align with the left side of the browser window.  Negative values can be used, as well as your own math (provided it results in an integer).<br />
<strong><span style="color: #0000ff;">yPad</span><span style="color: #0000ff;">:</span></strong>int &#8211; allows you to pad your float values.  For example, if you are using an image that always needs to be 20 pixels from the bottom of the window, you would use the &#8220;bottomStrict&#8221; mode and and yPad of 20.  Positive values for pads will move objects toward the middle of the window (vertically, in this case), except when using the &#8220;middle&#8221; mode, which moves positive values to the bottom.  Negative values can be used, as well as your own math (provided it results in an integer).<br />
<strong><span style="color: #0000ff;">sW:</span></strong>Number &#8211; current stage width.<br />
<span style="color: #0000ff;"><strong>sH:</strong></span>Number &#8211; current stage height.</p>
<p><span style="text-decoration: underline;"><strong><br />
floatHorVer</strong></span></p>
<p>public function floatHorVer(obj:Object, stickMode:String, xPad:int, yPad:int, sW:Number, sH:Number):void</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">returns</span>: nothing.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">parameters</span>:</p>
<p style="padding-left: 60px;"><strong><span style="color: #0000ff;">obj:</span></strong>Object &#8211; the object passed to the method.  Can be sprite or movieclip as well.<br />
<span style="color: #0000ff;"><strong>stickMode</strong></span>:String &#8211; analogous to the align parameter in the methods above.  Options are:<br />
<span style="color: #008000;">&#8220;center&#8221;</span> &#8211; aligns to the center (horizontally) and middle (vertically) of the window<br />
<span style="color: #008000;">&#8220;right&#8221;</span> &#8211; aligns vertically to the middle and horizontally to the right, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;rightStrict&#8221;</span> &#8211; aligns vertically to the middle and horizontally to the right, based strictly on current window size<br />
<span style="color: #008000;">&#8220;bottom&#8221;</span> &#8211; aligns horizontally to the center and vertically to the bottom, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;bottomStrict&#8221;</span> &#8211; aligns horizontally to the center and vertically to the bottom, based strictly on current window size<br />
<span style="color: #008000;">&#8220;bottomright&#8221;</span> &#8211; aligns to the bottom right, both proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;bottomrightStrict&#8221;</span> &#8211; aligns to the bottom right, both based strictly on current window size<br />
<span style="color: #008000;">&#8220;bottomleft&#8221;</span> &#8211; aligns to the bottom left, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;left&#8221;</span> &#8211; aligns vertically to the middle and horizontally to the left, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;topleft&#8221;</span> &#8211; aligns to the top left, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;top&#8221;</span> &#8211; aligns horizontally to the center and vertically to the top, proportionate to the minimum stage size<br />
<span style="color: #008000;">&#8220;topright&#8221;</span> &#8211; aligns to the top right, proportionate to the minimum stage size<em><br />
Note: because the browser window is anchored to the top left, certain stickMode parameters for this method would be redundant.  For example, there is no topleftStrict, as that effect can be achieved with the floatHor method, taking an align mode of &#8220;leftStrict&#8221;.</em><strong><span style="color: #0000ff;"><br />
xPad</span><span style="color: #0000ff;">:</span></strong>int &#8211; allows you to pad your float values horizontally.<span style="color: #0000ff;"><strong><br />
yPad</strong></span>:int &#8211; allows you to pad your float values vertically.<br />
xPad and yPad are as described for the methods above.  Either can accept negative values and math that results in an integer, except that both will push objects toward the center (horiztonally) and middle (vertically) of the window when given positive values, unless the &#8220;center&#8221; mode is used, which will push positive values down and to the right.  For example, if you wanted two objects to float at the center of the screen, with one always offset from the other 20 pixels down and to the right, you would float the first using the floatHorVer method with xPad and yPad of 0 and 0, and float the second using the same method, with an xPad of 20 and a yPad of 20.<strong><span style="color: #0000ff;"><br />
sW:</span></strong>Number &#8211; current stage width.<br />
<span style="color: #0000ff;"><strong>sH:</strong></span>Number &#8211; current stage height.</p>
<p>For more, see <a title="How To Use jsFloater" href="http://blog.joshuasiegal.com/2009/how-to-use-jsfloater/">How To Use jsFloater</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.joshuasiegal.com/2009/the-jsfloater-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
