<?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>Martin Ström &#187; prototype</title>
	<atom:link href="http://my-domain.se/tag/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://my-domain.se</link>
	<description></description>
	<lastBuildDate>Wed, 11 Jan 2012 11:04:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Quicker way to observe events in prototype.js</title>
		<link>http://my-domain.se/quicker-way-to-observe-events-in-prototype-js/</link>
		<comments>http://my-domain.se/quicker-way-to-observe-events-in-prototype-js/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 11:33:41 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2009/12/07/quicker-way-to-observe-events-in-prototype-js/</guid>
		<description><![CDATA[Here&#8217;s a shorter way to listen for events in prototype.js.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a shorter way to listen for events in prototype.js.</p>

<script src="http://gist.github.com/250775.js?file=prototype-events.js"></script>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Copy Paste Character</title>
		<link>http://my-domain.se/copy-paste-character/</link>
		<comments>http://my-domain.se/copy-paste-character/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 18:11:31 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[konst-teknik]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/?p=130</guid>
		<description><![CDATA[Two weeks ago we (me and Konst &#38; Teknik) launched copypastecharacter.com—a site to make it dead easy to copy those special characters which otherwise can be hard to find. We just pushed an update and I realized I hadn&#8217;t mentioned it here. The character you click will automatically get copied into your clipboard, thanks to [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago we (me and <a href="http://www.konst-teknik.se">Konst &amp; Teknik</a>) launched <a href="http://copypastecharacter.com">copypastecharacter.com</a>—a site to make it dead easy to copy those special characters which otherwise can be hard to find. We just pushed an update and I realized I hadn&#8217;t mentioned it here.</p>

<p>The character you click will automatically get copied into your clipboard, thanks to the <a href="http://www.jeffothy.com/weblog/clipboard-copy">flash technique mentioned here</a>. However, I wrote my own JavaScript class to handle the clipboard and the buffer of clicked characters since you can hold down ‹alt› to copy multiple characters at once.</p>

<p><a href="http://www.copypastecharacter.com/javascripts/copy_buffer.js">Here&#8217;s the source for the copy buffer class</a> in case anyone&#8217;s interested.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Multi-dimensional array sorter</title>
		<link>http://my-domain.se/multi-dimensional-array-sorter/</link>
		<comments>http://my-domain.se/multi-dimensional-array-sorter/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 09:41:54 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[konst-teknik]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2007/11/24/multi-dimensional-array-sorter/</guid>
		<description><![CDATA[The other day when working on some small updates on konst-teknik.se I wanted to sort the projects in a multi dimensional way, and take the other factors than the first into account. JavaScript&#8217;s Array#sort only supports one dimensional sorting so I wrapped my own sorter. The results turned up pretty good (at least compared to [...]]]></description>
			<content:encoded><![CDATA[<p>The other day when working on some small updates on <a href="http://konst-teknik.se">konst-teknik.se</a> I wanted to sort the projects in a multi dimensional way, and take the other factors than the first into account. JavaScript&#8217;s <code>Array#sort</code> only supports one dimensional sorting so I wrapped my own sorter.</p>

<p>The results turned up pretty good (at least compared to the first test), or perhaps I just like recursing functions.</p>

<pre><code>

var sortOrder = {
  'cat-no': ['cat-no', 'name', 'type', 'year'],
  'name':   ['name',   'type', 'year', 'cat_no'],
  'year':   ['year',   'name', 'type', 'cat_no'],
  'type':   ['type',   'name', 'year', 'cat_no']
};

function sort(order) {
  var ordering = sortOrder[order], length = ordering.length;
  $$('#projects > li').sort(function(left, right) {
    left = Project.find(left), right = Project.find(right);
    return (function(index) {
      var a = left.getSortValue(ordering[index]),
          b = right.getSortValue(ordering[index]);
      return a < b ? -1 : a > b ? 1 :
        index < length ? arguments.callee(++index) : 0;
    })(0);
  }).each(function(project) {
    project.parentNode.appendChild(project);
  });
}

</code></pre>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax.CachedRequest</title>
		<link>http://my-domain.se/ajaxcachedrequest/</link>
		<comments>http://my-domain.se/ajaxcachedrequest/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 17:40:48 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2007/11/11/ajaxcachedrequest/</guid>
		<description><![CDATA[Recently I wanted to cache the results (responseText) from a lot of Ajax.Requests since the returning data would not change and made the roundtrip to the server unnecessary. Maybe there are others out there interested so here&#8217;s the code. It&#8217;s not very well tested except the project where it is in use so there might [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I wanted to cache the results (responseText) from a lot of <code>Ajax.Request</code>s since the returning data would not change and made the roundtrip to the server unnecessary. Maybe there are others out there interested so here&#8217;s the code. It&#8217;s not very well tested except <a href="http://rbg6.se">the project where it is in use</a> so there might be some bugs or tweaks needed.</p>

<pre><code>
Ajax.CachedRequest = Class.create(Ajax.Request, {
  initialize: function($super, url, options) {
    options = options || {};
    var onSuccess = options.onSuccess || Prototype.K;
    if (!Ajax.CachedRequest.cache[url] || options.reload) {
      options.onSuccess = function(transport) {
        Ajax.CachedRequest.cache[url] = transport.responseText;
        onSuccess(transport);
      }
      $super(url, options);
    } else {
      eval(Ajax.CachedRequest.cache[url]);
      this.dispatch.defer();
      [onSuccess, options.onComplete].each(function(m) { m &#038;&#038; m() });
    }
  },

  dispatch: function() {
    Ajax.Responders.dispatch('onComplete', null);
  }
});

Ajax.CachedRequest.cache = {};
</code></pre>

<p>Of course this assumes you&#8217;re using the brand new <a href="http://prototypejs.org">Prototype 1.6 </a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Prototype &amp; Script.aculo.us SVN checkins RSS feed</title>
		<link>http://my-domain.se/prototype-scriptaculous-svn-checkins-rss-feed/</link>
		<comments>http://my-domain.se/prototype-scriptaculous-svn-checkins-rss-feed/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 20:39:29 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2007/07/25/prototype-scriptaculous-svn-checkins-rss-feed/</guid>
		<description><![CDATA[Thanks to Yahoo Pipes I created two RSS feeds for the Ruby on Rails checkins (changesets). One containing only the Rails-spinoffs checkins (that is Prototype and Script.aculo.us right now) and another without the spinoffs. This way I can follow the JavaScript-related changes as they happen but watch the Ruby-stuff every now and then. Only Spinoffs [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://pipes.yahoo.com">Yahoo Pipes</a> I created two RSS feeds for the Ruby on Rails checkins (changesets). One containing only the Rails-spinoffs checkins (that is Prototype and Script.aculo.us right now) and another without the spinoffs. This way I can follow the JavaScript-related changes as they happen but watch the Ruby-stuff every now and then.</p>

<ul>
<li><p><a href="http://pipes.yahoo.com/pipes/pipe.info?_id=wIRE5es63BGEPMGyl7okhQ">Only Spinoffs checkins</a></p></li>
<li><p><a href="http://pipes.yahoo.com/pipes/pipe.info?_id=aCK7Ne463BG9h_H9jknRlg">Without Spinoffs checkins</a></p></li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#039;s new in Prototype svn?</title>
		<link>http://my-domain.se/whats-new-in-prototype-svn/</link>
		<comments>http://my-domain.se/whats-new-in-prototype-svn/#comments</comments>
		<pubDate>Tue, 01 May 2007 09:59:04 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2007/05/01/whats-new-in-prototype-svn/</guid>
		<description><![CDATA[Just after posting this I saw that sam tagged the 1.5.1 release in svn so I guess this means that 1.5.1 is final. Great work! There has been a lot of action the past days in the Prototype SVN; the release of 1.5.1 RC4, the new DOM and Position branches and a lot of other [...]]]></description>
			<content:encoded><![CDATA[<p><em>Just after posting this I saw that sam <a href="http://dev.rubyonrails.org/changeset/6643">tagged the 1.5.1 release</a> in svn so I guess this means that 1.5.1 is final. Great work!</em></p>

<p>There has been a lot of action the past days in the <a href="http://svn.rubyonrails.org/rails/spinoffs/prototype">Prototype SVN</a>; the <a href="http://prototypejs.org/2007/4/28/release-candidate-4">release of 1.5.1 RC4</a>, the new DOM and Position branches and a lot of other work. Since I watch most of the tickets and changesets I thought I write something about what&#8217;s (might be) in the future for Prototype.</p>

<h3>DOM branch</h3>

<p>I was happy to see a patch I&#8217;ve been working on (<a href="http://dev.rubyonrails.org/ticket/7476">#7476</a>) to get <a href="http://dev.rubyonrails.org/changeset/6638">included</a> some days ago.
It will define a new <code>Element#writeAttribute</code> method which will work together as the already existing <code>#readAttribute</code> to work around many issues browsers having with the native <code>set/getAttribute</code> methods (as always mostly in IE) but also to make chaining work:</p>

<pre><code>$('my_image').writeAttribute('src', 'new-image.png').show();
</code></pre>

<p>The method will also accept a hash for the attributes to let you set multiple attributes at once:</p>

<pre><code>$('my_image').writeAttribute({src: 'new-image.png', custom_attr: 'foo'}).show();
</code></pre>

<p>The patch will also make the <code>Element</code> object into a constructor for very easy and fast element creation (i.e. <code>document.createElement</code> wrapper):</p>

<pre><code>var header = new Element('h1');
</code></pre>

<p>The constructor will also accept an optional attributes hash for the attributes (as seen above in the <code>#writeAttribute</code> method):</p>

<pre><code>var header = new Element('h1', {id: 'myHeader'});
</code></pre>

<p>Of course chaining will work so for a simple image switcher with preloading you could do this:</p>

<pre><code>&lt;!-- html --&gt;
&lt;img src="thumbnail.jpg" id="thumbnail" hires="big.jpg"&gt;

// javascript
$('thumbnail').observe('click', function(event) {
    var thumb = Event.element(event),
      preloader = new Element('img', {src: thumb.readAttribute('hires')});
    preloader.observe('load', function(event) {
        thumb.writeAttribute('src', preloader.readAttribute('src'));
    });
});
</code></pre>

<h3>Event Branch</h3>

<p>I haven&#8217;t followed the event branch very closely but from the code and messages on the <a href="http://groups.google.com/group/prototype-core">ML</a> I&#8217;ve seen there should be new functionality for better garbage collection (to prevent memory leaks) and for e.g. easier removal of observers from elements.</p>

<p>Where you before had to manually collect all an element&#8217;s event listeners to be able to remove them later:</p>

<pre><code>var listener1 = function(event) {...}.bindAsEventListener();
var listener2 = function(event) {...}.bindAsEventListener();

// start listening
$('myElement').observe('click', listener1);
$('myElement').observe('click', listener2);

// stop listening
$('myElement').stopObserving('click', listener1);
$('myElement').stopObserving('click', listener2);
</code></pre>

<p>you will now be able to remove all event listener for a specfic event:</p>

<pre><code>$('myElement').stopObserving('click'); // or Event.stopObserving('myElement', 'click');
</code></pre>

<h3>Other</h3>

<p>Some other new additions worth mentioning are:</p>

<ul>
<li><a href="http://dev.rubyonrails.org/changeset/6639"><code>Element#wrap</code></a></li>
<li><a href="http://dev.rubyonrails.org/changeset/6636"><code>Element#insert</code></a></li>
<li><a href="http://dev.rubyonrails.org/changeset/6626"><code>Function#defer, Function#delay, Function#curry, Function#wrap</code></a></li>
</ul>

<p>But to not make this post too long you&#8217;ll have to read about it on your own (check the source and/or the changesets manually).</p>

<p>Please notice that all these are subject to change since it&#8217;s under development right now and might never get into any future release of Prototype.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>One animated background image for multiple elements in Safari</title>
		<link>http://my-domain.se/animated_background_image_safari/</link>
		<comments>http://my-domain.se/animated_background_image_safari/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 17:32:14 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2007/02/27/animated_background_image_safari/</guid>
		<description><![CDATA[I&#8217;ve found out that Safari can&#8217;t handle the same animated gif as background for multiple elements, it will just animate one of them at the same time. On a project I&#8217;m currently working on my I use the following trick to make all requests to the background image (in this case indicator_black.gif) unique. [...] var [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found out that Safari can&#8217;t handle the same animated gif as background for multiple elements, it will just animate one of them at the same time. On a project I&#8217;m currently working on my I use the following trick to make all requests to the background image (in this case <code>indicator_black.gif</code>) unique.</p>

<pre><code>[...]
var text = transport.responseText;
if (Browser.WebKit) {
    text = text.gsub('indicator_black.gif', function(match) {
        return match + '?' + new Date().valueOf() +
          Math.round(Math.random() * 5000);
    });
}
[...]
</code></pre>

<p>Note that it uses <a href="http://prototypejs.org">Prototype JavaScript framework</a> and you should too.</p>

<div class="updated">
  <h3>Update:</h3>
  This is fixed in WebKit nightly (and therefore Safari 3 but I haven&#8217;t tested yet).
</div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails&#039; time extensions ported to JavaScript</title>
		<link>http://my-domain.se/rails-time-extensions-ported-to-javascript/</link>
		<comments>http://my-domain.se/rails-time-extensions-ported-to-javascript/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 17:59:29 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2006/09/15/rails-time-extensions-ported-to-javascript/</guid>
		<description><![CDATA[I&#8217;ve ported Rails&#8217; Numeric Time extensions to JavaScript since I needed to do some date calculations for a project I&#8217;m working on. Now one should be able to calculate dates in JS like this: (5).seconds() // =&#62; 5000 (2).weeks() + (2).hours() + (15).seconds() // =&#62; 1216815000 (1).week().fromNow().toDate() // =&#62; Fri Sep 22 2006 19:16:32 GMT+0200 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve ported <a href="http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Time.html">Rails&#8217; Numeric Time extensions</a> to JavaScript since I needed to do some date calculations for a project I&#8217;m working on. Now one should be able to calculate dates in JS like this:</p>

<pre><code>(5).seconds() // =&gt; 5000
(2).weeks() + (2).hours() + (15).seconds() // =&gt; 1216815000
(1).week().fromNow().toDate() // =&gt; Fri Sep 22 2006 19:16:32 GMT+0200 (CEST)
var date = new Date(2000, 11, 18, 18, 15, 23);
(2).years().since(date).toDate() // =&gt; Thu Dec 19 2002 06:15:23 GMT+0100 (CET)
</code></pre>

<p>Thought it could be useful for others as well.
You&#8217;ll need the latest <a href="http://prototype.conio.net/">prototype</a> library, unit tests are included.</p>

<p>Download a <a href="http://burnfield.com/martin/wordpress/wp-content/uploads/js_numeric_time_ext.zip">zip with both .js file and unit tests</a> or <a href="http://burnfield.com/martin/wordpress/wp-content/uploads/js_numeric_time_ext.js">just the .js-file</a>.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>TextMate Prototype &amp; Scriptaculous Bundle</title>
		<link>http://my-domain.se/textmate-prototype-scriptaculus-bundle/</link>
		<comments>http://my-domain.se/textmate-prototype-scriptaculus-bundle/#comments</comments>
		<pubDate>Fri, 14 Jul 2006 19:40:14 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[script.aculo.us]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2006/07/14/textmate-prototype-scriptaculus-bundle/</guid>
		<description><![CDATA[This the first version of a TextMate bundle for Prototype and script.aculo.us JavaScript libraries. The language grammar is based on from Justin Palmers Prototype Bundle but the other commands/snippets are all new. Please let me know if you have any comments and/or improvements. Download here Update 2006-07-16 The bundle is now added to TextMates official [...]]]></description>
			<content:encoded><![CDATA[<p>This the first version of a <a href="http://macromates.com">TextMate</a> bundle for <a href="http://prototype.conio.net">Prototype</a> and <a href="http://script.aculo.us">script.aculo.us</a> JavaScript libraries. The language grammar is based on from <a href="http://encytemedia.com/blog/articles/2006/01/03/textmate-vibrant-ink-theme-and-prototype-bundle">Justin Palmers Prototype Bundle</a> but the other commands/snippets are all new.
Please let me know if you have any comments and/or improvements.</p>

<p><a href="/wordpress/wp-content/uploads/Prototype &#038; Scriptaculous.tmbundle.zip">Download here</a></p>

<div class="updated">
    <h3>Update 2006-07-16</h3>
    The bundle is now added to TextMates <a href="http://macromates.com/svn/Bundles/trunk/Bundles/JavaScript%20Prototype%20&#038;%20Script_aculo_us.tmbundle">official svn repository</a>.
</div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

