Skip to content

Commit

Permalink
fixed IE for both kaltura basic player and inline video tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dale committed Jun 7, 2012
1 parent ef0a1bc commit eb2b769
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
33 changes: 29 additions & 4 deletions modules/KalturaSupport/kalturaIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private function getVersionUrlParams(){
* Get the startup location
*/
private function getMwEmbedStartUpLocation(){
return $this->getMwEmbedPath() . 'mwEmbedStartup.php' . $this->getVersionUrlParams() ;
return $this->getMwEmbedPath() . 'mwEmbedStartup.php' . $this->getVersionUrlParams() . '&iframeStartup=1';
}
/**
* Get the location of the mwEmbed library
Expand Down Expand Up @@ -752,9 +752,6 @@ function getViewPortSize(){
echo $uiConfJs->getUserAgentPlayerRules();
?></script>

<!-- Include the mwEmbedStartup script, will initialize the resource loader -->
<script type="text/javascript" src="<?php echo $this->getMwEmbedStartUpLocation() ?>"></script>

<!-- Output any iframe based packaged data -->
<script type="text/javascript">
// Initialize the iframe with associated setup
Expand All @@ -778,10 +775,38 @@ function getViewPortSize(){
)
);
?>;
</script>
<!-- Include the mwEmbedStartup script, will initialize the resource loader -->
<script type="text/javascript" src="<?php echo $this->getMwEmbedStartUpLocation() ?>"></script>

<script type="text/javascript">
// IE9 has out of order, wait for mw:
var waitForMwCount = 0;
var waitforMw = function( callback ){
if( window['mw'] ){
// most borwsers will directly execute the callback:
callback();
return ;
}
setTimeout(function(){
waitForMwCount++;
if( waitForMwCount < 1000 ){
waitforMw( callback );
} else {
console.log("Error in loading mwEmbedLodaer");
}
}, 10 );
};

waitforMw( function(){
mw.loader.go();
mw.loader.load('mw.MwEmbedSupport');
<?php
echo $this->outputKalturaModules();
?>
});
</script>

</body>
</html>
<?php
Expand Down
61 changes: 38 additions & 23 deletions mwEmbedStartup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,42 @@
}

// Bootstrap some js code to make the "loader" work in stand alone mode
// Note this has to be wrapped in a document.write to run after other document.writes
?>
// IE9 has out of order, wait for mw:
var waitForMwCount = 0;
var waitforMw = function( callback ){
if( window['mw'] ){
// most borwsers will directly execute the callback:
callback();
return ;
}
setTimeout(function(){
waitForMwCount++;
if( waitForMwCount < 1000 ){
waitforMw( callback );
} else {
console.log("Error in loading mwEmbedLodaer");
// not need when iframe includes starup and sets iframeStartup flag
if( !isset( $_GET[ 'iframeStartup' ] ) ){
// Bootstrap some js code to make the "loader" work in stand alone mode
// Note this has to be wrapped in a document.write to run after other document.writes
$pageStartupScript = Html::inlineScript(
ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.go', array() )
)
);
echo Xml::encodeJsCall( 'document.write', array( $pageStartupScript ) );

?>
var waitForMwCount = 0;
var waitforMw = function( callback ){
if( window['mw'] ){
// most borwsers will directly execute the callback:
callback();
return ;
}
}, 10 );
};

waitforMw( function(){
mw.loader.go();
mw.loader.load('mw.MwEmbedSupport');
});
setTimeout(function(){
waitForMwCount++;
if( waitForMwCount < 1000 ){
waitforMw( callback );
} else {
console.log("Error in loading mwEmbedLodaer");
}
}, 10 );
};
<?php
// Load the core mw.MwEmbedSupport library
$pageMwEmbedScript = Html::inlineScript(
'waitforMw( function(){' .
ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.load', array( 'mw.MwEmbedSupport' ) )
) .
'});'
);
echo Xml::encodeJsCall( 'document.write', array( $pageMwEmbedScript ) );
}
5 changes: 4 additions & 1 deletion resources/mediawiki/mediawiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ var mw = ( function ( $, undefined ) {
*/
function addScript( src, callback, async ) {
var done = false, script, head;
if ( ready || async ) {
// IE has out of order execution issues with document.write in friendly iframes,
//always use async to add scripts.
if ( ready || async || $.browser.msie ) {
// jQuery's getScript method is NOT better than doing this the old-fashioned way
// because jQuery will eval the script's code, and errors will not have sane
// line numbers.
Expand Down Expand Up @@ -1478,6 +1480,7 @@ window.$j = jQuery;
// Attach to window and globally alias
window.mw = window.mediaWiki = mw;

mw.log( 'done parsing ' + window.mw );
// Auto-register from pre-loaded startup scripts
if ( jQuery.isFunction( window.startUp ) ) {
window.startUp();
Expand Down
6 changes: 4 additions & 2 deletions resources/mediawiki/mediawiki.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
// Try to use an existing console
if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
window.console.log( string );
} else {
}
// the injected log caused issues in IE iframes
/*else {
// Set timestamp
var d = new Date();
var time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
Expand Down Expand Up @@ -58,7 +60,7 @@
.text( string )
.append( '<span style="float:right">[' + time + ']</span>' )
);
}
} */
};

})(jQuery, mediaWiki);
5 changes: 3 additions & 2 deletions resources/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ var isCompatible = function() {
// TODO: Chrome < 1
return true;
};
// IE has issues with document write when in a friendly iframe,
// so we check and do a script append
var writeScript = function( scriptUrl ){
// IE has issues with document write when in a friendly iframe,
// so we check and do an async script append
if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1
&& parseFloat( navigator.appVersion.split( 'MSIE' )[1] ) >= 6 )
{
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.type = 'text/javascript';
script.defer = 'defer';
script.src = scriptUrl;
head.appendChild( script );
} else {
Expand Down

0 comments on commit eb2b769

Please sign in to comment.