On 8/14/07, Gábor Farkas <[EMAIL PROTECTED]> wrote:
>
> hi,
>
> when using the mochikit-signal-framework,
> i usually connect the signals i use in the window.onload event.
>
> but i'm slightly worried that it might happen, that an user clicks on
> something before the onload-event is fired, and in that case, the signal
> is not connected yet.
>
> what is the usual way to solve this problem (in mochikit)?
>
> thanks,
> gabor
>

The standard way to solve this problem seems to be implementing your
own ondomload event. Perhaps this is something to be included in
future versions of MochiKit (I'm using 1.3) as it would certainly make
JavaScript suck less.

Here's my hack implementation as a basic example. It requires a <p
class="bottom"></p> at the end of the document, right before
</body></html>...

// signal ondomload when body element has loaded
// loosely based on http://brothercake.com/site/resources/scripts/domready/
ondomloadTries = 0;
ondomloadDelay = 500;
ondomloadInterval = setInterval( function() {
  ondomloadTries++;
  if ( ondomloadTries >= 12) {
    log("Too many ondomload tries, something went wrong.");
    clearInterval( ondomloadInterval );
  }
  bodies = getElementsByTagAndClassName('p', 'bottom');
  log("Looking for body",ondomloadTries,bodies);
  if ( bodies.length > 0 ) {
    log("signal ondomload!");
    try {
      signal(window,'ondomload');
    }
    catch ( e ) {
      log("EXCEPTION",e.message,e.errors);
    }
    clearInterval( ondomloadInterval );
  }
}, ondomloadDelay );

Suggestions, improvements and criticism welcome, of course...


-- 
Chris Snyder
http://chxo.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to