Archive for the ‘javascript’ Category

Using Jquery to display your GitHub repos

Friday, March 6th, 2009

Here is a quick little script to pull down your GitHub Repos and display them on a page:

Interesting note - I started off by using the append function inside the $.each loop - but after reading Josh Powell’s post on using append correctly I switched to building the HTML from a concatenated string. The result loads noticeably faster.

Check out the result on GitHub:

http://johnboxall.github.com/

onbeforeunload event - are you sure that’s what you want to do?

Tuesday, December 30th, 2008

`onbeforeunload` is a black sheep in the JavaScript event family. It’s nonstandard and yet supported all major browsers except Opera. You’ve seen it before in Gmail or Wordpress. When you try to close a draft that hasn’t been saved you are asked to confirm your action - that’s `onbeforeunload` in action.

Using jQuery we can duplicate this effect. The gist of the idea is to use a boolean called `dirty` to track changes to input elements. If `dirty` is set we’ll use the `onbeforeunload` event to confirm that user’s action:

Check out Stackoverflow for an introduction to the `onbeforeunload` event.