Skip to content

Commit

Permalink
MDL-17702 when embedding documents in ie, use iframe for ie and objec…
Browse files Browse the repository at this point in the history
…t for others, because forms cannot escape from objcet in ie
  • Loading branch information
Gordon Bateson committed May 14, 2010
1 parent 0dd4fc0 commit d1174b1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 32 deletions.
53 changes: 36 additions & 17 deletions mod/hotpot/iframe.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,26 +32,45 @@ function getElement(id, lyr) {
var obj = (document.layers) ? eval("d."+id) : (d.all) ? d.all[id] : (d.getElementById) ? d.getElementById(id) : null; var obj = (document.layers) ? eval("d."+id) : (d.all) ? d.all[id] : (d.getElementById) ? d.getElementById(id) : null;
return obj; return obj;
} }
function set_object_height(myObject) { function set_embed_object_height(evt, embed_object) {
if (myObject) { if (typeof(embed_object)=='undefined') {
if (document.frames) { if (evt) {
var obj = myObject; // IE - obj is alaredy a document element // we are being called by the onload event handler
} else { if (evt.target) { // most browsers
var obj = myObject.document || myObject.contentDocument || null; // IE || FireFox embed_object = evt.target;
} } else if (evt.srcElement) { // IE
if (obj) { embed_object = evt.srcElement;
if (obj.body) {
obj = obj.body;
}
var h = getContentH(obj);
if (h) {
setSize(myObject, 0, h + 65);
} }
if (document.all) { }
myObject.allowTransparency = true; }
obj.style.backgroundColor = 'transparent'; var obj = null;
if (embed_object) {
if (document.frames) { // IE
switch (embed_object.tagName) {
case 'IFRAME':
obj = document.frames[embed_object.name].document;
break;
case 'OBJECT':
obj = embed_object; // already an HTML document element
break;
} }
} else { // Firefox, Safari, Opera, Chrome
obj = embed_object.document || embed_object.contentDocument || null;
}
}
if (obj) {
if (obj.body) {
obj = obj.body;
}
var h = getContentH(obj);
if (h) {
setSize(embed_object, 0, h + 65);
} }
// at some point the next two lines were important, but now it doesn't seeme to matter ?!
// if (document.all) {
// embed_object.allowTransparency = true;
// obj.style.backgroundColor = 'transparent';
// }
} }
} }
is = new domSniffer(); is = new domSniffer();
48 changes: 33 additions & 15 deletions mod/hotpot/view.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -460,13 +460,17 @@
switch ($framename) { switch ($framename) {
case 'main': case 'main':
print $hp->html; print $hp->html;
break; break;
default: default:
// set iframe attributes // set iframe attributes
$iframe_id = 'hotpot_iframe'; $iframe_id = 'hotpot_embed_object';
$iframe_name = 'hotpot_embed_iframe';
$iframe_width = '100%';
$iframe_height = '100%';
$iframe_src = $CFG->wwwroot.'/mod/hotpot/view.php?id='.$cm->id.'&framename=main'; $iframe_src = $CFG->wwwroot.'/mod/hotpot/view.php?id='.$cm->id.'&framename=main';
$iframe_onload_function = 'set_object_height'; $iframe_onload_function = 'set_embed_object_height';
$iframe_js = '<script src="'.$CFG->wwwroot.'/mod/hotpot/iframe.js" type="text/javascript"></script>'."\n"; $iframe_js = '<script src="'.$CFG->wwwroot.'/mod/hotpot/iframe.js" type="text/javascript"></script>'."\n";

print_header( print_header(
$title, $heading, $navigation, $title, $heading, $navigation,
"", $head.$styles.$scripts.$iframe_js, true, $button, "", $head.$styles.$scripts.$iframe_js, true, $button,
Expand All @@ -476,21 +480,35 @@
notify($available_msg); notify($available_msg);
} }


// the object to hold the embedded html page // for XHTML 1.0 Strict compatability, the embedded page should be implemented
print '<object id="'.$iframe_id.'" type="text/html" data="'.$iframe_src.'" width="100%" height="100%" onload="'.$iframe_onload_function.'(this)"></object>'."\n"; // using an <object> not an <iframe>. However, IE <object>'s are problematic
// (links and forms cannot escape), so we use conditional comments to display
// an <iframe> in IE and an <object> in other browsers

// print the html element to hold the embedded html page
// Note: the iframe in IE needs a "name" attribute for the resizing to work
print '<!--[if IE]>'."\n";
print '<iframe name="'.$iframe_name.'" id="'.$iframe_id.'" src="'.$iframe_src.'" width="'.$iframe_width.'" height="'.$iframe_height.'"></iframe>'."\n";
print '<![endif]-->'."\n";
print '<!--[if !IE]> <-->'."\n";
print '<object id="'.$iframe_id.'" type="text/html" data="'.$iframe_src.'" width="'.$iframe_width.'" height="'.$iframe_height.'"></object>'."\n";
print '<!--> <![endif]-->'."\n";


// javascript to simulate object onload event in IE (thanks to David Horat !) // print javascript to add onload event handler - we do this here because
// an object tag should have no onload attribute in XHTML 1.0 Strict
print '<script type="text/javascript">'."\n"; print '<script type="text/javascript">'."\n";
print '//<![CDATA['."\n"; print '//<![CDATA['."\n";
print 'function ieOnload(id, fn) {'."\n"; print "var obj = document.getElementById('$iframe_id');\n";
print ' if (document.all[id].readyState==4) {'."\n"; print "if (obj) {\n";
print ' clearInterval(ieOnloadInterval);'."\n"; print " if (obj.addEventListener) {\n";
print ' fn(document.all[id]);'."\n"; print " obj.addEventListener('load', $iframe_onload_function, false);\n";
print ' }'."\n"; print " } else if (obj.attachEvent) {\n";
print '}'."\n"; print " obj.attachEvent('onload', $iframe_onload_function);\n";
print 'if (document.all) {'."\n"; print " } else {\n";
print ' var ieOnloadInterval = setInterval("ieOnload('."'$iframe_id',$iframe_onload_function".')", 100);'."\n"; print " obj['onload'] = $iframe_onload_function;\n";
print '}'."\n"; print " }\n";
print "}\n";
print "obj = null;\n";
print '//]]>'."\n"; print '//]]>'."\n";
print '</script>'."\n"; print '</script>'."\n";


Expand Down

0 comments on commit d1174b1

Please sign in to comment.