paul bennett

Archive for the ‘JavaScript’ Category

Internet Explorer: “unknown runtime error”

Posted by: Paul on: November 28, 2008

There’s already a lot of discussion around this rather unhelpful error message given by Internet Explore under certain circumstances.
I’ll add my voice ot the mix by adding this little gem:
Internet Explorer will also throw this error if you’re trying to alter the innerHTML of an element which doesn’t exist.
Hopefully this helps someone else out

As a follow up to the previous release, I’ve put together another plugin for the Expression Engine content management system.
This one adds the full YUI rich text editor to the ‘body’ area of the Expression Engine publish / edit interface.
The YUI simpleEditor is nice and everything, but sometimes it’s a bit too … simple.
Get the [...]

eeyui – a YUI rich text editor for Expression Engine

Posted by: Paul on: August 27, 2008

Being frustrated with the tinymce plugin for Expression Engine, I decided to create a rich text editor plugin for Expression Engine using the YUI library simple editor.
Due to a magic combination of:

the awesomeness of the YUI library
the thoroughness of the YUI documentation
the simplicity of creating extensions for Expression Engine

it was surprisingly straightforward.
If you’re using Expression [...]

CSS2 and CSS3 selectors in jQuery

Posted by: Paul on: April 29, 2008

Along with dom traversal (ala CSS2), you can also use CSS2 and CSS3 selectors in jQuery. For example:
lb = $(‘a[rel="lightbox"]‘);
will get you all the anchor elements in the dom which have the rel=”lightbox” attribute. This, however:
lb = $(‘a[rel*="light"]‘);
will get you all the anchor elements in the dom which have the substring “light” in their rel [...]

Tags: ,

jQuery convert

Posted by: Paul on: March 7, 2008

I’ve been using components of the YUI framework for a while now and have been really impressed with the depth and breadth of what it enables you to do. I was pretty convinced I’d stick with YUI for a good while….until today.
Now, I’d heard about jQuery a lot but had never taklen a decent look [...]

test early, test often

Posted by: Paul on: May 10, 2007

wrong: write 100 lines of code, test, spend an hour undoing your typo’s and logic bugs
right: write 5-10 lines of code, test, make easy fixes, repeat as often as needed until component is complete.

Javascript: checking if a function exists

Posted by: Paul on: March 20, 2007

It’s typeof to the rescue (again)!
To check if a function exists before you try and call it (and get a nasty javasscript error), use typeof to check.
Heres something I prepared earlier:
if(typeof window.myFunction == ‘function’) {
// function exists, so we can now call it
myFunction(‘foo’, ‘bar’);
}
——————
Want to improve your JavaScript skills? I recommend the following:

Ajax in [...]

In my previous post, I detailed how typeof could be used to test if something is present or not. Given that this sounds loosely defined at best, consider the following:

window.onload = function() {
var myObject = new Object();
var myImg = new Image();
var myArray = new Array();
var myString = new String();
theDiv = document.getElementById(‘n’);
theDiv.innerHTML = typeof(myObject) + ‘<br [...]

Javascript: testing whether elements or properties exist

Posted by: Paul on: February 1, 2007

PHP has a simple function to test whether a variable or array key is set:

if(isset($somevar)) {
// do PHP stuff
}

I needed the same kind of thing in JavaScript as tests like this were failing:

if(case1 && case1[0].innerHTML && case1[0].innerHTML.length > 0) {
// you won’t be doing anything in here, as your browser will cry and complain
}

Seeing as [...]