Skip to content

Commit

Permalink
Tested and implemented onload event handling for iframes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gleneivey committed Jul 23, 2009
1 parent 2d68820 commit 918e093
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 5 deletions.
14 changes: 14 additions & 0 deletions dist/env.js
Expand Up @@ -3752,6 +3752,14 @@ function __parseLoop__(impl, doc, p) {
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'iframe'){
if (iNodeParent.src && iNodeParent.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
iNodeParent.dispatchEvent( event );
}
}
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down Expand Up @@ -5881,6 +5889,12 @@ __extend__(HTMLFrameElement.prototype, {
},
set src(value){
this.setAttribute('src', value);
if (this.getAttribute('src').length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
}
},
get contentDocument(){
$debug("getting content document for (i)frame");
Expand Down
14 changes: 14 additions & 0 deletions dist/env.rhino.js
Expand Up @@ -4189,6 +4189,14 @@ function __parseLoop__(impl, doc, p) {
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'iframe'){
if (iNodeParent.src && iNodeParent.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
iNodeParent.dispatchEvent( event );
}
}
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down Expand Up @@ -6318,6 +6326,12 @@ __extend__(HTMLFrameElement.prototype, {
},
set src(value){
this.setAttribute('src', value);
if (this.getAttribute('src').length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
}
},
get contentDocument(){
$debug("getting content document for (i)frame");
Expand Down
8 changes: 8 additions & 0 deletions src/dom/implementation.js
Expand Up @@ -242,6 +242,14 @@ function __parseLoop__(impl, doc, p) {
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'iframe'){
if (iNodeParent.src && iNodeParent.src.length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
iNodeParent.dispatchEvent( event );
}
}
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down
6 changes: 6 additions & 0 deletions src/html/frame.js
Expand Up @@ -55,6 +55,12 @@ __extend__(HTMLFrameElement.prototype, {
},
set src(value){
this.setAttribute('src', value);
if (this.getAttribute('src').length > 0){
// don't actually load anything, so we're "done" immediately:
var event = document.createEvent();
event.initEvent("load");
this.dispatchEvent( event );
}
},
get contentDocument(){
$debug("getting content document for (i)frame");
Expand Down
23 changes: 21 additions & 2 deletions test/index.html
Expand Up @@ -25,7 +25,26 @@ <h2 id="userAgent"></h2>
<div id="nothiddendivchild"></div>
</div>
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="html/iframe.html"></iframe>
<iframe id="loadediframe" name="loadediframe" style="display:none;"
src="html/iframe.html">
<script>
// kind of a cheat--env.js isn't smart enough to choose between
// either loading from 'src' or parsing its content, so it
// does both, which is exploited here to ensure that the
// onload handler is installed before env.js "finishes
// loading" (which happens when the /iframe tag is parsed
var iframeElem = document.getElementById('loadediframe');
iframeElem.onload = function(){
var t = document.createTextNode(
'Paragraph created by execution of iframe-onload event handler.');
var p = document.createElement('p');
p.setAttribute('id', 'pCreatedByIframeOnload');
p.appendChild(t);
iframeElem.appendChild(p);
}
</script>
</iframe>

<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 Expand Up @@ -186,7 +205,7 @@ <h2 id="userAgent"></h2>

<!-- test execution of main pages's body-onload tag functionality -->
<script>
bodyElem = document.getElementsByTagName('body')[0];
var bodyElem = document.getElementsByTagName('body')[0];
bodyElem.onload = function(){
var t = document.createTextNode(
'Look, a dynamically-generated paragraph!');
Expand Down
29 changes: 26 additions & 3 deletions test/unit/onload.js
Expand Up @@ -7,16 +7,39 @@
*/


module("window");
module("onload-events");

// depends on <script> block in test/index.html
test("Execution of body-onload in top-level document", function() {
test("Execution of body & iframe onload events in top-level document",
function() {

// top-level window-onload works, or test framework wouldn't run.....
expect(1);
expect(3);

var mtch = document.getElementById('pCreatedByBodyOnload').innerHTML.
match(/dynamically-generated paragraph/);
try{ ok(mtch && mtch.length > 0,
"Got confirmation that body-onload handler executed");
}catch(e){print(e);}

mtch = document.getElementById('pCreatedByIframeOnload').innerHTML.
match(/iframe-onload event handler/);
try{ ok(mtch && mtch.length > 0,
"Got confirmation that iframe-onload handler executed");
}catch(e){print(e);}

var iframe = document.getElementById('loadediframe');
var aCounter = 0;
iframe.onload = function(){
aCounter++;
}
iframe.src = "html/iframe.html";
try{ ok(aCounter == 1,
"iframe-onload handler executes when iframe.src assigned");
}catch(e){print(e);}
});


// still to test: onload events for: <frame>, <frameset>, <img>, <link>
// image, layer

0 comments on commit 918e093

Please sign in to comment.