From 031b3049a75aafa46d3eb6960d001da89bf2dc2c Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 4 Nov 2010 01:53:59 -0500 Subject: [PATCH 1/7] fixing windows style paths and relative filesystem paths for Envjs.uri --- specs/platform/core.js | 11 +++++++++-- src/platform/core/xhr.js | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/specs/platform/core.js b/specs/platform/core.js index fd685e55..c8075c98 100644 --- a/specs/platform/core.js +++ b/specs/platform/core.js @@ -36,8 +36,6 @@ test('Envjs.uri', function(){ equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri'); equals(uri.toString(), 'http://envjs.com/specs/env/spec.html', 'uri'); - document = null; - uri = Envjs.uri('http://envjs.com/specs/env/spec.html'); ok(uri, 'Able to create uri'); equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri'); @@ -53,6 +51,15 @@ test('Envjs.uri', function(){ uri = Envjs.uri('file:///foo/bar/'); equals(uri, 'file:///foo/bar/', 'File, absolute, with ending "/"'); + + // handle windows style file paths, firefox will convert this to a file: URL + uri = Envjs.uri('C:\\foo\\bar\\index.html'); + equals(uri, 'file:///C:/foo/bar/index.html', 'File, absolute, converted slashes'); + + // when there is no document and you pass a relative path, it should be converted to a file: URL + document = null; + uri = Envjs.uri('specs/env/spec.html'); + ok(/file\:\/\/\/.*\/specs\/env\/spec.html/.test(uri), 'Relative filesystem paths work'); uri = Envjs.uri('http://foo.com'); equals(uri, 'http://foo.com/', 'http, absolute, without path, without ending "/"'); diff --git a/src/platform/core/xhr.js b/src/platform/core/xhr.js index 41141b7b..a4c2f7bb 100644 --- a/src/platform/core/xhr.js +++ b/src/platform/core/xhr.js @@ -14,6 +14,7 @@ Envjs.getcwd = function() { * @param {Object} base (semi-optional) The base url used in resolving "path" above */ Envjs.uri = function(path, base) { + path = path.replace(/\\/g, '/'); //console.log('constructing uri from path %s and base %s', path, base); // Semi-common trick is to make an iframe with src='javascript:false' @@ -27,6 +28,12 @@ Envjs.uri = function(path, base) { return urlparse.urlnormalize(path); } + // if path is a Windows style absolute path (C:\foo\bar\index.html) + // make it a file: URL + if (path.match('^[a-zA-Z]+:/')) { + return 'file:///' + urlparse.urlnormalize(path); + } + // interesting special case, a few very large websites use // '//foo/bar/' to mean 'http://foo/bar' if (path.match('^//')) { @@ -48,7 +55,7 @@ Envjs.uri = function(path, base) { // if base is still empty, then we are in QA mode loading local // files. Get current working directory if (!base) { - base = 'file://' + Envjs.getcwd() + '/'; + base = 'file:///' + (""+Envjs.getcwd()).replace(/\\/g, '/') + '/'; } // handles all cases if path is abosulte or relative to base // 3rd arg is "false" --> remove fragments From b645a704c7092d6de9cd7c5bffdcbd6978d204d6 Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 4 Nov 2010 02:00:46 -0500 Subject: [PATCH 2/7] accidentally removed document=null in the tests, restoring that --- specs/platform/core.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/platform/core.js b/specs/platform/core.js index c8075c98..d175e949 100644 --- a/specs/platform/core.js +++ b/specs/platform/core.js @@ -35,6 +35,8 @@ test('Envjs.uri', function(){ ok(uri, 'Able to create uri'); equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri'); equals(uri.toString(), 'http://envjs.com/specs/env/spec.html', 'uri'); + + document = null; uri = Envjs.uri('http://envjs.com/specs/env/spec.html'); ok(uri, 'Able to create uri'); From e080d0de8390e20ec31bf8a51bcd71afc7a88ceb Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 4 Nov 2010 19:11:04 -0500 Subject: [PATCH 3/7] adding afterInlineScriptLoad hook support --- src/platform/core/html.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/core/html.js b/src/platform/core/html.js index 18aeba80..bc84d737 100644 --- a/src/platform/core/html.js +++ b/src/platform/core/html.js @@ -40,6 +40,9 @@ Envjs.loadInlineScript = function(script){ 'eval('+script.text.substring(0,16)+'...):'+new Date().getTime() ); } + if ( Envjs.afterInlineScriptLoad ) { + Envjs.afterInlineScriptLoad(script) + } //console.log('evaluated at scope %s \n%s', // script.ownerDocument.ownerWindow.guid, script.text); }; From 65b41c619d2be4999733b21cdd7e32b1216b0c91 Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 4 Nov 2010 19:14:29 -0500 Subject: [PATCH 4/7] adding fireLoad hook support, if false, load will not be fired (so the application will not start up) --- src/parser/htmldocument.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/parser/htmldocument.js b/src/parser/htmldocument.js index e4f6f1e8..71c5d882 100644 --- a/src/parser/htmldocument.js +++ b/src/parser/htmldocument.js @@ -155,6 +155,9 @@ var __elementPopped__ = function(ns, name, node){ doc.parsing = false; //DOMContentLoaded event try{ + if ( Envjs.fireLoad === false ) { + return; + } if(doc.createEvent){ event = doc.createEvent('Events'); event.initEvent("DOMContentLoaded", false, false); From 3954fb157c7585605731c3fed0d8d39ea731c081 Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Fri, 5 Nov 2010 01:05:24 -0500 Subject: [PATCH 5/7] dontPrintUserAgent option will cause userAgent string not to print when you load Envjs --- src/platform/core/__global__.js | 4 ++++ src/window/window.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform/core/__global__.js b/src/platform/core/__global__.js index 08869f32..64b3b6a3 100644 --- a/src/platform/core/__global__.js +++ b/src/platform/core/__global__.js @@ -30,6 +30,10 @@ var Envjs = function(){ override(arguments[1]); window.location = arguments[0]; } + if (Envjs.dontPrintUserAgent !== true && Envjs.printedUserAgent !== true) { + Envjs.printedUserAgent = true; + console.log('[ %s ]', window.navigator.userAgent); + } return; }, __this__ = this; diff --git a/src/window/window.js b/src/window/window.js index 06292fff..c6fe6b41 100644 --- a/src/window/window.js +++ b/src/window/window.js @@ -325,5 +325,4 @@ Window = function(scope, parent, opener){ //finally pre-supply the window with the window-like environment //console.log('Default Window'); -new Window(__this__, __this__); -console.log('[ %s ]',window.navigator.userAgent); +new Window(__this__, __this__); \ No newline at end of file From 00b98a86ed883b94e2ae89fbd8ee7efcb45e0ba4 Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Fri, 5 Nov 2010 02:56:50 -0500 Subject: [PATCH 6/7] removing all the global var declarations because defining something with var in the global namespace means it can't be deleted, if you declare something without var, you can delete the property. plus, there is no advantage to declaring with var --- src/console/__global__.js | 4 ++-- src/css/__global__.js | 4 ++-- src/dom/__global__.js | 4 ++-- src/event/__global__.js | 4 ++-- src/html/__global__.js | 3 ++- src/parser/__global__.js | 5 ++--- src/platform/core/__global__.js | 2 +- src/platform/rhino/__global__.js | 2 +- src/timer/__global__.js | 4 ++-- src/window/__global__.js | 4 ++-- src/xhr/__global__.js | 3 ++- 11 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/console/__global__.js b/src/console/__global__.js index 1b073730..ab96506e 100644 --- a/src/console/__global__.js +++ b/src/console/__global__.js @@ -2,5 +2,5 @@ /** * @author envjs team */ -var Console, - console; +/*var Console, + console;*/ diff --git a/src/css/__global__.js b/src/css/__global__.js index f934c1a7..9c59f7f3 100644 --- a/src/css/__global__.js +++ b/src/css/__global__.js @@ -2,7 +2,7 @@ /** * DOM Style Level 2 */ -var CSS2Properties, +/*var CSS2Properties, CSSRule, CSSStyleRule, CSSImportRule, @@ -13,4 +13,4 @@ var CSS2Properties, CSSStyleSheet, StyleSheet, StyleSheetList; -; +;*/ diff --git a/src/dom/__global__.js b/src/dom/__global__.js index 2bd3345f..23ee796f 100644 --- a/src/dom/__global__.js +++ b/src/dom/__global__.js @@ -13,7 +13,7 @@ * be able to correctly implement to core browser DOM interfaces." */ -var Attr, +/*var Attr, CDATASection, CharacterData, Comment, @@ -35,5 +35,5 @@ var Attr, Range, XMLSerializer, DOMParser; - +*/ diff --git a/src/event/__global__.js b/src/event/__global__.js index 5111fb91..afc65082 100644 --- a/src/event/__global__.js +++ b/src/event/__global__.js @@ -7,7 +7,7 @@ * This file simply provides the global definitions we need to * be able to correctly implement to core browser DOM Event interfaces. */ -var Event, +/*var Event, MouseEvent, UIEvent, KeyboardEvent, @@ -17,4 +17,4 @@ var Event, EventException, //nonstandard but very useful for implementing mutation events //among other things like general profiling - Aspect; \ No newline at end of file + Aspect;*/ \ No newline at end of file diff --git a/src/html/__global__.js b/src/html/__global__.js index e60eb688..05b48f2a 100644 --- a/src/html/__global__.js +++ b/src/html/__global__.js @@ -6,7 +6,7 @@ * This file simply provides the global definitions we need to * be able to correctly implement to core browser DOM HTML interfaces. */ -var HTMLDocument, +/*var HTMLDocument, HTMLElement, HTMLCollection, HTMLAnchorElement, @@ -64,3 +64,4 @@ var HTMLDocument, Option, __loadImage__, __loadLink__; +*/ \ No newline at end of file diff --git a/src/parser/__global__.js b/src/parser/__global__.js index 51e04bcc..42ff5f2b 100644 --- a/src/parser/__global__.js +++ b/src/parser/__global__.js @@ -2,7 +2,6 @@ //these are both non-standard globals that //provide static namespaces and functions //to support the html 5 parser from nu. -var XMLParser = {}, - HTMLParser = {}; - +XMLParser = {}; +HTMLParser = {}; \ No newline at end of file diff --git a/src/platform/core/__global__.js b/src/platform/core/__global__.js index 64b3b6a3..b7332c4c 100644 --- a/src/platform/core/__global__.js +++ b/src/platform/core/__global__.js @@ -5,7 +5,7 @@ * Copyright 2008-2010 John Resig, under the MIT License */ -var Envjs = function(){ +Envjs = function(){ var i, name, override = function(){ diff --git a/src/platform/rhino/__global__.js b/src/platform/rhino/__global__.js index fab8f277..c5a40465 100644 --- a/src/platform/rhino/__global__.js +++ b/src/platform/rhino/__global__.js @@ -5,7 +5,7 @@ * Copyright 2008-2010 John Resig, under the MIT License */ -var __context__ = Packages.org.mozilla.javascript.Context.getCurrentContext(); +__context__ = Packages.org.mozilla.javascript.Context.getCurrentContext(); Envjs.platform = "Rhino"; Envjs.revision = "1.7.0.rc2"; diff --git a/src/timer/__global__.js b/src/timer/__global__.js index 0113278c..e36b4821 100644 --- a/src/timer/__global__.js +++ b/src/timer/__global__.js @@ -10,10 +10,10 @@ * * requires Envjs.wait, Envjs.sleep, Envjs.WAIT_INTERVAL */ -var setTimeout, +/*var setTimeout, clearTimeout, setInterval, clearInterval; - +*/ \ No newline at end of file diff --git a/src/window/__global__.js b/src/window/__global__.js index f0874bfd..30e13d29 100644 --- a/src/window/__global__.js +++ b/src/window/__global__.js @@ -2,8 +2,8 @@ /** * @todo: document */ -var Window, +/*var Window, Screen, History, Navigator; - +*/ diff --git a/src/xhr/__global__.js b/src/xhr/__global__.js index ff185f16..fa400c93 100644 --- a/src/xhr/__global__.js +++ b/src/xhr/__global__.js @@ -10,5 +10,6 @@ * be able to correctly implement to core browser (XML)HTTPRequest * interfaces. */ -var Location, +/*var Location, XMLHttpRequest; +*/ \ No newline at end of file From 9e60fcf6dcb8c629f9817d9b767f62368f62a60a Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Fri, 5 Nov 2010 03:57:35 -0500 Subject: [PATCH 7/7] adding support for killTimersAfterLoad, which kills any timers when load is fired --- src/parser/htmldocument.js | 3 +++ src/timer/timer.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/parser/htmldocument.js b/src/parser/htmldocument.js index 71c5d882..4cbef07e 100644 --- a/src/parser/htmldocument.js +++ b/src/parser/htmldocument.js @@ -155,6 +155,9 @@ var __elementPopped__ = function(ns, name, node){ doc.parsing = false; //DOMContentLoaded event try{ + if ( Envjs.killTimersAfterLoad === true ) { + Envjs.clear(); + } if ( Envjs.fireLoad === false ) { return; } diff --git a/src/timer/timer.js b/src/timer/timer.js index 3d6f217b..fa410c85 100644 --- a/src/timer/timer.js +++ b/src/timer/timer.js @@ -11,6 +11,18 @@ $timers.lock = function(fn){ Envjs.sync(fn)(); }; +Envjs.clear = function(){ + $timers.lock(function(){ + for(var i=0; i<$timers.length; i++) { + if ( !$timers[i] ) { + continue; + } + $timers[i].stop(); + delete $timers[i]; + } + }); +} + //private internal class var Timer = function(fn, interval){ this.fn = fn;