By placing the below script in the UI's header immediately above the closing
</head> tag, I've managed to emulate the document/ready behavior of various
Javascript frameworks such as jQuery.  Instead of trying to optimize for the
various browsers, I just rely on what works for the least common
denominator, IE.  Please refer to
http://ryanmorr.com/archives/ondomready-no-browser-sniffing and/or
http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
to
take note of how IE checks for document.documentElement.

<script>
//console.log('script begin: ' + (new Date()).getTime());

var fossil_ui = {'ready': function() {
    alert('fossil ui ready!');
}};

fossil_ui.ready_interval = setInterval(function() {
    var docEl = document.documentElement;
    if (docEl) {
        clearInterval(fossil_ui.ready_interval);
        //console.log('dom ready: ' + (new Date()).getTime());
        fossil_ui.ready();
    }
}, 2);
</script>

This approach allows DOM manipulation before/without the body/onload event.
 I've tested it on IE, FF, Chrome & Safari (I suppose I can go download
Opera too ;)  To demonstrate that this allows the DOM to be scripted before
all body elements finish loading, comment in the console.log statements, and
modify the body tag as follows:

<body onload="console.log('body loaded: ' + (new Date()).getTime())">

Then in FF (or another browser that supports console/log), I got the
following when I did a hard-refresh (to circumvent caching) of the UI home
page:

script begin:  1301164708735
dom ready:    1301164708782
body loaded: 1301164708965

Being able to work with the DOM before the body loads can be important,
particularly if images or other elements for some reason take an inordinate
amount of time to download, plus de-coupling from the body/onload event
allows scripting with as few dependencies as possible.  Please consider this
as the first step toward possibly warranting a separate Javascript file for
inclusion, not unlike the style.css file.
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to