On Dec 17, 1:02 pm, Mean Mike <mcgra...@gmail.com> wrote:

> so I tried that and of course I get CKEDITOR not defined ...

Bummer!

> so I figure ot I'll wait for I try it this way
>         $('#fck').ckeditor();
>         var wait = setTimeout(function() {
>                 if( $.ckeditor.instance("fck")) {
>                         var editor = $.ckeditor.instance("fck");
>                         editor.document.on("keyup",function(e){
>                                 alert("keyup");
>                         });
>                         clearTimeout(wait);
>                         }
>         }, 2000);
> and this works because it waits for the editor to load but it seems to
> me there should be a better way

There certainly should be.  It makes me wonder if the plug-in really
has any value.  If all it's doing is to use jQuery's selector engine
to identify the elements you want to use for CKEditor, it hardly seems
worth it, especially when you're likely to just be selecting by id.

One thing you could do is write a simple waitFor script that
continually polls and calls your function as soon as it's ready,
something you could use like this:

    waitFor(
        function() {return $.ckeditor.instance("fck");},
        function() {
            $.ckeditor.instance("fck").document.on("keyup",function(e)
{
                alert("keyup");
            });
        },
        10000 // timeout in 10 seconds
    }

A simple version of waitFor (that doesn't do any error checking) might
look like this:

    function waitFor(testFn, mainFn, timeout) {
        var start = new Date().getTime();
        setTimeout(function again() {
            if (testFn()) {
                mainFn();
            } else if (!timeout || new Date().getTime() < start +
timeout) {
                setTimeout(again, 10);
            } else {
                // wait timed out.
            }
        }, 10);
    }

At least here, you don't have to wait an arbitrary two seconds, but
are ready to go almost as soon as your data is back.

Good luck,

  -- Scott

Reply via email to