Better timeouts and intervals with Javascript

window.setTimeout and window.setInterval don’t ever seem to have been given any love for a long time. (At least from my limited end-user point of view). I’ve toyed in the past with a better queuing system for them and having the ability to run on clear (especially for intervals), but I’ve actually knocked up a basic script that allows object-oriented timeout events. It still uses the native implementations outside, and I’m sure that this has probably already been done 100 times, but I still wanted to have a go.

This script extends the return from window.setTimeout and window.setInterval to be an object itself that you can stop() and restart(), preserving the function for further use.

Please note: I’ve only really tested this in Chrome! I can’t see why it wouldn’t work in other browsers, I guess maybe some of these would be protected, but I’m not sure… If that’s the case, it wouldn’t be too difficult to utilise the alternative new Timeout(function(){ }, 400); syntax…

There’s a bit more (not much!) of an explanation here and the code is available here. There are no prerequisites for this code, should run on plain old Javascript.

Edit: Minor update to the script to include the object in the callback.

jQuery Parallax: In action

A lot of the traffic I get to this blog is related to the jQuery Parallax script I wrote quite some time ago. Looking at the code now, I don’t think I’d change too much about it, perhaps use .on('mousemouse', ...) instead of .mousemove(), but mostly it seems to serve it’s function quite well. Since the only real functions being called are .mousemove() and .css() it should still be working with the latest versions of jQuery and unless they decide to majorly change the API, it should continue to work too!

Since my example was on a fairly empty page, I thought I’d link to a couple of sites that are using it in the real world:

If you’re using the script and think your sites is a good example of utilising the parallax effect, please leave me a message!

Tool: Fix broken unicode characters

So in the past I’ve had many a nightmare receiving garbled unicode characters in an email or in a poorly encoded database field, so I’ve written a basic tool that works with some of the most common Western European characters and will correctly convert them (optionally to their closest matching standard ASCII character).

I am going to try and work on a full set (that can be incrementally loaded), but this has been sufficient for my needs so far.

Use it here!

Edit: I’ve updated the Tool to allow for various functions, input via literals (\x0d or \u02f4), returning to multibyte in the text area and other fixes. The same link will work.

This link was incredibly helpful with my investigation and testing!

Bookmarklet: Reload CSS files without reloading the page

Working on styling the contents of popup windows can be frustrating and laborious. But not if you can just reload the CSS…

This bookmarklet will reload all the associated stylesheets in the current document. It looks for all <link/> elements with rel="stylesheet", removes from the DOM and re-adds them appending a ?_=1234567890 (or &_ depending on the URL, where the numbers represent the JS timestamp) into the <head/>.

Hopefully this will help someone suffering similar pain to myself!

Reload CSS (Add the link to the left to your bookmarks to use!)

Please note: I haven’t tested this in IE, but surely it’ll work… Right?

Continue reading “Bookmarklet: Reload CSS files without reloading the page”