r66985 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66984‎ | r66985 | r66986 >
Date:01:54, 28 May 2010
Author:dale
Status:deferred
Tags:
Comment:
added IE9 conditional to HTML5 tag support for IE
added flag to better test mobile safari
added checks for -static for static packaged version of mwEmbed mw.isStaticPackge() etc.
Modified paths:
  • /trunk/extensions/JS2Support/mwEmbed/mwEmbed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/mwEmbed/mwEmbed.js
@@ -1,6 +1,6 @@
22 // Add support for html5 / mwEmbed elements to IE ( comment must come before js code )
33 // For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
4 -/*@cc_on'video source itext playlist'.replace(/\w+/g,function(n){document.createElement(n)})@*/
 4+/*@cc_on@if(@_jscript_version<9){'video audio source itext playlist'.replace(/\w+/g,function(n){document.createElement(n)})}@end@*/
55
66 /**
77 * ~mwEmbed ~
@@ -53,7 +53,9 @@
5454 */
5555
5656 // Local scope configuration var:
57 - var mwConfig = { };
 57+ if( !mwConfig ){
 58+ var mwConfig = { };
 59+ }
5860
5961 // Local scope mwUserConfig var. Stores user configuration
6062 var mwUserConfig = { };
@@ -135,23 +137,19 @@
136138 var setupUserConfigFlag = false;
137139 mw.setupUserConfig = function( callback ) {
138140 if( setupUserConfigFlag ) {
139 - if( callback )
 141+ if( callback ) {
140142 callback();
 143+ }
141144 }
142145 // Do Setup user config:
143 - mw.load( [ '$j.cookie', 'JSON' ], function() {
 146+ mw.load( [ '$j.cookie', 'JSON' ], function() {
144147 if( $j.cookie( 'mwUserConfig' ) ) {
145148 mwUserConfig = JSON.parse( $j.cookie( 'mwUserConfig' ) );
146 - }
147 - mw.log( 'mw UserConfig: ' + $j.cookie( 'mwUserConfig' ) );
148 - for(var i in mwUserConfig ) {
149 - mw.log( 'i: ' + i + ' ' + mwUserConfig[ i ] ) ;
150 - }
151 - //debugger;
152 -
 149+ }
153150 setupUserConfigFlag = true;
154 - if( callback )
155 - callback();
 151+ if( callback ) {
 152+ callback();
 153+ }
156154 });
157155 }
158156
@@ -1076,9 +1074,15 @@
10771075 }
10781076
10791077 /**
 1078+ * Mobile Safari has special properties for html5 video::
 1079+ *
10801080 * NOTE: should be moved to browser detection script
10811081 */
1082 - mw.isMobileSafari = function(){
 1082+ mw.isMobileSafari = function() {
 1083+ // check mobile safari foce ( for debug )
 1084+ if( mw.getConfig( 'forceMobileSafari' ) ){
 1085+ return true;
 1086+ }
10831087 if ((navigator.userAgent.indexOf('iPhone') != -1) ||
10841088 (navigator.userAgent.indexOf('iPod') != -1) ||
10851089 (navigator.userAgent.indexOf('iPad') != -1)) {
@@ -1313,7 +1317,7 @@
13141318 * Runs all the queued functions
13151319 * called by mwEmbedSetup
13161320 */
1317 - mw.runReadyFunctions = function ( ) {
 1321+ mw.runReadyFunctions = function ( ) {
13181322 // Run all the queued functions:
13191323 while( mwOnLoadFunctions.length ) {
13201324 mwOnLoadFunctions.shift()();
@@ -1369,6 +1373,7 @@
13701374 //( will use XHR if on same domain )
13711375 if( mw.isset( 'window.jQuery' )
13721376 && mw.getConfig( 'debug' ) === false
 1377+ && $j
13731378 && !isCssFile )
13741379 {
13751380 $j.getScript( url, myCallback);
@@ -1432,7 +1437,7 @@
14331438 styleNode.appendChild( styleText );
14341439 }
14351440 var head = document.getElementsByTagName("head")[0];
1436 - head.appendChild( styleNode );
 1441+ head.appendChild( styleNode );
14371442 };
14381443
14391444 /**
@@ -1543,6 +1548,11 @@
15441549 mwpath = src.substr( 0, src.indexOf( 'jsScriptLoader.php' ) );
15451550 }
15461551
 1552+ // For static packages mwEmbed packages start with: "mwEmbed-"
 1553+ if( src.indexOf( 'mwEmbed-' ) !== -1 && src.indexOf( '-static' ) !== -1 ) {
 1554+ mwpath = src.substr( 0, src.indexOf( 'mwEmbed-' ) );
 1555+ }
 1556+
15471557 // Error out if we could not get the path:
15481558 if( mwpath === null ) {
15491559 mw.log( "Error could not get mwEmbed path " );
@@ -1653,21 +1663,23 @@
16541664 // Check for mwEmbed.js and/or script loader
16551665 var src = js_elements[i].getAttribute( "src" );
16561666 if ( src ) {
1657 - if (
 1667+ if ( // Check for mwEmbed.js ( debug mode )
16581668 ( src.indexOf( 'mwEmbed.js' ) !== -1 && src.indexOf( 'MediaWiki:Gadget') == -1 )
1659 - ||
 1669+ || // Check for script-loader
16601670 (
16611671 ( src.indexOf( 'mwScriptLoader.php' ) !== -1 || src.indexOf( 'jsScriptLoader.php' ) !== -1 )
16621672 &&
16631673 src.indexOf( 'mwEmbed' ) !== -1
1664 - )
 1674+ )
 1675+ || // Check for static mwEmbed package
 1676+ ( src.indexOf( 'mwEmbed' ) !== -1 && src.indexOf( 'static' ) !== -1 )
16651677 ) {
16661678 mwEmbedSrc = src;
16671679 return mwEmbedSrc;
16681680 }
16691681 }
16701682 }
1671 - mw.log( 'Error: getMwEmbedScriptURL failed to get script path' );
 1683+ mw.log( 'Error: getMwEmbedSrc failed to get script path' );
16721684 return false;
16731685 }
16741686
@@ -2018,10 +2030,30 @@
20192031 callback();
20202032 return ;
20212033 }
 2034+
 2035+ // Check if we are using a static package ( mwEmbed path includes -static )
 2036+ if( mw.isStaticPackge ){
 2037+ callback();
 2038+ return ;
 2039+ }
 2040+
20222041 // Add the Core loader to the request
20232042 // The follow code is ONLY RUN in debug / raw file mode
20242043 mw.load( 'loader.js', callback );
20252044 }
 2045+ /**
 2046+ * Checks if the javascript is a static package ( not using script-loader )
 2047+ * @return {boolean}
 2048+ * true the included script is static
 2049+ * false the included script
 2050+ */
 2051+ mw.isStaticPackge = function(){
 2052+ var src = mw.getMwEmbedSrc();
 2053+ if( src.indexOf('-static') !== -1 ){
 2054+ return true;
 2055+ }
 2056+ return false;
 2057+ }
20262058
20272059 /**
20282060 * Check for script-loader module loaders, and localization files
@@ -2032,9 +2064,10 @@
20332065 mw.checkModuleLoaderFiles = function( callback ) {
20342066 mw.log( 'doLoaderCheck::' );
20352067
2036 - // Check if we are using scriptloader ( handles loader include automatically )
2037 - if( mw.getScriptLoaderPath() ) {
2038 - callback();
 2068+ // Check if we are using scriptloader ( handles loader include automatically )
 2069+ // Or if mwEmbed is a static package ( all classes are already loaded )
 2070+ if( mw.getScriptLoaderPath() || mw.isStaticPackge() ) {
 2071+ callback();
20392072 return ;
20402073 }
20412074
@@ -2414,7 +2447,11 @@
24152448 mw.log( 'Error: jQuery is required for mwEmbed, please update your script-loader request' );
24162449 }
24172450
2418 -/*
 2451+if( mw.isStaticPackge() && !window.jQuery ){
 2452+ alert( 'Error: jQuery is required for mwEmbed ');
 2453+}
 2454+
 2455+/**
24192456 * Hack to keep jQuery in $ when its
24202457 * already there, but also use noConflict to get $j = jQuery
24212458 *

Status & tagging log