Forum:Detecting when RTE is loaded

I'm writing a template preload script, based on the one found on Wookieepedia. It simply replaces the template module in the source editor with a dropdown, predefined list of templates that can be inserted into the edit area. I'm having a little trouble making it work with RTE.

The code I'm currently using is that found on Grunny's talk page: But when it's loading CKEDITOR isn't defined and it throws an error. This is only a problem when Visual editing is enabled, with it disabled the editor can apparently be interacted with using. CKEDITOR is clearly defined somewhere else, so does anyone know how to declare a dependency on the script that defined it? I thought something like, but I couldn't see if there was a module being defined for this or not.

The full script can be found here, and can be tested here.