Index: branches/js2-work/phase3/js2/mwEmbed/example_usage/Player_Themable.html |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | wikiTitleKey="Charles_Lindbergh_flight_to_Brussels.ogg" |
21 | 21 | durationHint="15"> |
22 | 22 | </video> |
23 | | - |
| 23 | +<!-- |
24 | 24 | <video |
25 | 25 | style="width:208px;height:160px;float:left" |
26 | 26 | src="http://upload.wikimedia.org/wikipedia/commons/2/29/Charles_Lindbergh_flight_to_Brussels.ogg" |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | poster="http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Charles_Lindbergh_flight_to_Brussels.ogg/mid-Charles_Lindbergh_flight_to_Brussels.ogg.jpg" |
47 | 47 | durationHint="15"> |
48 | 48 | </video> |
| 49 | + --> |
49 | 50 | <b>(kskin) Source Code used:</b><br> |
50 | 51 | <textarea cols="50" rows="7"><video class="kskin" style="width:400px;height:288px" poster="http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Charles_Lindbergh_flight_to_Brussels.ogg/mid-Charles_Lindbergh_flight_to_Brussels.ogg.jpg" |
51 | 52 | src="http://upload.wikimedia.org/wikipedia/commons/2/29/Charles_Lindbergh_flight_to_Brussels.ogg"></video></textarea> |
Index: branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js |
— | — | @@ -2322,7 +2322,7 @@ |
2323 | 2323 | } |
2324 | 2324 | // Load text interface if not already loaded: |
2325 | 2325 | var timedTextRequestSet = [ |
2326 | | - '$j.menu', |
| 2326 | + '$j.fn.menu', |
2327 | 2327 | 'mw.timedText' |
2328 | 2328 | ]; |
2329 | 2329 | // Re-get the menu: |
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js |
— | — | @@ -1,4 +1,4 @@ |
2 | | -/* |
| 2 | +/** |
3 | 3 | * ~mwEmbed ~ |
4 | 4 | * For details see: http://www.mediawiki.org/wiki/MwEmbed |
5 | 5 | * |
— | — | @@ -1057,7 +1057,7 @@ |
1058 | 1058 | * @param {Function} callback Function to run once class is loaded |
1059 | 1059 | */ |
1060 | 1060 | loadClass: function( className , callback){ |
1061 | | - |
| 1061 | + var _this = this; |
1062 | 1062 | // Make sure the class is not already defined: |
1063 | 1063 | if ( $.isset( className ) ){ |
1064 | 1064 | mw.log( 'Class ( ' + className + ' ) already defined ' ); |
— | — | @@ -1094,21 +1094,13 @@ |
1095 | 1095 | |
1096 | 1096 | // Include class defined check for older browsers |
1097 | 1097 | var classDone = false; |
| 1098 | + |
1098 | 1099 | |
1099 | | - // Check if the class is ready: ( not all browers support onLoad script attribute ) |
1100 | | - // In the case of a "class" we can pull the javascript state until its ready |
1101 | | - setTimeout( function(){ |
1102 | | - $.waitForObject( className, function( className ){ |
1103 | | - if( callback ) |
1104 | | - callback( className ); |
1105 | | - callback = null; |
1106 | | - } ); |
1107 | | - }, 25 ); |
1108 | | - |
1109 | 1100 | // Issue the request to load the class (include class name in result callback: |
1110 | | - $.getScript( scriptRequest, function( ) { |
| 1101 | + $.getScript( scriptRequest, function( scriptRequest ) { |
| 1102 | + mw.log(" on : " + scriptRequest ); |
1111 | 1103 | if(! $.isset( className )){ |
1112 | | - mw.log( 'ClassName not set in time ( Use waitForObject )' ); |
| 1104 | + mw.log( ' Error: ' + className +' not set in time, or not defined in:' + "\n" + _this.classPaths[ className ] ); |
1113 | 1105 | }else{ |
1114 | 1106 | if( callback ) |
1115 | 1107 | callback( className ); |
— | — | @@ -1116,6 +1108,18 @@ |
1117 | 1109 | } |
1118 | 1110 | } ); |
1119 | 1111 | //mw.log( 'done with running getScript request ' ); |
| 1112 | + |
| 1113 | + // Check if the class is ready: ( not all browsers support onLoad script attribute ) |
| 1114 | + // In the case of a "class" we can pull the javascript state until its ready |
| 1115 | + setTimeout( function(){ |
| 1116 | + $.waitForObject( className, function( className ){ |
| 1117 | + if( callback ){ |
| 1118 | + mw.log( " waitForObject callback for: " + className ); |
| 1119 | + callback( className ); |
| 1120 | + callback = null; |
| 1121 | + } |
| 1122 | + } ); |
| 1123 | + }, 25 ); |
1120 | 1124 | }, |
1121 | 1125 | |
1122 | 1126 | /** |
— | — | @@ -1366,6 +1370,7 @@ |
1367 | 1371 | } |
1368 | 1372 | return true; |
1369 | 1373 | } |
| 1374 | + |
1370 | 1375 | /** |
1371 | 1376 | * Waits for a object to be defined and the calls callback |
1372 | 1377 | * |
— | — | @@ -1376,20 +1381,25 @@ |
1377 | 1382 | */ |
1378 | 1383 | var waitTime = 1200; // About 30 seconds |
1379 | 1384 | $.waitForObject = function( objectName, callback, _callNumber){ |
1380 | | - //mw.log( 'waitForObject: ' + objectName ); |
1381 | | - if( !_callNumber ) |
| 1385 | + //mw.log( 'waitForObject: ' + objectName + ' cn: ' + _callNumber); |
| 1386 | + |
| 1387 | + // Increment callNumber: |
| 1388 | + if( !_callNumber ){ |
1382 | 1389 | _callNumber = 1; |
| 1390 | + } else { |
| 1391 | + _callNumber++; |
| 1392 | + } |
1383 | 1393 | |
1384 | 1394 | if( _callNumber > waitTime ){ |
1385 | | - mw.log( "Errro: waiting for object: " + objectName + ' timeout ' ); |
1386 | | - return ; |
| 1395 | + mw.log( "Error: waiting for object: " + objectName + ' timeout ' ); |
| 1396 | + callback( false ); |
1387 | 1397 | } |
1388 | 1398 | |
1389 | | - if ( $.isset( objectName ) ){ |
| 1399 | + if ( $.isset( objectName ) ){ |
1390 | 1400 | callback( objectName ) |
1391 | 1401 | }else{ |
1392 | 1402 | setTimeout( function( ){ |
1393 | | - $.waitForObject( objectName, callback, _callNumber++ ); |
| 1403 | + $.waitForObject( objectName, callback, _callNumber); |
1394 | 1404 | }, 25); |
1395 | 1405 | } |
1396 | 1406 | } |
— | — | @@ -1559,8 +1569,7 @@ |
1560 | 1570 | script.onload = script.onreadystatechange = function(){ |
1561 | 1571 | if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") { |
1562 | 1572 | if( callback ) |
1563 | | - callback( scriptRequest ); |
1564 | | - callback = null; |
| 1573 | + callback( scriptRequest ); |
1565 | 1574 | } |
1566 | 1575 | }; |
1567 | 1576 | // Append the script to the DOM: |
— | — | @@ -2222,7 +2231,7 @@ |
2223 | 2232 | "kskinConfig" : "skins/kskin/kskinConfig.js", |
2224 | 2233 | "mvpcfConfig" : "skins/mvpcf/mvpcfConfig.js", |
2225 | 2234 | |
2226 | | - "$j.menu" : "libTimedText/jQuery.menu.js", |
| 2235 | + "$j.fn.menu" : "libTimedText/jQuery.menu.js", |
2227 | 2236 | "mw.timedText" : "libTimedText/mw.timedText.js", |
2228 | 2237 | "Itext" : "libTimedText/Itext.js" |
2229 | 2238 | |
— | — | @@ -2232,7 +2241,7 @@ |
2233 | 2242 | mw.addClassStyleSheets( { |
2234 | 2243 | "kskinConfig" : "skins/kskin/playerSkin.css", |
2235 | 2244 | "mvpcfConfig" : "skins/mvpcf/playerSkin.css", |
2236 | | - "$j.menu" : "libTimedText/jQuery.menu.css" |
| 2245 | + "$j.fn.menu" : "libTimedText/jQuery.menu.css" |
2237 | 2246 | } ); |
2238 | 2247 | |
2239 | 2248 | // Add the module loader function: |
— | — | @@ -2260,7 +2269,7 @@ |
2261 | 2270 | //If we should include the timedText interface |
2262 | 2271 | var checkForTimedText =false; |
2263 | 2272 | var timedTextRequestSet = [ |
2264 | | - '$j.menu', |
| 2273 | + '$j.fn.menu', |
2265 | 2274 | 'mw.timedText' |
2266 | 2275 | ]; |
2267 | 2276 | switch( mw.getConfig( 'textInterface') ){ |
Index: branches/js2-work/phase3/js2/mwEmbed/libTimedText/mw.timedText.js |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | // Layout for basic "timedText" type can be 'ontop', 'off', 'below' |
69 | 69 | 'layout': 'below', |
70 | 70 | //Set the default local ( should be grabbed from the browser ) |
71 | | - 'userLanugage': 'en' |
| 71 | + 'userLanugage': 'en' |
72 | 72 | }, |
73 | 73 | |
74 | 74 | /** |
— | — | @@ -121,7 +121,7 @@ |
122 | 122 | //Set up embedPlayer monitor hook: |
123 | 123 | embedPlayer.addHook( 'monitor', function(){ |
124 | 124 | _this.monitor(); |
125 | | - } ) |
| 125 | + } ) |
126 | 126 | // @@TODO: Load cookie / page preferences |
127 | 127 | |
128 | 128 | // Load textSources |
— | — | @@ -140,11 +140,17 @@ |
141 | 141 | * Monitor video time and update timed text filed[s] |
142 | 142 | */ |
143 | 143 | monitor: function( embedPlayer ){ |
| 144 | + mw.log(" timed Text monitor: " ); |
| 145 | + embedPlayer = this.embedPlayer; |
144 | 146 | //setup local refrence to currentTime: |
145 | 147 | var currentTime = embedPlayer.currentTime; |
146 | 148 | |
147 | | - for( var i in enabledSource) { |
148 | | - |
| 149 | + for( var i in this.enabledSources ) { |
| 150 | + var source = this.enabledSources[ i ]; |
| 151 | + // Get text for "this" time: |
| 152 | + var text = source.getTextTime ( currentTime ); |
| 153 | + mw.log('should set text: ' + text ); |
| 154 | + // Set the display handle |
149 | 155 | } |
150 | 156 | }, |
151 | 157 | |
— | — | @@ -386,6 +392,7 @@ |
387 | 393 | return this.init( source ); |
388 | 394 | } |
389 | 395 | textSource.prototype = { |
| 396 | + |
390 | 397 | //The load state: |
391 | 398 | loaded: false, |
392 | 399 | |
— | — | @@ -393,6 +400,10 @@ |
394 | 401 | // captions include "start", "end" and "content" fields |
395 | 402 | captions: [], |
396 | 403 | |
| 404 | + // The previus index of the timed text served |
| 405 | + // Avoids searching the entire array on time updates. |
| 406 | + prevIndex: 0, |
| 407 | + |
397 | 408 | /** |
398 | 409 | * @constructor Inherits mediaSource from embedPlayer |
399 | 410 | * @param {source} Base source element |
— | — | @@ -435,18 +446,52 @@ |
436 | 447 | // Update the loaded state: |
437 | 448 | _this.loaded = true; |
438 | 449 | }, 'text' ); |
| 450 | + }, |
| 451 | + |
| 452 | + /** |
| 453 | + * Returns the text content for requested time |
| 454 | + * |
| 455 | + * @param {String} time Time in seconds |
| 456 | + */ |
| 457 | + getTextTime: function ( requestedTime ){ |
| 458 | + //debugger; |
| 459 | + var prevCaption = this.captions[ this.prevIndex ]; |
| 460 | + |
| 461 | + // Setup the startIndex: |
| 462 | + if( requestedTime >= prevCaption.start ){ |
| 463 | + var startIndex = this.prevIndex; |
| 464 | + }else{ |
| 465 | + //If a backwards seek start searching at the start: |
| 466 | + var startIndex = 0; |
| 467 | + } |
| 468 | + // Start looking for the text via time, return first match: |
| 469 | + for( var i = startIndex ; i < this.captions.length; i ++ ){ |
| 470 | + caption = this.captions[ i ]; |
| 471 | + if( requestedTime >= caption.start && |
| 472 | + requestedTime <= caption.end ){ |
| 473 | + this.prevIndex = i; |
| 474 | + return caption.text; |
| 475 | + } |
| 476 | + } |
| 477 | + //No text found in range return false: |
| 478 | + return false; |
439 | 479 | } |
440 | 480 | } |
441 | 481 | /** |
442 | 482 | * srt timed text parse hanndle: |
443 | 483 | * @param {String} data Srt string to be parsed |
444 | 484 | */ |
445 | | - function parseSrt( data ) { |
446 | | - var srt = data.replace(/\r+/g, ''); // remove dos newlines |
447 | | - srt = srt.replace(/^\s+|\s+$/g, ''); // trim white space start and end |
448 | | - srt = srt.replace(/<[a-zA-Z\/][^>]*>/g, ''); // remove all html tags for security reasons |
| 485 | + function parseSrt( data ) { |
| 486 | + // Remove dos newlines |
| 487 | + var srt = data.replace(/\r+/g, ''); |
| 488 | + |
| 489 | + // Trim white space start and end |
| 490 | + srt = srt.replace(/^\s+|\s+$/g, ''); |
| 491 | + |
| 492 | + // Remove all html tags for security reasons |
| 493 | + srt = srt.replace(/<[a-zA-Z\/][^>]*>/g, ''); |
449 | 494 | |
450 | | - // get captions |
| 495 | + // Get captions |
451 | 496 | var captions = [ ]; |
452 | 497 | var caplist = srt.split('\n\n'); |
453 | 498 | for (var i = 0; i < caplist.length; i=i+1) { |
— | — | @@ -454,7 +499,7 @@ |
455 | 500 | var content, start, end, s; |
456 | 501 | caption = caplist[i]; |
457 | 502 | s = caption.split(/\n/); |
458 | | - if (s[0].match(/^\d+$/) && s[1].match(/\d+:\d+:\d+/)) { |
| 503 | + if (s[0].match(/^\d+$/) && s[1].match(/\d+:\d+:\d+/)) { |
459 | 504 | // ignore caption number in s[0] |
460 | 505 | // parse time string |
461 | 506 | var m = s[1].match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/); |
— | — | @@ -479,7 +524,11 @@ |
480 | 525 | // file format error or comment lines |
481 | 526 | continue; |
482 | 527 | } |
483 | | - captions.push({start: start, end: end, content: content}); |
| 528 | + captions.push({ |
| 529 | + 'start' : start, |
| 530 | + 'end' : end, |
| 531 | + 'content' : content |
| 532 | + } ); |
484 | 533 | } |
485 | 534 | |
486 | 535 | return captions; |
— | — | @@ -503,7 +552,11 @@ |
504 | 553 | content = bn.text; |
505 | 554 | } |
506 | 555 | } ); |
507 | | - captions.push({start: start, end: end, content: content}); |
| 556 | + captions.push ( { |
| 557 | + 'start': start, |
| 558 | + 'end' : end, |
| 559 | + 'content' : content |
| 560 | + } ); |
508 | 561 | } ); |
509 | 562 | |
510 | 563 | return captions; |
Index: branches/js2-work/phase3/js2/mwEmbed/libTimedText/jQuery.menu.js |
— | — | @@ -16,8 +16,8 @@ |
17 | 17 | var allUIMenus = []; |
18 | 18 | |
19 | 19 | (function($) { |
20 | | - |
21 | 20 | |
| 21 | + |
22 | 22 | $.fn.menu = function( options ){ |
23 | 23 | var caller = this; |
24 | 24 | var options = options; |
— | — | @@ -674,4 +674,4 @@ |
675 | 675 | return result; |
676 | 676 | }; |
677 | 677 | |
678 | | -} )(jQuery); |
\ No newline at end of file |
| 678 | +} )(jQuery); |
\ No newline at end of file |
Index: branches/js2-work/phase3/js2/remoteMwEmbed.js |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | var urlparts = getRemoteEmbedPath(); |
8 | 8 | var mwEmbedHostPath = urlparts[0]; |
9 | 9 | var mwRemoteVersion = '1.1d'; |
10 | | -var mwUseScriptLoader = true; |
| 10 | +var mwUseScriptLoader = false; |
11 | 11 | |
12 | 12 | // Setup up request Params: |
13 | 13 | var reqParts = urlparts[1].substring( 1 ).split( '&' ); |