Skip to content

Commit

Permalink
added equivalent frame modification for elementPopped as we had for a…
Browse files Browse the repository at this point in the history
…ppendChild, integrated readme.refactor into main readme (including correction from nickg), have a bunch of patches to apply from nickg and FroMage in the next hour or so depending on how late I can stay up
  • Loading branch information
thatcher committed Mar 17, 2010
1 parent 3398872 commit c9fdb70
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 107 deletions.
124 changes: 97 additions & 27 deletions README
@@ -1,8 +1,10 @@
= envjs : pilot fish =

env.js : A pure JavaScript browser environment.
Developed by John Resig (http://ejohn.org)

Major Contributers:
Chris Thatcher (http://github.com/thatcher)
Envjs Team

GitHub repositories:
http://github.com/jeresig/env-js/
Expand All @@ -12,7 +14,7 @@ Mailing List:
http://groups.google.com/group/envjs

Lighthouse (Bug Tracking):
http://envjs.lighthouseapp.com/projects/21590-envjs/
http://envjs.lighthouseapp.com/

Build Status:
http://runcoderun.com/thatcher/env-js
Expand All @@ -27,31 +29,74 @@ Getting the code:

* Check the code out from git: git clone git://github.com/thatcher/env-js.git

Building:
* run "ant concat"
* Creates a platform-agnostic "dist/env.js" file and a Rhino-specific "dist/env.rhino.js" file.

Testing:
* Checkout qunit: "git submodule update --init"
* run "ant test"

Java command line:

env.rhino.js can be run either with a "generic" version of the Rhino
library (js.jar), or with the repackaged/extended version of Rhino
supplied with env.js (env-js.jar). If your application uses multiple
windows, frames, or iframes, or if it depends on precise adherence to
JavaScript object scoping in event handlers, you will have to use
env-js.jar. Simple applications may be able to run with the generic
version of Rhino.

The command line used for testing env.js can be found in build.xml,
although the general form is:
java -jar [jar file] [javascript file]
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
local path to a different version of the Rhino js.jar file. The
"javascript file" is the path to the JavaScript you wish to execute.

* Build targets
> ant //(does all the following in order)
> ant env-platforms
> ant console-specs
> ant dom-specs
> ant event-specs
> ant html-specs
> ant timer-specs
> ant parser-specs
> ant xhr-specs
> ant window-specs


== src folder ==

The source files for this project are organized by the conventions described
below. All final sources are included here, including the massaged parser.
Platform developers are welcome to use the src/env/ folder to consider a new
platform.

== specs folder ==

The 'specifications' are our best attempt at isolating some DOM Spec into
something we can measure via an existing implementation, namely Firefox, and
which also allow us to pass the same tests in a Platform.


== a couple code conventions ==

* Page width <= 80
* 'Modules' are isolated as
var A,B,C;
(function(){
A = ...;
B = ...;
C = ...;
})();
* Modules depend on each other in some order. Many modules provide mix-ins to
enhance interfaces exposed in other modules. events.js for example, provide
dom 2 events for the dom.js module, adding addEventListener etc to the dom.
Here is the general hierarchy as proposed:

dom.js |->event.js |->html.js |->timer.js |->parser.js |->xhr.js |->window.js

all together we also include what we believe is a platform specific module
that describes the interfaces that must be implemented in a platform specific
api, and this lives in src/platform/(core|rhino).
* Variable naming should be short but complete words.
* Module level internal functions should be prefixed and appended with __.
For example __example__.


== contributing tests with patches ==

Each module has a spec in env-js/test/spec. Most tests will run whether you
load them in the file:, http:, or https:, though once you get to xhr.js
the tests will fail for the 'file:' protocol in firefox because of
permissions. To run xhr.js and window.js specs, copy settings.js to
local_settings.js and run a local server to satisfy those urls included in
the spec.js;


== platforms ==

Out of the box we have support for native platforms with rhino. A spidermonkey
port is also being widely used, and we hope to integrate into the main branch
or as a github plugin.

Installing:
1) Include the proper env.js file for your platform.
load('env.rhino.js'); //if in a Rhino script
Expand Down Expand Up @@ -100,12 +145,37 @@ succession into the same window, load the first into a new window
object using window.open().

Testing jQuery Compatibility:
* run ./bin/test-jquery.sh #runs 1.4.1 by default
* run ./bin/test-jquery.sh 1.3.2
* run ./bin/test-jquery.sh 1.3.1
* run ./bin/test-jquery.sh 1.2.6
* Checks out the given jQuery tag from Subversion into test/vendor/jQuery/[version],
moves dist/env.rhino.js into the correct location in their tree, and runs the test suites.


== 1.1 to 1.2 note ==

The goal for refactoring 1.1.rcX to 1.2.X was primarily to isolate and
organize the code into more independent areas, provide behavior driven testing
with tests that run on firefox for each module and it's dependencies.

Java command line:

env.rhino.js can be run either with a "generic" version of the Rhino
library (js.jar), or with the repackaged/extended version of Rhino
supplied with env.js (env-js.jar). If your application uses multiple
windows, frames, or iframes, or if it depends on precise adherence to
JavaScript object scoping in event handlers, you will have to use
env-js.jar. Simple applications may be able to run with the generic
version of Rhino.

The command line used for testing env.js can be found in build.xml,
although the general form is:
java -jar [jar file] [javascript file]
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
local path to a different version of the Rhino js.jar file. The
"javascript file" is the path to the JavaScript you wish to execute.

Changes with new timer code:

Previously with envjs, you could call Java's thread sleep() method to delay execution. This was mostly used in test suites. This may no
Expand Down
76 changes: 0 additions & 76 deletions README.Refactor.txt

This file was deleted.

2 changes: 1 addition & 1 deletion build.properties
Expand Up @@ -2,7 +2,7 @@
PROJECT: env-js
BUILD_MAJOR: 1
BUILD_MINOR: 2
BUILD_ID: 0.6
BUILD_ID: 0.7
BUILD_VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
BUILD: ${PROJECT}.${BUILD_VERSION}
VERSION: ${BUILD} ${DSTAMP}
Expand Down
2 changes: 1 addition & 1 deletion src/event/eventtarget.js
Expand Up @@ -130,7 +130,7 @@ function __dispatchEvent__(target, event, bubbles){
//with default behavior being executed in a browser but I could be
//wrong as usual. The goal is much more to filter at this point
//what events have no need to be handled
console.log('triggering default behavior for %s', event.type);
//console.log('triggering default behavior for %s', event.type);
if(event.type in Envjs.defaultEventBehaviors){
Envjs.defaultEventBehaviors[event.type](event);
}
Expand Down
37 changes: 36 additions & 1 deletion src/parser/htmldocument.js
Expand Up @@ -66,7 +66,42 @@ var __elementPopped__ = function(ns, name, node){
break;
case 'frame':
case 'iframe':
node.contentWindow = { };
node.contentDocument = new HTMLDocument(new DOMImplementation(), node.contentWindow);
node.contentWindow.document = node.contentDocument;
try{
Window;
}catch(e){
node.contentDocument.addEventListener('DOMContentLoaded', function(){
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
});
}
try{
if (node.src && node.src.length > 0){
//console.log("getting content document for (i)frame from %s", node.src);
Envjs.loadFrame(node, Envjs.uri(node.src));
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
}else{
//I dont like this being here:
//TODO: better mix-in strategy so the try/catch isnt required
try{
if(Window){
Envjs.loadFrame(node);
//console.log('src/html/document.js: triggering frame load');
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
}
}catch(e){}
}
}catch(e){
console.log('error loading html element %s %e', node, e.toString());
}
/*try{
if (node.src && node.src.length > 0){
//console.log("getting content document for (i)frame from %s", node.src);
Envjs.loadFrame(node, Envjs.uri(node.src));
Expand All @@ -78,7 +113,7 @@ var __elementPopped__ = function(ns, name, node){
}
}catch(e){
console.log('error loading html element %s %s %s %e', ns, name, node, e.toString());
}
}*/
break;
case 'link':
if (node.href && node.href.length > 0){
Expand Down
2 changes: 1 addition & 1 deletion src/platform/core/__global__.js
Expand Up @@ -25,7 +25,7 @@ var Envjs = function(){
window.location = arguments[0];
}else if (arguments.length === 1 && typeof(arguments[0]) == "object"){
override(arguments[0])
}else if(arguments.length === 2){
}else if(arguments.length === 2 && typeof(arguments[0]) == 'string'){
override(arguments[1]);
window.location = arguments[0];
}
Expand Down
20 changes: 20 additions & 0 deletions src/window/eventtarget.js
@@ -0,0 +1,20 @@
/**
*
* @param {Object} event
*/
__extend__(Envjs.defaultEventBehaviors,{

'submit': function(event){
var target = event.target;
while(target.nodeName != 'FORM'){
target = target.parentNode;
}
if(target.nodeName == 'FORM'){
target.submit
}
},
'click': function(event){
console.log('handling event target default behavior for click');
}

});

0 comments on commit c9fdb70

Please sign in to comment.