DomReady and MooTools 1.11

Joomla! 1.5 and many of its extensions in JavaScript scripts still use MooTools 1.11, which have sometimes problem with supporting DomReady (DOMContentLoaded) event in IE browsers.

DomReady and MooTools

If we do not want to see such errors:

 Message: HTML Parsing Error:
Unable to modify the parent container element before the 
child element is closed (KB927917)
Line: 0
Char: 0
Code: 0

I suggest adding a code fragment below on the end of mootools.js file from media/ catalog:

 Element.Events.domready = {
 add: function(fn){
 if (window.loaded){
 fn.call(this); 
 return;
 }
 
 var domReady = function(){
 if (window.loaded) return;
 window.loaded = true;
 window.timer = $clear(window.timer);
 this.fireEvent('domready');
 }.bind(this);
 
 if (document.readyState && window.webkit){
 window.timer = function(){
 if (['loaded','complete'].contains(document.readyState)) domReady();
 }.periodical(50);
 } else {
 window.addListener("load", domReady);
 document.addListener("DOMContentLoaded", domReady);
 } }
}; 

Instead of looking for all scripts with a line:

window.addEvent("domready", function(){

And changing it into:

window.addEvent("load", function(){

The advantage of this solution is that in browsers (other than IE) domready event will be working as DOMContentLoaded event and will be changed immediately to load event only in IE.

DomReady and MooTools 1.11 4.505 (90.00%) 2 votes
Share
This article was first published April 19th, 2010