JS Error Logs

Posted on Jan 23, 2013 in JavaScript, Open Source Projects | 0 comments

Many javascript errors on production sites go unnoticed: they’re only ever visible to the visitor and never tracked – what a wasted opportunity!

This script catches any client-side errors that occur in any modern browser and pass the information – line number, URL, stack trace – to the server for logging. It can provide significant insight into problems occurring on your web sites and applications that otherwise would go missed.


Read More

Canvas spinner script fork

Posted on Dec 28, 2012 in Code, HTML5, JavaScript, Open Source Projects | 0 comments

I came across this marvellous little script yesterday by Nick Stakenburg which creates a loading icon spinner using Canvas, letting you avoid having to use animated gifs. Very nice!

It was almost perfect for my needs, except I needed a few small tweaks. So here’s my fork of the script, with fadeOutSpeed, pauseColor and pauseOpacity options.

You can download it from github here:

Read More

Avoiding DOM-insertion timing problems with JS

Posted on Dec 8, 2012 in Code, generatedata.com, JavaScript | 0 comments

This afternoon I revisited some old code I wrote to address the problem where sometimes you want to do the following:


Even though that’s perfectly acceptable within JS, it takes time for the browser rendering engine to do the job of actually inserting the DOM, so it may not be ready for the second line to actually find the content it just inserted. I outlined the whole problem in an old post here.

Anyway, I updated the code in that post and rewrote it into a requireJS module. You can find it here:
https://gist.github.com/4242808. It’ll be included in the upcoming Data Generator rewrite.

Read More

PHP Smarty Template mode for CodeMirror 2

Posted on Mar 12, 2012 in Code, Form Tools, JavaScript, Open Source Projects | 2 comments

A Smarty syntax highlighter for CodeMirror has long been needed for my Form Tools script, so this weekend I finally took a few hours to put one together. It’s not been reviewed by the CodeMirror developer yet (Marijn Haverbeke), but will hopefully find its way into the main script at some point. I also plan on developing a HTML-JS-CSS-Smarty mixed mode, which will be useful in many places.

Example: http://www.benjaminkeen.com/misc/CodeMirror2/mode/smarty/

[UPDATE: Marijn accepted my changes and it’s now part of the CodeMirror repository].

[UPDATE 2: I added in Smarty 3 support in May, 2013].

Read More

Namespacing in Javascript

Posted on Dec 11, 2010 in JavaScript | 0 comments

A very nice summary of some techniques to namespace your javascript:

Personally I’ve always used what he calls direct assignment. But his objection that the namespace label is hardcoded is quite legitimate. Doing a search and replace on the file isn’t the problem – it’s catching all the calls to the namespaced functions that are scattered around the code. That’s bit me a number of times (today, as a matter of fact!). But what I like most is that it’s extremely simple: even a noob can understand it.

That said, his favourite – #5 Using this as a namespace proxy – is excellent. Very inventive indeed.

Check out his post for the details.

Read More