Skip to content

Commit

Permalink
Updated the domReady loading to resolve a possible ie7 crash.
Browse files Browse the repository at this point in the history
The domReady library was having issues with IE7, the code has been updated
in the combined file to provide a less-obtrusive dom-content-loaded function
for initializing TinyMCE.
  • Loading branch information
trevorrowe committed Oct 12, 2009
1 parent f94d456 commit 987356b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 143 deletions.
158 changes: 16 additions & 142 deletions app/controllers/tinymce/hammer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,148 +63,22 @@ def combine
# it was loaded via a combined file.
def init_content
@content = <<-JS
// domReady.js
//
// DOMContentLoaded event handler. Works for browsers that don't support the DOMContentLoaded event.
//
// Modification Log:
// Date Initial Description
// 26 May 2008 TKO Created by Tanny O'Haley
/*global addEvent, escape, unescape */
var domReadyEvent = {
name: "domReadyEvent",
// Array of DOMContentLoaded event handlers.
events: {},
domReadyID: 1,
bDone: false,
DOMContentLoadedCustom: null,
// Function that adds DOMContentLoaded listeners to the array.
add: function(handler) {
// Assign each event handler a unique ID. If the handler has an ID, it
// has already been added to the events object or been run.
if (!handler.$$domReadyID) {
handler.$$domReadyID = this.domReadyID++;
// If the DOMContentLoaded event has happened, run the function.
if(this.bDone){
handler();
}
// store the event handler in the hash table
this.events[handler.$$domReadyID] = handler;
}
},
remove: function(handler) {
// Delete the event handler from the hash table
if (handler.$$domReadyID) {
delete this.events[handler.$$domReadyID];
}
},
// Function to process the DOMContentLoaded events array.
run: function() {
// quit if this function has already been called
if (this.bDone) {
return;
}
// Flag this function so we don't do the same thing twice
this.bDone = true;
// iterates through array of registered functions
for (var i in this.events) {
this.events[i]();
}
},
schedule: function() {
// Quit if the init function has already been called
if (this.bDone) {
return;
}
// First, check for Safari or KHTML.
if(/KHTML|WebKit/i.test(navigator.userAgent)) {
if(/loaded|complete/.test(document.readyState)) {
this.run();
} else {
// Not ready yet, wait a little more.
setTimeout(this.name + ".schedule()", 100);
}
} else if(document.getElementById("__ie_onload")) {
// Second, check for IE.
return true;
}
// Check for custom developer provided function.
if(typeof this.DOMContentLoadedCustom === "function") {
//if DOM methods are supported, and the body element exists
//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
if(typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null)) {
// Call custom function.
if(this.DOMContentLoadedCustom()) {
this.run();
} else {
// Not ready yet, wait a little more.
setTimeout(this.name + ".schedule()", 250);
}
}
}
return true;
},
init: function() {
// If addEventListener supports the DOMContentLoaded event.
if(document.addEventListener) {
document.addEventListener("DOMContentLoaded", function() { domReadyEvent.run(); }, false);
}
// Schedule to run the init function.
setTimeout("domReadyEvent.schedule()", 100);
function run() {
domReadyEvent.run();
}
// Just in case window.onload happens first, add it to onload using an available method.
if(typeof addEvent !== "undefined") {
addEvent(window, "load", run);
} else if(document.addEventListener) {
document.addEventListener("load", run, false);
} else if(typeof window.onload === "function") {
var oldonload = window.onload;
window.onload = function() {
domReadyEvent.run();
oldonload();
};
} else {
window.onload = run;
}
/* for Internet Explorer */
/*@cc_on
@if (@_win32 || @_win64)
document.write('<script id=__ie_onload defer src="//:"><\/script>');
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
domReadyEvent.run(); // call the onload handler
}
};
@end
@*/
}
};
var domReady = function(handler) { domReadyEvent.add(handler); };
domReadyEvent.init();
(function(){var DomReady=window.DomReady={};var userAgent=navigator.userAgent.toLowerCase();var browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:(/msie/.test(userAgent))&&(!/opera/.test(userAgent)),mozilla:(/mozilla/.test(userAgent))&&(!/(compatible|webkit)/.test(userAgent))};var readyBound=false;var isReady=false;var readyList=[];function domReady(){if(!isReady){isReady=true;if(readyList){for(var fn=0;fn<readyList.length;fn++){readyList[fn].call(window,[]);}
readyList=[];}}};function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){if(oldonload){oldonload();}
func();}}};function bindReady(){if(readyBound){return;}
readyBound=true;if(document.addEventListener&&!browser.opera){document.addEventListener("DOMContentLoaded",domReady,false);}
if(browser.msie&&window==top)(function(){if(isReady)return;try{document.documentElement.doScroll("left");}catch(error){setTimeout(arguments.callee,0);return;}
domReady();})();if(browser.opera){document.addEventListener("DOMContentLoaded",function(){if(isReady)return;for(var i=0;i<document.styleSheets.length;i++)
if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return;}
domReady();},false);}
if(browser.safari){var numStyles;(function(){if(isReady)return;if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return;}
if(numStyles===undefined){var links=document.getElementsByTagName("link");for(var i=0;i<links.length;i++){if(links[i].getAttribute('rel')=='stylesheet'){numStyles++;}}
var styles=document.getElementsByTagName("style");numStyles+=styles.length;}
if(document.styleSheets.length!=numStyles){setTimeout(arguments.callee,0);return;}
domReady();})();}
addLoadEvent(domReady);};DomReady.ready=function(fn,args){bindReady();if(isReady){fn.call(window,[]);}else{readyList.push(function(){return fn.call(window,[]);});}};bindReady();})();
window.tinyMCEPreInit = {
base : '#{Tinymce::Hammer.url_path}',
Expand Down
2 changes: 1 addition & 1 deletion lib/tinymce/hammer/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def tinymce_hammer_javascript_tags
tinyMCE.execCommand("mceAddControl", true, dom_id);
}
}
domReady(TinymceHammer.init);
DomReady.ready(TinymceHammer.init);
</script>
JS
end
Expand Down

0 comments on commit 987356b

Please sign in to comment.