Skip to content

Commit

Permalink
Merge branch 'onload-events' into multi-window
Browse files Browse the repository at this point in the history
Conflicts:
	dist/env.js
	dist/env.rhino.js
	src/dom/implementation.js
	test/unit/onload.js
  • Loading branch information
gleneivey committed Jul 24, 2009
2 parents 966c248 + 19805a0 commit 13d810a
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 49 deletions.
49 changes: 34 additions & 15 deletions dist/env.js
Expand Up @@ -3528,15 +3528,23 @@ var DOMImplementation = function() {
this.errorChecking = true; // by default, test for exceptions
};

var $handleEndOfNormalOrEmptyElement = function(node, doc){
var $handleEndOfNormalOrEmptyElement = function(node, doc, p){
if(node.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(node, p);

//handle frame and iframe tags
if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){
// only fire event if we actually had something to load
if (node.src && node.src.length > 0){
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){

if (node.src && node.src.length > 0){
$debug("getting content document for (i)frame from " +
node.src);
$debug("getting content document for (i)frame from " + node.src);

// create a new global/window object, such that its methods and
// objects are defined within the scope of the new global.
Expand Down Expand Up @@ -3607,6 +3615,14 @@ var $handleEndOfNormalOrEmptyElement = function(node, doc){
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'img'){
if (node.src && node.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
}

__extend__(DOMImplementation.prototype,{
Expand Down Expand Up @@ -3835,14 +3851,7 @@ function __parseLoop__(impl, doc, p) {
}

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else
$handleEndOfNormalOrEmptyElement(iNodeParent, doc);

$handleEndOfNormalOrEmptyElement(iNodeParent, doc, p);
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree
}

Expand Down Expand Up @@ -3930,7 +3939,7 @@ function __parseLoop__(impl, doc, p) {
}


$handleEndOfNormalOrEmptyElement(iNode, doc);
$handleEndOfNormalOrEmptyElement(iNode, doc, p);
iNodeParent.appendChild(iNode); // attach Element to parentNode
}
else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events
Expand Down Expand Up @@ -6208,12 +6217,19 @@ __extend__(HTMLImageElement.prototype, {
},
set src(value){
this.setAttribute('src', value);

var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
},
get width(){
return this.getAttribute('width');
},
set width(value){
this.setAttribute('width', value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down Expand Up @@ -6810,6 +6826,9 @@ __extend__(HTMLScriptElement.prototype, {
},
set type(value){
this.setAttribute('type',value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down
49 changes: 34 additions & 15 deletions dist/env.rhino.js
Expand Up @@ -3967,15 +3967,23 @@ var DOMImplementation = function() {
this.errorChecking = true; // by default, test for exceptions
};

var $handleEndOfNormalOrEmptyElement = function(node, doc){
var $handleEndOfNormalOrEmptyElement = function(node, doc, p){
if(node.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(node, p);

//handle frame and iframe tags
if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){
// only fire event if we actually had something to load
if (node.src && node.src.length > 0){
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){

if (node.src && node.src.length > 0){
$debug("getting content document for (i)frame from " +
node.src);
$debug("getting content document for (i)frame from " + node.src);

// create a new global/window object, such that its methods and
// objects are defined within the scope of the new global.
Expand Down Expand Up @@ -4046,6 +4054,14 @@ var $handleEndOfNormalOrEmptyElement = function(node, doc){
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'img'){
if (node.src && node.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
}

__extend__(DOMImplementation.prototype,{
Expand Down Expand Up @@ -4274,14 +4290,7 @@ function __parseLoop__(impl, doc, p) {
}

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else
$handleEndOfNormalOrEmptyElement(iNodeParent, doc);

$handleEndOfNormalOrEmptyElement(iNodeParent, doc, p);
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree
}

Expand Down Expand Up @@ -4369,7 +4378,7 @@ function __parseLoop__(impl, doc, p) {
}


$handleEndOfNormalOrEmptyElement(iNode, doc);
$handleEndOfNormalOrEmptyElement(iNode, doc, p);
iNodeParent.appendChild(iNode); // attach Element to parentNode
}
else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events
Expand Down Expand Up @@ -6647,12 +6656,19 @@ __extend__(HTMLImageElement.prototype, {
},
set src(value){
this.setAttribute('src', value);

var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
},
get width(){
return this.getAttribute('width');
},
set width(value){
this.setAttribute('width', value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down Expand Up @@ -7249,6 +7265,9 @@ __extend__(HTMLScriptElement.prototype, {
},
set type(value){
this.setAttribute('type',value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down
Binary file modified rhino/mainForEnvjs.jar
Binary file not shown.
39 changes: 24 additions & 15 deletions src/dom/implementation.js
Expand Up @@ -12,15 +12,23 @@ var DOMImplementation = function() {
this.errorChecking = true; // by default, test for exceptions
};

var $handleEndOfNormalOrEmptyElement = function(node, doc){
var $handleEndOfNormalOrEmptyElement = function(node, doc, p){
if(node.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(node, p);

//handle frame and iframe tags
if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){
// only fire event if we actually had something to load
if (node.src && node.src.length > 0){
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'frame' ||
node.nodeName.toLowerCase() == 'iframe' ){

if (node.src && node.src.length > 0){
$debug("getting content document for (i)frame from " +
node.src);
$debug("getting content document for (i)frame from " + node.src);

// create a new global/window object, such that its methods and
// objects are defined within the scope of the new global.
Expand Down Expand Up @@ -91,6 +99,14 @@ var $handleEndOfNormalOrEmptyElement = function(node, doc){
node.dispatchEvent( event );
}
}
else if (node.nodeName.toLowerCase() == 'img'){
if (node.src && node.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = doc.createEvent();
event.initEvent("load");
node.dispatchEvent( event );
}
}
}

__extend__(DOMImplementation.prototype,{
Expand Down Expand Up @@ -319,14 +335,7 @@ function __parseLoop__(impl, doc, p) {
}

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else
$handleEndOfNormalOrEmptyElement(iNodeParent, doc);

$handleEndOfNormalOrEmptyElement(iNodeParent, doc, p);
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree
}

Expand Down Expand Up @@ -414,7 +423,7 @@ function __parseLoop__(impl, doc, p) {
}


$handleEndOfNormalOrEmptyElement(iNode, doc);
$handleEndOfNormalOrEmptyElement(iNode, doc, p);
iNodeParent.appendChild(iNode); // attach Element to parentNode
}
else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events
Expand Down
7 changes: 7 additions & 0 deletions src/html/img.js
Expand Up @@ -43,12 +43,19 @@ __extend__(HTMLImageElement.prototype, {
},
set src(value){
this.setAttribute('src', value);

var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
},
get width(){
return this.getAttribute('width');
},
set width(value){
this.setAttribute('width', value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/html/script.js
Expand Up @@ -58,6 +58,9 @@ __extend__(HTMLScriptElement.prototype, {
},
set type(value){
this.setAttribute('type',value);
},
onload: function(event){
__eval__(this.getAttribute('onload')||'')
}
});

Expand Down
38 changes: 38 additions & 0 deletions test/index.html
Expand Up @@ -60,6 +60,44 @@ <h2 id="userAgent"></h2>
</iframe>
<iframe id="emptyiframe" name="emtpyiframe" style="display:none;"></iframe>

<script>
function imgOnloadEventHandler(){
var t = document.createTextNode(
'Paragraph created by execution of img-onload event handler.');
var p = document.createElement('p');
p.setAttribute('id', 'pCreatedByImgOnload');
p.appendChild(t);
document.getElementsByTagName('body')[0].appendChild(p);
}
</script>
<img id="anImg" src="html/img1.png" onload="imgOnloadEventHandler();" />

<script>
function onloadHandlerThatShouldntExecute(){
var t = document.createTextNode(
'Paragraph created by execution of script-onload *BAD* event handler.');
var p = document.createElement('p');
p.setAttribute('id', 'pShouldntBeCreated');
p.appendChild(t);
document.getElementsByTagName('body')[0].appendChild(p);
}
</script>
<script onload="onloadHandlerThatShouldntExecute();">
function scriptOnloadEventHandler(tag){
var t = document.createTextNode(
'Paragraph created by execution of script-onload event handler.');
var p = document.createElement('p');
p.setAttribute('id', 'pCreatedByScriptOnload'+tag);
p.appendChild(t);
document.getElementsByTagName('body')[0].appendChild(p);
}
</script>
<script src="html/missingScript.js"
onload="scriptOnloadEventHandler('A');" />
<script src="html/missingScript.js"
onload="scriptOnloadEventHandler('B');"></script>


<dl id="dl" style="display:none;">
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
Expand Down

0 comments on commit 13d810a

Please sign in to comment.