Index: trunk/extensions/JS2Support/mwEmbed/mwEmbed.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | // Add support for html5 / mwEmbed elements to IE ( comment must come before js code ) |
3 | 3 | // 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@*/ |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * ~mwEmbed ~ |
— | — | @@ -53,7 +53,9 @@ |
54 | 54 | */ |
55 | 55 | |
56 | 56 | // Local scope configuration var: |
57 | | - var mwConfig = { }; |
| 57 | + if( !mwConfig ){ |
| 58 | + var mwConfig = { }; |
| 59 | + } |
58 | 60 | |
59 | 61 | // Local scope mwUserConfig var. Stores user configuration |
60 | 62 | var mwUserConfig = { }; |
— | — | @@ -135,23 +137,19 @@ |
136 | 138 | var setupUserConfigFlag = false; |
137 | 139 | mw.setupUserConfig = function( callback ) { |
138 | 140 | if( setupUserConfigFlag ) { |
139 | | - if( callback ) |
| 141 | + if( callback ) { |
140 | 142 | callback(); |
| 143 | + } |
141 | 144 | } |
142 | 145 | // Do Setup user config: |
143 | | - mw.load( [ '$j.cookie', 'JSON' ], function() { |
| 146 | + mw.load( [ '$j.cookie', 'JSON' ], function() { |
144 | 147 | if( $j.cookie( 'mwUserConfig' ) ) { |
145 | 148 | 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 | + } |
153 | 150 | setupUserConfigFlag = true; |
154 | | - if( callback ) |
155 | | - callback(); |
| 151 | + if( callback ) { |
| 152 | + callback(); |
| 153 | + } |
156 | 154 | }); |
157 | 155 | } |
158 | 156 | |
— | — | @@ -1076,9 +1074,15 @@ |
1077 | 1075 | } |
1078 | 1076 | |
1079 | 1077 | /** |
| 1078 | + * Mobile Safari has special properties for html5 video:: |
| 1079 | + * |
1080 | 1080 | * NOTE: should be moved to browser detection script |
1081 | 1081 | */ |
1082 | | - mw.isMobileSafari = function(){ |
| 1082 | + mw.isMobileSafari = function() { |
| 1083 | + // check mobile safari foce ( for debug ) |
| 1084 | + if( mw.getConfig( 'forceMobileSafari' ) ){ |
| 1085 | + return true; |
| 1086 | + } |
1083 | 1087 | if ((navigator.userAgent.indexOf('iPhone') != -1) || |
1084 | 1088 | (navigator.userAgent.indexOf('iPod') != -1) || |
1085 | 1089 | (navigator.userAgent.indexOf('iPad') != -1)) { |
— | — | @@ -1313,7 +1317,7 @@ |
1314 | 1318 | * Runs all the queued functions |
1315 | 1319 | * called by mwEmbedSetup |
1316 | 1320 | */ |
1317 | | - mw.runReadyFunctions = function ( ) { |
| 1321 | + mw.runReadyFunctions = function ( ) { |
1318 | 1322 | // Run all the queued functions: |
1319 | 1323 | while( mwOnLoadFunctions.length ) { |
1320 | 1324 | mwOnLoadFunctions.shift()(); |
— | — | @@ -1369,6 +1373,7 @@ |
1370 | 1374 | //( will use XHR if on same domain ) |
1371 | 1375 | if( mw.isset( 'window.jQuery' ) |
1372 | 1376 | && mw.getConfig( 'debug' ) === false |
| 1377 | + && $j |
1373 | 1378 | && !isCssFile ) |
1374 | 1379 | { |
1375 | 1380 | $j.getScript( url, myCallback); |
— | — | @@ -1432,7 +1437,7 @@ |
1433 | 1438 | styleNode.appendChild( styleText ); |
1434 | 1439 | } |
1435 | 1440 | var head = document.getElementsByTagName("head")[0]; |
1436 | | - head.appendChild( styleNode ); |
| 1441 | + head.appendChild( styleNode ); |
1437 | 1442 | }; |
1438 | 1443 | |
1439 | 1444 | /** |
— | — | @@ -1543,6 +1548,11 @@ |
1544 | 1549 | mwpath = src.substr( 0, src.indexOf( 'jsScriptLoader.php' ) ); |
1545 | 1550 | } |
1546 | 1551 | |
| 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 | + |
1547 | 1557 | // Error out if we could not get the path: |
1548 | 1558 | if( mwpath === null ) { |
1549 | 1559 | mw.log( "Error could not get mwEmbed path " ); |
— | — | @@ -1653,21 +1663,23 @@ |
1654 | 1664 | // Check for mwEmbed.js and/or script loader |
1655 | 1665 | var src = js_elements[i].getAttribute( "src" ); |
1656 | 1666 | if ( src ) { |
1657 | | - if ( |
| 1667 | + if ( // Check for mwEmbed.js ( debug mode ) |
1658 | 1668 | ( src.indexOf( 'mwEmbed.js' ) !== -1 && src.indexOf( 'MediaWiki:Gadget') == -1 ) |
1659 | | - || |
| 1669 | + || // Check for script-loader |
1660 | 1670 | ( |
1661 | 1671 | ( src.indexOf( 'mwScriptLoader.php' ) !== -1 || src.indexOf( 'jsScriptLoader.php' ) !== -1 ) |
1662 | 1672 | && |
1663 | 1673 | src.indexOf( 'mwEmbed' ) !== -1 |
1664 | | - ) |
| 1674 | + ) |
| 1675 | + || // Check for static mwEmbed package |
| 1676 | + ( src.indexOf( 'mwEmbed' ) !== -1 && src.indexOf( 'static' ) !== -1 ) |
1665 | 1677 | ) { |
1666 | 1678 | mwEmbedSrc = src; |
1667 | 1679 | return mwEmbedSrc; |
1668 | 1680 | } |
1669 | 1681 | } |
1670 | 1682 | } |
1671 | | - mw.log( 'Error: getMwEmbedScriptURL failed to get script path' ); |
| 1683 | + mw.log( 'Error: getMwEmbedSrc failed to get script path' ); |
1672 | 1684 | return false; |
1673 | 1685 | } |
1674 | 1686 | |
— | — | @@ -2018,10 +2030,30 @@ |
2019 | 2031 | callback(); |
2020 | 2032 | return ; |
2021 | 2033 | } |
| 2034 | + |
| 2035 | + // Check if we are using a static package ( mwEmbed path includes -static ) |
| 2036 | + if( mw.isStaticPackge ){ |
| 2037 | + callback(); |
| 2038 | + return ; |
| 2039 | + } |
| 2040 | + |
2022 | 2041 | // Add the Core loader to the request |
2023 | 2042 | // The follow code is ONLY RUN in debug / raw file mode |
2024 | 2043 | mw.load( 'loader.js', callback ); |
2025 | 2044 | } |
| 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 | + } |
2026 | 2058 | |
2027 | 2059 | /** |
2028 | 2060 | * Check for script-loader module loaders, and localization files |
— | — | @@ -2032,9 +2064,10 @@ |
2033 | 2065 | mw.checkModuleLoaderFiles = function( callback ) { |
2034 | 2066 | mw.log( 'doLoaderCheck::' ); |
2035 | 2067 | |
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(); |
2039 | 2072 | return ; |
2040 | 2073 | } |
2041 | 2074 | |
— | — | @@ -2414,7 +2447,11 @@ |
2415 | 2448 | mw.log( 'Error: jQuery is required for mwEmbed, please update your script-loader request' ); |
2416 | 2449 | } |
2417 | 2450 | |
2418 | | -/* |
| 2451 | +if( mw.isStaticPackge() && !window.jQuery ){ |
| 2452 | + alert( 'Error: jQuery is required for mwEmbed '); |
| 2453 | +} |
| 2454 | + |
| 2455 | +/** |
2419 | 2456 | * Hack to keep jQuery in $ when its |
2420 | 2457 | * already there, but also use noConflict to get $j = jQuery |
2421 | 2458 | * |