paul bennett

Archive for the ‘JavaScript’ Category

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

The ee-yui plugin in the Expression Engine editing interface

The ee-yui plugin in the Expression Engine editing interface

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 full plugin from the nice folks at Google Code:

ee-YUI full editor > plugin information and downloads

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:

  1. the awesomeness of the YUI library
  2. the thoroughness of the YUI documentation
  3. the simplicity of creating extensions for Expression Engine

it was surprisingly straightforward.

If you’re using Expression Engine and are either sick of fighting with tinymce or aren’t using a rich text editor, you can download it from http://code.google.com/p/ee-yui/.

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 attribute.

Tags: ,

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 at it. I decided to after reading Cameron Moll’s latest post in his ‘the highly extensible interface’ series. I had a nice challenge for it too. I needed to recreate our sites navigation using way cleaner mark-up and unobtrusive JavaScript to replace the existing ‘tables-and-document.write’ nightmare.

To cut a long story short, I was able to not only recreate but also improve the navigation and it all took only 2 hours and about 50 lines of code. All I ended up with a solution which was less than a quarter the size of the original but supported more browsers and (in my opinion) had a more satisfying behaviour.

Seriously, a framework which makes things this easy and yet is so powerful deserves a lot of praise. Even after being reasonably familiar with YUI, I believe it wouyld have taken me around three times as long to get a working solution using ther YUI components. Remember – this was the first time I’d ever used jQuery

jQuery, I’m converted.

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.

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:


Archives