Permalink
Browse files

The onload handler is more like dom:ready now so browser-based testin…

…g works more naturally
  • Loading branch information...
1 parent c05c8ed commit 947e1d50a22100e063b090a4f61174b2362ec4a7 Alex Young committed Oct 23, 2009
Showing with 39 additions and 3 deletions.
  1. +39 −3 riot.js
View
42 riot.js
@@ -18,11 +18,10 @@ var Riot = {
break;
case 'browser':
Riot.formatter = new Riot.Formatters.HTML();
- var onload = window.onload;
- window.onload = function() {
+ Riot.onload(function() {
if (onload) { window.onload(); }
Riot.runAndReport(tests);
- };
+ });
break;
}
},
@@ -41,6 +40,43 @@ var Riot = {
}
},
+ onload: function(callback) {
+ function init() {
+ if (arguments.callee.done) return;
+ arguments.callee.done = true;
+ if (_timer) clearInterval(_timer);
+ callback();
+ }
+
+ if (document.addEventListener) {
+ document.addEventListener("DOMContentLoaded", init, false);
+ }
+
+ /* for Internet Explorer */
+ /*@cc_on @*/
+ /*@if (@_win32)
+ document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>")
+ var script = document.getElementById("__ie_onload")
+ script.onreadystatechange = function() {
+ if (this.readyState == "complete") {
+ init()
+ }
+ }
+ /*@end @*/
+
+ /* for Safari */
+ if (/WebKit/i.test(navigator.userAgent)) {
+ var _timer = setInterval(function() {
+ if (/loaded|complete/.test(document.readyState)) {
+ init();
+ }
+ }, 10);
+ }
+
+ /* for other browsers */
+ window.onload = init;
+ },
+
runAndReport: function(tests) {
this.running = true;
var benchmark = Riot.Benchmark.run(1, function() { Riot.runAllContexts(tests); });

0 comments on commit 947e1d5

Please sign in to comment.