<?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>marcgray.co.uk &#187; Javascript</title>
	<atom:link href="http://marcgray.co.uk/category/web/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://marcgray.co.uk</link>
	<description>Technical musings of a self-confessed geek.</description>
	<lastBuildDate>Thu, 05 Apr 2012 19:36:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP, JS and CSS Compression</title>
		<link>http://marcgray.co.uk/2009/07/php-js-and-css-compression/</link>
		<comments>http://marcgray.co.uk/2009/07/php-js-and-css-compression/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 23:46:54 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://marcgray.co.uk/?p=20</guid>
		<description><![CDATA[I wasn&#8217;t feeling very well today, so I thought I&#8217;d do something more light-hearted and fun. Yes, that&#8217;s right! I wrote a website compression utility! Basically, you do &#8220;php sitecompress.php mywebsitefolder&#8221; and it goes through all the .php, .html, .htm, .js and .css files. Javascript and CSS (inline and external &#8211; yes I said inline. [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fphp-js-and-css-compression%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fphp-js-and-css-compression%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop --><p>I wasn&#8217;t feeling very well today, so I thought I&#8217;d do something more light-hearted and fun.</p>
<p>Yes, that&#8217;s right! I wrote a website compression utility!</p>
<p>Basically, you do &#8220;php sitecompress.php mywebsitefolder&#8221; and it goes through all the .php, .html, .htm, .js and .css files. Javascript and CSS (inline and external &#8211; yes I said inline. It pulls out the scripts and styles embedded in your HTML and compresses those too) go through YUICompressor (courtesy of Yahoo UI library), PHP and HTML go through an internal algorithm to kill the whitespace. No, I didn&#8217;t use &#8220;php -w filename&#8221;, that would (a) be cheating, and (b) not be very good. Seems PHP&#8217;s own whitespace removal is a bit lackluster and keeps a lot of unnecessary whitespace.</p>
<p>I&#8217;ve run it on a download of microsoft.com and it displays identically. I&#8217;ve run it on the source code of PHPBB3 (after realising I have to add a &#8220;keep html comments&#8221; option, due to their templating system) and that seems fine (strips 4mb off the 37mb install).</p>
<p>I&#8217;ll do a bit more testing in the next couple of days and GPL it on Lamped.co.uk.</p>
<p>p.s. Apologies for the poor readability, It&#8217;s 00:45 and I&#8217;m very tired&#8230;</p>
<div class="shr-publisher-20"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fphp-js-and-css-compression%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fphp-js-and-css-compression%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://marcgray.co.uk/2009/07/php-js-and-css-compression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Object setTimeout</title>
		<link>http://marcgray.co.uk/2009/07/javascript-object-settimeout/</link>
		<comments>http://marcgray.co.uk/2009/07/javascript-object-settimeout/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 09:19:41 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://marcgray.co.uk/?p=6</guid>
		<description><![CDATA[So I&#8217;ve been developing a chat room entirely in Javascript and PHP using a lot of ajax. Aside from an eCard I made for friends and family last christmas, I&#8217;ve not written more than a few lines of javascript before. I find starting a large project is a good way to learn a language, so [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fjavascript-object-settimeout%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fjavascript-object-settimeout%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop --><p>So I&#8217;ve been developing a chat room entirely in Javascript and PHP using a lot of ajax. Aside from an eCard I made for friends and family last christmas, I&#8217;ve not written more than a few lines of javascript before. I find starting a large project is a good way to learn a language, so off I went&#8230;</p>
<p>I wanted to do this properly, so I read up on Javascript OOP development and improved my general knowledge of the excellent jQuery library. I developed the client side script over a week or so and while doing so, found a number of issues with how setTimeout and setInterval work with objects.</p>
<p>Example:</p>
<pre>function someObject() {</pre>
<pre>    this.myVar = 'Test';</pre>
<pre>    setTimeout(this.myTimeoutCall, 1000);</pre>
<pre>}</pre>
<pre>someObject.prototype.myTimeoutCall = function() {</pre>
<pre>    alert(this.myVar);</pre>
<pre>}</pre>
<p>This alerts out &#8216;Test&#8217; right? Wrong. It alerts Undefined&#8230; Why? Apparently setTimeout and setInterval lose the object scope when they call the timer function. I spent hours in Aptana last night butchering around some Javascript until I came up with 2 functions that ensure your timer code is called in the correct scope, and since there&#8217;s little appropriate documentation for it out there, I thought I&#8217;d share:</p>
<pre>function SetTimeoutObj(o, t, f, a) {

<span>	</span>return setTimeout(function() {

<span>		</span>f.apply(o,a);

<span>	</span>}, t);

}

function SetIntervalObj(o, t, f, a) {

<span>	</span>return setInterval(function() {

<span>		</span>f.apply(o,a);

<span>	</span>}, t);

}</pre>
<p>Change your code to use setTimeout(this, time, this.function, [param1, param2, etc]) and hopefully your problems are solved (note: the function parameter list is similar to the original setTimeout, but I moved the duration parameter left one for clarity.)</p>
<div class="shr-publisher-6"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fjavascript-object-settimeout%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fmarcgray.co.uk%2F2009%2F07%2Fjavascript-object-settimeout%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://marcgray.co.uk/2009/07/javascript-object-settimeout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

