Ticket #192 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

Better addLoadEvent function.. (DOMContentLoaded?)

Reported by: mrrau Assigned to: beau@hartshornesoftware.com
Priority: highest Milestone: MochiKit 1.5
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description

IMHO it is a good idea to fire 'onload' event after DOM has fully loaded.

The problem is that the onload event fires after all page content has loaded (including images and other binary content).

Please, check this article: http://dean.edwards.name/weblog/2006/06/again/#comment5338

Attachments

domcontentloaded.patch (3.5 kB) - added by sky@columbia.edu on 10/19/06 21:13:11.
DOMContentLoaded in MochiKit.Signal
domcontentloaded.2.patch (3.6 kB) - added by sky@columbia.edu on 10/19/06 21:44:05.
DOMContentLoaded in MochiKit.Signal patch replacement
domcontentloaded.3.patch (3.6 kB) - added by sky@columbia.edu on 10/19/06 22:07:57.
same patch, this time safer to use on DOM nodes besides document
oncontent_192.diff (2.8 kB) - added by therve@gmail.com on 11/27/06 04:53:00.

Change History

09/30/06 16:08:19 changed by bob@redivi.com

A patch would make this happen really fast.

09/30/06 16:10:16 changed by bob@redivi.com

Also note that it can't use JScript conditional comments since the dojo compressor does not support them.

10/02/06 07:54:33 changed by mrrau

JScript cond. -> yes, I understand.

I know that you can find solutin on your own ;) but check this code, from jQuery:

if ( jQuery.browser.msie ) {
	
		// Only works if you document.write() it
		document.write("<scr" + "ipt id=__ie_init defer=true " + 
			"src=//:><\/script>");
	
		// Use the defer script hack
		var script = document.getElementById("__ie_init");
		script.onreadystatechange = function() {
			if ( this.readyState != "complete" ) return;
			this.parentNode.removeChild( this );
			jQuery.ready();
		};
	
		// Clear from memory
		script = null;
}

This solution is better, because it prevents unnecessary memory consumption.

10/19/06 21:10:14 changed by sky@columbia.edu

A patch would make this happen really fast. well, here comes a patch. This was inspired, because I'd like addLoadEvent to use MochiKit.Signal if it's there, so addLoadEvent remains compatible.

This is implemented with Dean Edwards' IE script defer hack. The interface is as follows: connect(document, 'onDOMContentLoaded', func) or addLoadEvent(func)

tested in IE6 and Firefox, an example is at: http://ccnmtl.columbia.edu/draft/sky/mochikit/domContentLoaded.html

10/19/06 21:13:11 changed by sky@columbia.edu

  • attachment domcontentloaded.patch added.

DOMContentLoaded in MochiKit.Signal

10/19/06 21:44:05 changed by sky@columbia.edu

  • attachment domcontentloaded.2.patch added.

DOMContentLoaded in MochiKit.Signal patch replacement

10/19/06 22:07:57 changed by sky@columbia.edu

  • attachment domcontentloaded.3.patch added.

same patch, this time safer to use on DOM nodes besides document

11/10/06 09:32:27 changed by therve@gmail.com

  • owner deleted.
  • priority changed from normal to highest.

11/14/06 05:52:02 changed by therve@gmail.com

  • owner set to sky@columbia.edu.

Your patch doesn't work on Konqueror, and I don't think on Safari either.

11/18/06 16:05:54 changed by bob@redivi.com

  • milestone set to MochiKit 1.4.

11/24/06 10:13:36 changed by beau@hartshornesoftware.com

No, this doesn't work in Safari or WebKit?. What's the use case again?

11/26/06 00:44:38 changed by therve@gmail.com

The use case is an onload method that fires when DOM content is loaded, not waiting for static elements (eg images).

Some hints: * http://ajaxian.com/archives/domcontentloadednext * http://webreflection.blogspot.com/2006/11/my-domcontentloaded-final-solution.html * http://novemberborn.net/javascript/domcontentloaded-style-information

11/27/06 04:53:00 changed by therve@gmail.com

  • attachment oncontent_192.diff added.

11/27/06 04:54:24 changed by therve@gmail.com

  • owner changed from sky@columbia.edu to beau@hartshornesoftware.com.

I tried to find a solution. It works under Firefox and Konqueror. Beau, what do you think ?

01/20/07 18:58:47 changed by beau@hartshornesoftware.com

  • milestone deleted.

01/21/07 22:44:05 changed by anonymous

  • milestone set to MochiKit 1.5.