What is Toluu?
Toluu is a free service for sharing the feeds you read and discovering new ones.
Get Invite

andrewburke.ca


How to do Google Maps-Style Scrolling Windows with JavaScript and DHTMLSeptember 6 2007
I've spent the last few weeks working for a client who brought me in for my Ruby on Rails experience, but I ended up working almost exclusively in JavaScript. Doing complicated things with JavaScript used to be annoying and painful, but with the newer debugging tools for Firefox and cool things like the Prototype library, it's a lot more fun.

I don't want to give away too much about the project, but I ended up building a diagramming system that let users add and remove elements in a graphical hierarchy and see the relationships between them. All of this was done entirely in the browser - no going back to the server and its friendly relational database and Ruby code - and it turned out quite nicely. The diagram could get quite large, though, so we decided that you should be able to scroll around in it a bit like how Google Maps works.

I looked around the web for quite a while and couldn't find any information on how to do this. So, to help anyone else out there who may want to do a similar thing, I thought I'd share what I figured out. Actually, this isn't exactly how I did it in my recent project, since I used a more object-oriented approach and leaned heavily on the awesome Prototype library; this versi



RJS / AJAX Highlight Colouring in RailsMay 1 2007
I've been at the top of the development S curve on a big project for the last few weeks - getting closer and closer to that asymptotic 'done' line but never quite getting all the way.

This project I've been doing is the first where I've made extensive use of RJS effects and lots of swappable subsections on a page. It has really expanded the interface tools at my disposal. However, the documentation for how to do this properly is rather sparse and one has to pick up a lot of techniques from other people or by trial and error.

One quirk I found today involves the highlight effect. As made famous by 37Signals, it flashes the specified component on the page in yellow and then fades away. I'm highlighting a large part of a page to show that an update has occurred and the huge flash of yellow is a little overwhelming - so I've tried using different colours, but I haven't been able to make anything stick.

After poking around the effects.js file itself and playing with the FireBug console for a bit, I finally figured it out. To specify a colour, you need to use the hexadecimal code inside two sets of quotes. The code that works is like this:page.visual_effect(:highlight, "supplier_#{@next_supplierorder.id}", :startcolor => "'#CCEECC'", :endcolor => "'#A8CFA3'")This may be fixed in more up-to-date versions of Rails - I froze my version several months ago so I wouldn't have to develop to a moving target - but hopefully this will help you





Analgesic Code: BacktrackApril 9 2007
Over the years I've found snippets of code that make my life easier and, like Aspirin (a name still trademarked in Canada so I guess I can't use it), get rid of the headaches.

The Back button in browsers can be a headache for web developers. If you're not careful it can cause things like duplicated information, old pages showing inaccurate information, and other badness. I've found it handy to build a 'back' button directly into my applications - that way users are more tempted to use that rather than the browser's button.

This can be implemented in Java, PHP, or whatever - but I've done it mostly in Ruby on Rails applications, so that's what the examples will show. First, set up a class called PageTrack - I'm lazy and I put it in my 'models' directory, although I guess it should be in 'lib'. This is code I wrote a while ago while I was still getting the hang of Ruby, so it's not as elegant as it could be - but I've learned not to 'fix' small code that already works unless there's a really good reason.
class PageTrack def self.add(session, address) if session && address session[:page_track] = Array.new if !(session[:page_track]) # check top element - if the same as current page don't add previous_address = session[:page_track][-1] if previous_address != address session[:page_track].push(address) end end end def self.prev(session) if session && session[:page_track]




It's the Little Things - ajax_collection_select and Rails 1.1July 2 2006
I've wanted to upgrade my various applications to Rails 1.1 ever since it came out a few months ago. I tried upgrading a while back, but the upgrade broke one of my favorite AJAX helper methods - and since there were deadlines, I went back to 1.0 and decided I'd figure it out later.

Well, it's a long weekend and instead of hanging out on a dock somewhere and drinking beer, I've decided to try upgrading again and see if I could figure out what's going on. Finally figured it out. In the interest of helping anyone out there who may be googling for a similar issue, here are the ugly details.

Everything runs fine in the upgrade except for one really handy helper method I use a lot. It's an extended version of the collection_select helper that automatically triggers an AJAX update when the selection is changed. I noticed that the built-in helpers used watchers, which spreads the functionality around into multiple places, and also causes lots of reloads in Firefox, where scrolling through the menus will trigger a reload. My helper is like this:


def collection_select_ajax(name, property, collection, key, value, update_div, url_params)
url = url_for(url_params)
collection_select(name, property, collection, key, value, '', {:onchange => "new Ajax.Updater('#{update_div}', '#{url}', {asynchronous:true, evalScripts:true, parameters:value})"})
end


Handy. Two lines of code - one if I wanted












iCal: The Lickable CronMay 5 2006
Apple managed to sneak some actual functionality into iCal while we weren't looking.