r60112 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60111‎ | r60112 | r60113 >
Date:02:43, 16 December 2009
Author:dale
Status:deferred
Tags:
Comment:
* some more timed text updates ( not fully working yet)
Modified paths:
  • /branches/js2-work/phase3/js2/mwEmbed/example_usage/Player_Themable.html (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libTimedText/jQuery.menu.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libTimedText/mw.timedText.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js2/remoteMwEmbed.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js2/mwEmbed/example_usage/Player_Themable.html
@@ -19,7 +19,7 @@
2020 wikiTitleKey="Charles_Lindbergh_flight_to_Brussels.ogg"
2121 durationHint="15">
2222 </video>
23 -
 23+<!--
2424 <video
2525 style="width:208px;height:160px;float:left"
2626 src="http://upload.wikimedia.org/wikipedia/commons/2/29/Charles_Lindbergh_flight_to_Brussels.ogg"
@@ -45,6 +45,7 @@
4646 poster="http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Charles_Lindbergh_flight_to_Brussels.ogg/mid-Charles_Lindbergh_flight_to_Brussels.ogg.jpg"
4747 durationHint="15">
4848 </video>
 49+ -->
4950 <b>(kskin) Source Code used:</b><br>
5051 <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"
5152 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 @@
23232323 }
23242324 // Load text interface if not already loaded:
23252325 var timedTextRequestSet = [
2326 - '$j.menu',
 2326+ '$j.fn.menu',
23272327 'mw.timedText'
23282328 ];
23292329 // Re-get the menu:
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js
@@ -1,4 +1,4 @@
2 -/*
 2+/**
33 * ~mwEmbed ~
44 * For details see: http://www.mediawiki.org/wiki/MwEmbed
55 *
@@ -1057,7 +1057,7 @@
10581058 * @param {Function} callback Function to run once class is loaded
10591059 */
10601060 loadClass: function( className , callback){
1061 -
 1061+ var _this = this;
10621062 // Make sure the class is not already defined:
10631063 if ( $.isset( className ) ){
10641064 mw.log( 'Class ( ' + className + ' ) already defined ' );
@@ -1094,21 +1094,13 @@
10951095
10961096 // Include class defined check for older browsers
10971097 var classDone = false;
 1098+
10981099
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 -
11091100 // 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 );
11111103 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 ] );
11131105 }else{
11141106 if( callback )
11151107 callback( className );
@@ -1116,6 +1108,18 @@
11171109 }
11181110 } );
11191111 //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 );
11201124 },
11211125
11221126 /**
@@ -1366,6 +1370,7 @@
13671371 }
13681372 return true;
13691373 }
 1374+
13701375 /**
13711376 * Waits for a object to be defined and the calls callback
13721377 *
@@ -1376,20 +1381,25 @@
13771382 */
13781383 var waitTime = 1200; // About 30 seconds
13791384 $.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 ){
13821389 _callNumber = 1;
 1390+ } else {
 1391+ _callNumber++;
 1392+ }
13831393
13841394 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 );
13871397 }
13881398
1389 - if ( $.isset( objectName ) ){
 1399+ if ( $.isset( objectName ) ){
13901400 callback( objectName )
13911401 }else{
13921402 setTimeout( function( ){
1393 - $.waitForObject( objectName, callback, _callNumber++ );
 1403+ $.waitForObject( objectName, callback, _callNumber);
13941404 }, 25);
13951405 }
13961406 }
@@ -1559,8 +1569,7 @@
15601570 script.onload = script.onreadystatechange = function(){
15611571 if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
15621572 if( callback )
1563 - callback( scriptRequest );
1564 - callback = null;
 1573+ callback( scriptRequest );
15651574 }
15661575 };
15671576 // Append the script to the DOM:
@@ -2222,7 +2231,7 @@
22232232 "kskinConfig" : "skins/kskin/kskinConfig.js",
22242233 "mvpcfConfig" : "skins/mvpcf/mvpcfConfig.js",
22252234
2226 - "$j.menu" : "libTimedText/jQuery.menu.js",
 2235+ "$j.fn.menu" : "libTimedText/jQuery.menu.js",
22272236 "mw.timedText" : "libTimedText/mw.timedText.js",
22282237 "Itext" : "libTimedText/Itext.js"
22292238
@@ -2232,7 +2241,7 @@
22332242 mw.addClassStyleSheets( {
22342243 "kskinConfig" : "skins/kskin/playerSkin.css",
22352244 "mvpcfConfig" : "skins/mvpcf/playerSkin.css",
2236 - "$j.menu" : "libTimedText/jQuery.menu.css"
 2245+ "$j.fn.menu" : "libTimedText/jQuery.menu.css"
22372246 } );
22382247
22392248 // Add the module loader function:
@@ -2260,7 +2269,7 @@
22612270 //If we should include the timedText interface
22622271 var checkForTimedText =false;
22632272 var timedTextRequestSet = [
2264 - '$j.menu',
 2273+ '$j.fn.menu',
22652274 'mw.timedText'
22662275 ];
22672276 switch( mw.getConfig( 'textInterface') ){
Index: branches/js2-work/phase3/js2/mwEmbed/libTimedText/mw.timedText.js
@@ -67,7 +67,7 @@
6868 // Layout for basic "timedText" type can be 'ontop', 'off', 'below'
6969 'layout': 'below',
7070 //Set the default local ( should be grabbed from the browser )
71 - 'userLanugage': 'en'
 71+ 'userLanugage': 'en'
7272 },
7373
7474 /**
@@ -121,7 +121,7 @@
122122 //Set up embedPlayer monitor hook:
123123 embedPlayer.addHook( 'monitor', function(){
124124 _this.monitor();
125 - } )
 125+ } )
126126 // @@TODO: Load cookie / page preferences
127127
128128 // Load textSources
@@ -140,11 +140,17 @@
141141 * Monitor video time and update timed text filed[s]
142142 */
143143 monitor: function( embedPlayer ){
 144+ mw.log(" timed Text monitor: " );
 145+ embedPlayer = this.embedPlayer;
144146 //setup local refrence to currentTime:
145147 var currentTime = embedPlayer.currentTime;
146148
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
149155 }
150156 },
151157
@@ -386,6 +392,7 @@
387393 return this.init( source );
388394 }
389395 textSource.prototype = {
 396+
390397 //The load state:
391398 loaded: false,
392399
@@ -393,6 +400,10 @@
394401 // captions include "start", "end" and "content" fields
395402 captions: [],
396403
 404+ // The previus index of the timed text served
 405+ // Avoids searching the entire array on time updates.
 406+ prevIndex: 0,
 407+
397408 /**
398409 * @constructor Inherits mediaSource from embedPlayer
399410 * @param {source} Base source element
@@ -435,18 +446,52 @@
436447 // Update the loaded state:
437448 _this.loaded = true;
438449 }, '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;
439479 }
440480 }
441481 /**
442482 * srt timed text parse hanndle:
443483 * @param {String} data Srt string to be parsed
444484 */
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, '');
449494
450 - // get captions
 495+ // Get captions
451496 var captions = [ ];
452497 var caplist = srt.split('\n\n');
453498 for (var i = 0; i < caplist.length; i=i+1) {
@@ -454,7 +499,7 @@
455500 var content, start, end, s;
456501 caption = caplist[i];
457502 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+/)) {
459504 // ignore caption number in s[0]
460505 // parse time string
461506 var m = s[1].match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/);
@@ -479,7 +524,11 @@
480525 // file format error or comment lines
481526 continue;
482527 }
483 - captions.push({start: start, end: end, content: content});
 528+ captions.push({
 529+ 'start' : start,
 530+ 'end' : end,
 531+ 'content' : content
 532+ } );
484533 }
485534
486535 return captions;
@@ -503,7 +552,11 @@
504553 content = bn.text;
505554 }
506555 } );
507 - captions.push({start: start, end: end, content: content});
 556+ captions.push ( {
 557+ 'start': start,
 558+ 'end' : end,
 559+ 'content' : content
 560+ } );
508561 } );
509562
510563 return captions;
Index: branches/js2-work/phase3/js2/mwEmbed/libTimedText/jQuery.menu.js
@@ -16,8 +16,8 @@
1717 var allUIMenus = [];
1818
1919 (function($) {
20 -
2120
 21+
2222 $.fn.menu = function( options ){
2323 var caller = this;
2424 var options = options;
@@ -674,4 +674,4 @@
675675 return result;
676676 };
677677
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 @@
77 var urlparts = getRemoteEmbedPath();
88 var mwEmbedHostPath = urlparts[0];
99 var mwRemoteVersion = '1.1d';
10 -var mwUseScriptLoader = true;
 10+var mwUseScriptLoader = false;
1111
1212 // Setup up request Params:
1313 var reqParts = urlparts[1].substring( 1 ).split( '&' );

Status & tagging log