Skip to content

Commit

Permalink
restructured load sequence to work with IE, but still is broken.
Browse files Browse the repository at this point in the history
-- somehow loading a susquent script purges the mw global.
  • Loading branch information
mdale committed Jun 7, 2012
1 parent 6b520e4 commit ef0a1bc
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 35 deletions.
7 changes: 0 additions & 7 deletions includes/MwEmbedResourceLoaderStartUpModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ public function getFileDependencies( $skin ) {
return array();
}

public function getScript( ResourceLoaderContext $context ) {
$out = parent::getScript( $context );
// Append mediaWiki.loader.go() for stand alone context:
$out.= Xml::encodeJsCall( 'document.write', array( Html::inlineScript( "mediaWiki.loader.go();" ) ) );
return $out;
}

protected function getConfig( $context ) {
global $wgLoadScript;

Expand Down
3 changes: 1 addition & 2 deletions includes/resourceloader/ResourceLoaderStartUpModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ public function getScript( ResourceLoaderContext $context ) {
"};\n";

// Conditional script injection
$scriptTag = Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) );
$out .= "if ( isCompatible() ) {\n" .
"\t" . Xml::encodeJsCall( 'document.write', array( $scriptTag ) ) .
"\t" . Xml::encodeJsCall( 'writeScript', array( $wgLoadScript . '?' . wfArrayToCGI( $query ) ) ) .
"}\n" .
"delete isCompatible;";
}
Expand Down
14 changes: 6 additions & 8 deletions modules/KalturaSupport/kalturaIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,9 @@ function outputKalturaModules(){
};

// Load all the known required libraries:
return Html::inlineScript(
ResourceLoader::makeLoaderConditionalScript(
return ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.load', array( $moduleList ) )
)
);
);
}

function outputIFrame( ){
Expand Down Expand Up @@ -761,7 +759,7 @@ function getViewPortSize(){
<script type="text/javascript">
// Initialize the iframe with associated setup
window.kalturaIframePackageData = <?php
echo json_encode(
echo json_encode(
array(
// The base player config controls most aspects of player display and sources
'playerConfig' => $this->getResultObject()->getPlayerConfig(),
Expand All @@ -780,10 +778,10 @@ function getViewPortSize(){
)
);
?>;
<?php
echo $this->outputKalturaModules();
?>
</script>
<?php
echo $this->outputKalturaModules();
?>
</body>
</html>
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
mw.log('Error: rewrite object is not supported');
return ;
}
// Setup required properties ( json_encode the string for safe javascript pasing )
var flashEmbedHTML = playerData['flashHTML'];

// Setup player
var playerConfig = mw.config.get( 'KalturaSupport.PlayerConfig' );
var playerId = mw.config.get( 'EmbedPlayer.IframeParentPlayerId');
Expand Down Expand Up @@ -126,7 +123,7 @@
// part of the javascript check kIsHTML5FallForward )
removeElement( 'videoContainer' );
// Write out the embed object
document.write( flashEmbedHTML );
document.write( playerData['flashHTML'] );
}


Expand Down
35 changes: 22 additions & 13 deletions mwEmbedStartup.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@

// 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 ) );
?>
// 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 );
};

// Load the core mw.MwEmbedSupport library
$pageMwEmbedScript = Html::inlineScript(
ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.load', array( 'mw.MwEmbedSupport' ) )
)
);
echo Xml::encodeJsCall( 'document.write', array( $pageMwEmbedScript ) );
waitforMw( function(){
mw.loader.go();
mw.loader.load('mw.MwEmbedSupport');
});
1 change: 0 additions & 1 deletion resources/mediawiki/mediawiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/*
* Core MediaWiki JavaScript Library
*/

var mw = ( function ( $, undefined ) {
"use strict";

Expand Down
15 changes: 15 additions & 0 deletions resources/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ 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 ){
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.src = scriptUrl;
head.appendChild( script );
} else {
document.write( '<script src=\"' + scriptUrl + '" type="text/javascript" ></script>' );
}
}
/**
* The startUp() function will be generated and added here (at the bottom)
*/

0 comments on commit ef0a1bc

Please sign in to comment.