Displaying articles with tag

Localized dates in rails using JQuery

Posted by joakimk, Mon Oct 20 10:08:00 UTC 2008

A little snipplet for localizing dates clientside with some unobtrusive javascript. Please note that this does result in different outputs in different browsers. I’ve used a regexp to remove the time difference (ex. GMT+2000) to give it a cleaner look.

On the server side simply print the date:
   <div class="date"><%= @user.created_at %></div>
Then in your javascript (for example application.js), do something like this:
    jQuery.each($(".date"), function() {        
      var new_date = new Date(Date.parse($(this).text())).toLocaleString();
      new_date = new_date.replace(/((GMT|UTC)[+-]((\d{4})|(\d{2}:\d{2})))|(\(.+\))/gi, '');
      $(this).text(new_date);
    });

I have verified that this works in Firefox, Opera, Safari, Chrome and IE7.

0 comments | Filed Under: | Tags:

Memo - Shoppinglist application

Posted by joakimk, Thu Jun 26 19:06:00 UTC 2008

I’ve written a small shoppinglist application for my Pocket PC. It’s called memo and you can find it at github.

The idea came from shopList, an iPhone application. I really liked the idea, but I don’t own an iPhone (yet).

The application is written in pure xhtml/javascript so it should work on almost anything. I had to keep within the limits of Windows Mobile 5.0 (IE Mobile) javascript support… which did not include a smooth way to remove just one element. Because of this the application is a bit jumpy, but it works.

I could naturally not use much Ruby for this application, but I did sneak it in as a deploy script =)

0 comments | Filed Under: | Tags: