Index: branches/MwEmbedStandAlone/mwEmbed.js |
— | — | @@ -281,9 +281,15 @@ |
282 | 282 | * @key Name of resource |
283 | 283 | * @value Class file path |
284 | 284 | */ |
285 | | - resourcePaths : { }, |
| 285 | + resourcePaths : { }, |
286 | 286 | |
287 | 287 | /** |
| 288 | + * Stores resources that have been requested ( to avoid re-requesting the same resources ) |
| 289 | + * in concurrent requests ) |
| 290 | + */ |
| 291 | + requestedResourceQueue: { }, |
| 292 | + |
| 293 | + /** |
288 | 294 | * javascript Resource Paths |
289 | 295 | * |
290 | 296 | * @key Name of resource |
— | — | @@ -324,6 +330,7 @@ |
325 | 331 | */ |
326 | 332 | load: function( loadRequest, instanceCallback ) { |
327 | 333 | // mw.log("mw.load:: " + loadRequest ); |
| 334 | + var _this = this; |
328 | 335 | |
329 | 336 | // Throw out any loadRequests that are not strings |
330 | 337 | loadRequest = this.cleanLoadRequest( loadRequest ); |
— | — | @@ -366,7 +373,7 @@ |
367 | 374 | if( !resourceSet ){ |
368 | 375 | mw.log( "mw.load:: Error with module loader: " + loadRequest + ' ( no resource set defined )' ); |
369 | 376 | return ; |
370 | | - } |
| 377 | + } |
371 | 378 | |
372 | 379 | // xxx should use refactor "ready" stuff into a "domReady" class |
373 | 380 | // So we would not have local scope globals like this: |
— | — | @@ -375,7 +382,7 @@ |
376 | 383 | // mw.ready has run |
377 | 384 | this.load( resourceSet, callback ); |
378 | 385 | } else { |
379 | | - this.addToModuleLoaderQueue( |
| 386 | + this.addToModuleLoaderQueue( |
380 | 387 | loadRequest, |
381 | 388 | resourceSet, |
382 | 389 | callback |
— | — | @@ -391,11 +398,27 @@ |
392 | 399 | } |
393 | 400 | |
394 | 401 | // Try loading as a "file" or via ScriptLoader |
395 | | - if( loadRequest ) { |
| 402 | + if( loadRequest ) { |
| 403 | + // Check if this resource was already requested |
| 404 | + if( typeof this.requestedResourceQueue[ loadRequest ] == 'object' ){ |
| 405 | + this.requestedResourceQueue[ loadRequest ].push( callback ); |
| 406 | + return ; |
| 407 | + } else { |
| 408 | + this.requestedResourceQueue[ loadRequest ] = []; |
| 409 | + } |
| 410 | + |
396 | 411 | if( loadRequest.indexOf( '.js' ) == -1 && !mw.getResourceLoaderPath() ) { |
397 | 412 | mw.log( 'Error: are you sure ' + loadRequest + ' is a file ( is it missing a resource path? ) ' ); |
398 | 413 | } |
399 | | - mw.getScript( loadRequest, callback ); |
| 414 | + mw.getScript( loadRequest, function(){ |
| 415 | + // Check if we have requestedResources queue items: |
| 416 | + while( _this.requestedResourceQueue[ loadRequest ].length ){ |
| 417 | + _this.requestedResourceQueue[ loadRequest ].shift()( loadRequest ); |
| 418 | + } |
| 419 | + callback( loadRequest ); |
| 420 | + // empty the load request queue: |
| 421 | + _this.requestedResourceQueue[ loadRequest ] = []; |
| 422 | + }); |
400 | 423 | return ; |
401 | 424 | } |
402 | 425 | |
— | — | @@ -475,12 +498,12 @@ |
476 | 499 | } |
477 | 500 | |
478 | 501 | // We are infact loading many: |
479 | | - mw.log("mw.load: LoadMany:: " + loadSet ); |
| 502 | + //mw.log("mw.load: LoadMany:: " + loadSet ); |
480 | 503 | |
481 | 504 | // Issue the load request check check loadStates to see if we are |
482 | 505 | // "done" |
483 | 506 | for( var loadName in loadStates ) { |
484 | | - // mw.log("loadMany: load: " + loadName ); |
| 507 | + mw.log("loadMany: load: " + loadName ); |
485 | 508 | this.load( loadName, function ( loadName ) { |
486 | 509 | loadStates[ loadName ] = 1; |
487 | 510 | |
— | — | @@ -533,20 +556,19 @@ |
534 | 557 | // Setup grouped loadStates Set: |
535 | 558 | var groupClassKey = ''; |
536 | 559 | var coma = ''; |
| 560 | + var uniqueResourceName = {}; |
537 | 561 | for( var i=0; i < groupedLoadSet.length; i++ ) { |
538 | | - var loadName = groupedLoadSet[ i ]; |
539 | | - |
540 | | - |
| 562 | + var loadName = groupedLoadSet[ i ]; |
541 | 563 | if( this.getResourcePath( loadName ) ) { |
542 | | - // Only add to group request if not already set: |
543 | | - if ( !mw.isset( loadName ) ) { |
| 564 | + // Check if not already in request queue and not defined in global namespace |
| 565 | + if( !mw.isset( loadName ) && ! uniqueResourceName[ loadName] ){ |
544 | 566 | groupClassKey += coma + loadName |
545 | 567 | coma = ','; |
546 | 568 | |
547 | 569 | // Check for style sheet dependencies |
548 | 570 | if( this.resourceStyleDependency[ loadName ] ){ |
549 | 571 | groupClassKey += coma + this.resourceStyleDependency[ loadName ]; |
550 | | - } |
| 572 | + } |
551 | 573 | } |
552 | 574 | } else if ( this.moduleLoaders[ loadName ] ) { |
553 | 575 | |
— | — | @@ -556,9 +578,12 @@ |
557 | 579 | loadStates[ groupClassKey ] = 0; |
558 | 580 | groupClassKey = coma = ''; |
559 | 581 | } |
560 | | - // Add the module to the loadSate |
561 | | - loadStates[ loadName ] = 0; |
| 582 | + if( ! uniqueResourceName[ loadName] ){ |
| 583 | + // Add the module to the loadSate |
| 584 | + loadStates[ loadName ] = 0; |
| 585 | + } |
562 | 586 | } |
| 587 | + uniqueResourceName[ loadName] = true; |
563 | 588 | } |
564 | 589 | |
565 | 590 | // Add groupClassKey if set: |
— | — | @@ -1324,7 +1349,7 @@ |
1325 | 1350 | var isCssFile = ( ext == '.css') ? true : false ; |
1326 | 1351 | |
1327 | 1352 | if( scriptLoaderPath && isResourceName ) { |
1328 | | - url = scriptLoaderPath + '?class=' + scriptRequest; |
| 1353 | + url = scriptLoaderPath + '?class=' + scriptRequest ; |
1329 | 1354 | } else { |
1330 | 1355 | // Add the mwEmbed path if a relative path request |
1331 | 1356 | url = ( isResourceName ) ? mw.getMwEmbedPath() : ''; |
— | — | @@ -1377,7 +1402,7 @@ |
1378 | 1403 | // mw.log(" append script: " + script.src ); |
1379 | 1404 | // Append the script to the DOM: |
1380 | 1405 | head.appendChild( script ); |
1381 | | - }; |
| 1406 | + }; |
1382 | 1407 | |
1383 | 1408 | /** |
1384 | 1409 | * Add a style sheet string to the document head |
— | — | @@ -2219,7 +2244,7 @@ |
2220 | 2245 | callback(); |
2221 | 2246 | return ; |
2222 | 2247 | } |
2223 | | - var callbackSet = $j( targetObject ).data( 'events' )[ triggerName ]; |
| 2248 | + var callbackSet = $j( targetObject ).data( 'events' )[ triggerName ]; |
2224 | 2249 | if( !callbackSet || callbackSet.length === 0 ){ |
2225 | 2250 | mw.log( ' No events run the callback directly: ' + triggerName ); |
2226 | 2251 | // No events run the callback directly |
— | — | @@ -2231,9 +2256,10 @@ |
2232 | 2257 | |
2233 | 2258 | mw.log(" runTriggersCallback:: " + callbackCount ); |
2234 | 2259 | var callInx = 0; |
2235 | | - $j( targetObject ).trigger( triggerName, function() { |
| 2260 | + $j( targetObject ).trigger( triggerName, function() { |
2236 | 2261 | callInx++; |
2237 | | - if( callInx == callbackCount ){ |
| 2262 | + if( callInx == callbackCount ){ |
| 2263 | + mw.log(" callbackCountReached run:: " + callback); |
2238 | 2264 | // Run callback |
2239 | 2265 | callback(); |
2240 | 2266 | } |
— | — | @@ -2522,6 +2548,10 @@ |
2523 | 2549 | */ |
2524 | 2550 | |
2525 | 2551 | if( window.jQuery ){ |
| 2552 | + if( ! mw.versionIsAtLeast( '1.4.0', jQuery.fn.jquery ) ){ |
| 2553 | + if( console.log ) |
| 2554 | + console.log( 'Error mwEmbed requires jQuery 1.4 or above' ); |
| 2555 | + } |
2526 | 2556 | var dollarFlag = false; |
2527 | 2557 | if( $ && $.fn && $.fn.jquery ) { |
2528 | 2558 | // NOTE we could check the version of |
Index: branches/MwEmbedStandAlone/ResourceLoader.php |
— | — | @@ -862,32 +862,32 @@ |
863 | 863 | static function removeLogStatements( $jsString ){ |
864 | 864 | $outputJs = ''; |
865 | 865 | for ( $i = 0; $i < strlen( $jsString ); $i++ ) { |
866 | | - // find next occurance of |
867 | | - preg_match( '/[\n;]\s*mw\.log\s*/', $jsString, $matches, PREG_OFFSET_CAPTURE, $i ); |
868 | | - // check if any matches are left: |
| 866 | + // find next occurrence of |
| 867 | + preg_match( '/([\n;]\s*mw\.log\s*)\(/', $jsString, $matches, PREG_OFFSET_CAPTURE, $i ); |
| 868 | + // check if any matches are left: |
869 | 869 | if( count( $matches ) == 0){ |
870 | 870 | $outputJs .= substr( $jsString, $i ); |
871 | 871 | break; |
872 | 872 | } |
873 | | - if( count( $matches ) > 0 ){ |
874 | | - $startOfLogIndex = strlen( $matches[0][0] ) + $matches[0][1]; |
875 | | - // append everytnig up to this point: |
876 | | - $outputJs .= substr( $jsString, $i, ( $startOfLogIndex - strlen( $matches[0][0] ) )-$i ); |
877 | | - |
878 | | - // Increment i to position of closing ) not inside quotes |
879 | | - $parenthesesDepth = 0; |
| 873 | + if( count( $matches ) > 0 ){ |
| 874 | + $startOfLogIndex = strlen( $matches[1][0] ) + $matches[1][1]; |
| 875 | + // append everything up to this point: |
| 876 | + $outputJs .= substr( $jsString, $i, ( $startOfLogIndex - strlen( $matches[1][0] ) )-$i ); |
| 877 | + |
| 878 | + // Increment i to position of closing ) not inside quotes |
| 879 | + $parenthesesDepth = 0; |
880 | 880 | $ignorenext = false; |
881 | 881 | $inquote = false; |
882 | 882 | $inSingleQuote = false; |
883 | | - for ( $i = $startOfLogIndex; $i < strlen( $jsString ); $i++ ) { |
| 883 | + for ( $i = $startOfLogIndex; $i < strlen( $jsString ); $i++ ) { |
884 | 884 | $char = $jsString[$i]; |
885 | 885 | if ( $ignorenext ) { |
886 | 886 | $ignorenext = false; |
887 | 887 | } else { |
888 | | - // Search for a close ) that is not in quotes |
| 888 | + // Search for a close ) that is not in quotes |
889 | 889 | switch( $char ) { |
890 | 890 | case '"': |
891 | | - if( !$inSingleQuote ){ |
| 891 | + if( !$inSingleQuote ){ |
892 | 892 | $inquote = !$inquote; |
893 | 893 | } |
894 | 894 | break; |
— | — | @@ -897,13 +897,13 @@ |
898 | 898 | } |
899 | 899 | break; |
900 | 900 | case '(': |
901 | | - if( !$inquote && !$inSingleQuote ){ |
| 901 | + if( !$inquote && !$inSingleQuote ){ |
902 | 902 | $parenthesesDepth++; |
903 | | - } |
904 | | - break; |
| 903 | + } |
| 904 | + break; |
905 | 905 | case ')': |
906 | | - if( ! $inquote && !$inSingleQuote ){ |
907 | | - $parenthesesDepth--; |
| 906 | + if( ! $inquote && !$inSingleQuote ){ |
| 907 | + $parenthesesDepth--; |
908 | 908 | } |
909 | 909 | break; |
910 | 910 | case '\\': |
— | — | @@ -912,18 +912,19 @@ |
913 | 913 | } |
914 | 914 | // Done with close parentheses search for next mw.log in outer loop: |
915 | 915 | if( $parenthesesDepth === 0 ){ |
916 | | - break; |
917 | | - } |
| 916 | + break; |
| 917 | + } |
918 | 918 | } |
919 | 919 | } |
920 | 920 | } |
921 | | - } |
| 921 | + } |
922 | 922 | return $outputJs; |
923 | 923 | } |
924 | 924 | /* simple function to return addMessageJs without preg_replace back reference substitution */ |
925 | 925 | private static function preg_addMessageJs(){ |
926 | 926 | return self::$addMessageJs; |
927 | 927 | } |
| 928 | + |
928 | 929 | /** |
929 | 930 | * Get the "addMesseges" function index ( for replacing msg text with localized json ) |
930 | 931 | * |
Index: branches/MwEmbedStandAlone/modules/EmbedPlayer/mw.EmbedPlayer.js |
— | — | @@ -188,6 +188,7 @@ |
189 | 189 | "type" : null |
190 | 190 | }); |
191 | 191 | |
| 192 | + |
192 | 193 | /** |
193 | 194 | * The base source attribute checks |
194 | 195 | * also see: http://dev.w3.org/html5/spec/Overview.html#the-source-element |
— | — | @@ -269,6 +270,7 @@ |
270 | 271 | * |
271 | 272 | */ |
272 | 273 | $.fn.embedPlayer = function( attributes, callback ) { |
| 274 | + mw.log( 'EmbedPlayer:: fn.embedPlayer' ); |
273 | 275 | var playerSelect = this.selector; |
274 | 276 | |
275 | 277 | // Define attributes if unset |
— | — | @@ -434,10 +436,11 @@ |
435 | 437 | // Update the list of dependent libraries for the player |
436 | 438 | // ( allows extensions to add to the dependency list ) |
437 | 439 | mw.embedPlayerUpdateLibraryRequest( playerElement, playerDependencyRequest ); |
438 | | - |
| 440 | + |
439 | 441 | // Load any skins we need then swap in the interface |
440 | | - mw.load( playerDependencyRequest, function() { |
441 | | - var waitForMeta = true; |
| 442 | + mw.load( playerDependencyRequest, function() { |
| 443 | + var waitForMeta = true; |
| 444 | + |
442 | 445 | // Be sure to "stop" the target ( sometimes firefox keeps playing the video even |
443 | 446 | // though its been removed from the DOM ) |
444 | 447 | if( playerElement.pause ){ |
— | — | @@ -450,9 +453,9 @@ |
451 | 454 | var eventObject = { |
452 | 455 | 'playerElement':playerElement, |
453 | 456 | 'waitForMeta' : waitForMeta |
454 | | - } |
| 457 | + }; |
| 458 | + $j( mw ).trigger( 'addElementWaitForMetaEvent', eventObject ); |
455 | 459 | |
456 | | - $j( mw ).trigger( 'addElementWaitForMetaEvent', eventObject ); |
457 | 460 | // update the waitForMeta |
458 | 461 | waitForMeta = eventObject[ 'waitForMeta' ]; |
459 | 462 | |
— | — | @@ -495,7 +498,7 @@ |
496 | 499 | playerElement.removeEventListener( "loadedmetadata", runPlayerSwap, true ); |
497 | 500 | playerElement.addEventListener( "loadedmetadata", runPlayerSwap, true ); |
498 | 501 | |
499 | | - // Time-out of 5 seconds ( maybe still playable but no timely metadata ) |
| 502 | + // Time-out of 5 seconds ( maybe still playable but no timely metadata ) |
500 | 503 | setTimeout( runPlayerSwap, 5000 ); |
501 | 504 | return ; |
502 | 505 | } else { |
— | — | @@ -1030,6 +1033,7 @@ |
1031 | 1034 | if ( $j( videoElement ).attr( "src" ) ) { |
1032 | 1035 | _this.tryAddSource( videoElement ); |
1033 | 1036 | } |
| 1037 | + |
1034 | 1038 | // Process elements source children |
1035 | 1039 | $j( videoElement ).find( 'source,track' ).each( function( ) { |
1036 | 1040 | _this.tryAddSource( this ); |
— | — | @@ -1124,7 +1128,7 @@ |
1125 | 1129 | * Selects the default source via cookie preference, default marked, or by id order |
1126 | 1130 | */ |
1127 | 1131 | autoSelectSource: function() { |
1128 | | - mw.log( 'EmbedPlayer::mediaElement::autoSelectSource:' ); |
| 1132 | + mw.log( 'EmbedPlayer::mediaElement::autoSelectSource:' + this.id); |
1129 | 1133 | // Select the default source |
1130 | 1134 | var playableSources = this.getPlayableSources(); |
1131 | 1135 | var flash_flag = ogg_flag = false; |
— | — | @@ -1610,7 +1614,7 @@ |
1611 | 1615 | // Scope the end of check for player sources so it can be called in a callback |
1612 | 1616 | var finishCheckPlayerSources = function(){ |
1613 | 1617 | // Run embedPlayer sources hook |
1614 | | - mw.runTriggersCallback( _this, 'checkPlayerSourcesEvent', function(){ |
| 1618 | + mw.runTriggersCallback( _this, 'checkPlayerSourcesEvent', function(){ |
1615 | 1619 | _this.checkForTimedText(); |
1616 | 1620 | }) |
1617 | 1621 | } |
— | — | @@ -3681,3 +3685,4 @@ |
3682 | 3686 | return hasObj; |
3683 | 3687 | } |
3684 | 3688 | }; |
| 3689 | + |