Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js |
— | — | @@ -119,11 +119,14 @@ |
120 | 120 | |
121 | 121 | |
122 | 122 | // Options menu display: |
123 | | - $tp.find( '.k-options' ).unbind().click( function() { |
124 | | - if ( $j( '#' + embedObj.id + ' .k-menu' ).length == 0 ) { |
| 123 | + $tp.find( '.k-options' ).unbind().click( function() { |
| 124 | + // Get an updated refrence to the embed object |
| 125 | + var embedObj = $tp.get( 0 ); |
| 126 | + if ( $j( '#' + embedObj.id + ' .k-menu' ).length == 0 ) { |
125 | 127 | // Stop the player if it does not support overlays: |
126 | | - if ( !embedObj.supports['overlay'] ) |
| 128 | + if ( !embedObj.supports['overlays'] ){ |
127 | 129 | $tp.get( 0 ).stop(); |
| 130 | + } |
128 | 131 | // Add the options |
129 | 132 | _this.addOptionsBinding( $tp ); |
130 | 133 | } |
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js |
— | — | @@ -97,6 +97,13 @@ |
98 | 98 | */ |
99 | 99 | textSourceSetupFlag: null, |
100 | 100 | |
| 101 | + |
| 102 | + /* |
| 103 | + * Hard coded to "commons" right now .. but we will want to support per-asset provider id's |
| 104 | + * in addition to a standard "callback" system from cross domain grabbing of srt's |
| 105 | + */ |
| 106 | + textProviderId : 'commons', |
| 107 | + |
101 | 108 | /** |
102 | 109 | * Valid "iText" categories |
103 | 110 | */ |
— | — | @@ -120,6 +127,7 @@ |
121 | 128 | */ |
122 | 129 | timedTextExtMime: { |
123 | 130 | 'srt': 'text/x-srt', |
| 131 | + 'mw-srt': 'text/mw-srt', |
124 | 132 | 'cmml': 'text/cmml' |
125 | 133 | }, |
126 | 134 | |
— | — | @@ -260,8 +268,6 @@ |
261 | 269 | } |
262 | 270 | |
263 | 271 | //If there are no inline sources check timedTextProviders & wikiTitleKey |
264 | | - // ( hard coded to "commons" right now ) |
265 | | - var textProviderId = 'commons'; |
266 | 272 | if( !this.embedPlayer.wikiTitleKey || !this.timedTextProviders){ |
267 | 273 | //no other sources just issue the callback: |
268 | 274 | callback(); |
— | — | @@ -269,12 +275,12 @@ |
270 | 276 | } |
271 | 277 | |
272 | 278 | // Try to get sources from text provider: |
273 | | - var provider = this.timedTextProviders[ textProviderId ]; |
| 279 | + var provider = this.timedTextProviders[ this.textProviderId ]; |
274 | 280 | var assetKey = this.embedPlayer.wikiTitleKey; |
275 | 281 | switch( provider.lib ){ |
276 | 282 | case 'mediaWiki': |
277 | 283 | this.textProvider = new mw.MediaWikiTextProvider( { |
278 | | - 'provider_id' : textProviderId, |
| 284 | + 'provider_id' : this.textProviderId, |
279 | 285 | 'api_url': provider.api_url, |
280 | 286 | 'embedPlayer': this.embedPlayer |
281 | 287 | } ); |
— | — | @@ -443,6 +449,8 @@ |
444 | 450 | |
445 | 451 | /** |
446 | 452 | * Shows the timed text edit ui |
| 453 | + * |
| 454 | + * @param {String} mode Mode or page to display ( to diffrenciate between edit vs new transcript) |
447 | 455 | */ |
448 | 456 | showTimedTextEditUI: function( mode ){ |
449 | 457 | var _this = this; |
— | — | @@ -851,15 +859,16 @@ |
852 | 860 | } |
853 | 861 | // Set parser handler: |
854 | 862 | switch( this.getMIMEType() ){ |
| 863 | + //Special mediaWiki srt format ( support wiki-text in srt's ) |
| 864 | + case 'text/mw-srt': |
| 865 | + var handler = parseMwSrt; |
| 866 | + break; |
855 | 867 | case 'text/x-srt': |
856 | 868 | var handler = parseSrt; |
857 | 869 | break; |
858 | 870 | case 'text/cmml': |
859 | 871 | var handler = parseCMML; |
860 | 872 | break; |
861 | | - case 'text/html': |
862 | | - var handler = parseSrtHTML; |
863 | | - break; |
864 | 873 | default: |
865 | 874 | var hanlder = null; |
866 | 875 | break; |
— | — | @@ -929,6 +938,72 @@ |
930 | 939 | return false; |
931 | 940 | } |
932 | 941 | } |
| 942 | + /** |
| 943 | + * parse mediaWiki html srt |
| 944 | + */ |
| 945 | + function parseMwSrt( data ){ |
| 946 | + var captions = [ ]; |
| 947 | + var curentCap = []; |
| 948 | + var parseNextAsTime = false; |
| 949 | + // Optimize: we could use javascript strings instead of XML parsing |
| 950 | + $j( '<div>' + data + '</div>' ).find('p').each( function(){ |
| 951 | + currentPtext = $j(this).html(); |
| 952 | + mw.log( currentPtext ); |
| 953 | + |
| 954 | + //Check if the p matches the "all in one line" match: |
| 955 | + var m = currentPtext.replace('-->', '-->').match(/\d+\s(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?(.*)/); |
| 956 | + if (m) { |
| 957 | + captions.push({ |
| 958 | + 'start': |
| 959 | + (parseInt(m[1], 10) * 60 * 60) + |
| 960 | + (parseInt(m[2], 10) * 60) + |
| 961 | + (parseInt(m[3], 10)) + |
| 962 | + (parseInt(m[4], 10) / 1000), |
| 963 | + 'end': |
| 964 | + (parseInt(m[5], 10) * 60 * 60) + |
| 965 | + (parseInt(m[6], 10) * 60) + |
| 966 | + (parseInt(m[7], 10)) + |
| 967 | + (parseInt(m[8], 10) / 1000), |
| 968 | + 'content': $j.trim( m[9] ) |
| 969 | + }); |
| 970 | + return 'next'; |
| 971 | + } |
| 972 | + // Else check for multi-line match: |
| 973 | + if( parseInt( currentPtext ) == currentPtext ){ |
| 974 | + if( curentCap.length != 0) { |
| 975 | + captions.push( curentCap ); |
| 976 | + } |
| 977 | + curentCap = { |
| 978 | + 'content': '' |
| 979 | + }; |
| 980 | + return 'next'; |
| 981 | + } |
| 982 | + //Check only for time match: |
| 983 | + var m = currentPtext.replace('-->', '-->').match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/); |
| 984 | + if (m) { |
| 985 | + curentCap['start']= |
| 986 | + (parseInt(m[1], 10) * 60 * 60) + |
| 987 | + (parseInt(m[2], 10) * 60) + |
| 988 | + (parseInt(m[3], 10)) + |
| 989 | + (parseInt(m[4], 10) / 1000); |
| 990 | + curentCap['end']= |
| 991 | + (parseInt(m[5], 10) * 60 * 60) + |
| 992 | + (parseInt(m[6], 10) * 60) + |
| 993 | + (parseInt(m[7], 10)) + |
| 994 | + (parseInt(m[8], 10) / 1000); |
| 995 | + return 'next'; |
| 996 | + } |
| 997 | + //Else content for the curentCap |
| 998 | + if( currentPtext != '<br>' ){ |
| 999 | + curentCap['content'] += currentPtext; |
| 1000 | + } |
| 1001 | + }); |
| 1002 | + //Push last subtitle: |
| 1003 | + if( curentCap.length != 0){ |
| 1004 | + captions.push( curentCap ); |
| 1005 | + } |
| 1006 | + return captions; |
| 1007 | + } |
933 | 1008 | /** |
934 | 1009 | * srt timed text parse hanndle: |
935 | 1010 | * @param {String} data Srt string to be parsed |
— | — | @@ -1071,23 +1146,13 @@ |
1072 | 1147 | */ |
1073 | 1148 | loadTitleKey: function( titleKey, callback ){ |
1074 | 1149 | var request = { |
1075 | | - 'titles': titleKey, |
1076 | | - 'prop':'revisions', |
1077 | | - 'rvprop':'content' |
| 1150 | + 'action': 'parse', |
| 1151 | + 'page': titleKey |
1078 | 1152 | }; |
1079 | | - mw.getJSON( this.api_url, request, function( data ){ |
1080 | | - if ( data && data.query && data.query.pages ) { |
1081 | | - for ( var i in data.query.pages ) { |
1082 | | - var page = data.query.pages[i]; |
1083 | | - if ( page.revisions ) { |
1084 | | - for ( var j in page.revisions ) { |
1085 | | - if ( page.revisions[j]['*'] ) { |
1086 | | - callback( page.revisions[j]['*'] ); |
1087 | | - return ; |
1088 | | - } |
1089 | | - } |
1090 | | - } |
1091 | | - } |
| 1153 | + mw.getJSON( this.api_url, request, function( data ){ |
| 1154 | + if ( data && data.parse && data.parse.text['*'] ) { |
| 1155 | + callback( data.parse.text['*'] ); |
| 1156 | + return; |
1092 | 1157 | } |
1093 | 1158 | mw.log("Error: could not load:" + titleKey); |
1094 | 1159 | callback( false ); |
— | — | @@ -1158,7 +1223,13 @@ |
1159 | 1224 | var langKey = subPage.title.split( '.' ); |
1160 | 1225 | var extension = langKey.pop(); |
1161 | 1226 | langKey = langKey.pop(); |
1162 | | - |
| 1227 | + |
| 1228 | + //NOTE: we hard code the mw-srt type |
| 1229 | + // ( This is because mediaWiki srt files can have wiki-text and parsed as such ) |
| 1230 | + if( extension == 'srt' ){ |
| 1231 | + extension = 'mw-srt'; |
| 1232 | + } |
| 1233 | + |
1163 | 1234 | if ( ! _this.isSuportedLang( langKey ) ) { |
1164 | 1235 | mw.log( 'Error: langkey:' + langKey + ' not supported' ); |
1165 | 1236 | } else { |
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/remotes/RemoteMwTimedText.js |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | * Stop-gap for mediaWiki timed text support |
4 | 4 | * |
5 | 5 | * Does some tranformations to normal wiki timed Text pages to make them look |
6 | | -* like the php output that we will eventually want to support |
| 6 | +* like the php output that we will eventually want to have |
7 | 7 | */ |
8 | 8 | mw.addMessages( { |
9 | 9 | "mwe-language-subtiles-for-clip": "$1 subtitles for clip: $2", |
— | — | @@ -105,6 +105,9 @@ |
106 | 106 | mw.log("Error: no timedText method on embedPlayer" ); |
107 | 107 | return ; |
108 | 108 | } |
| 109 | + // Set the userLanguage: |
| 110 | + player.timedText.config.userLanugage = langKey; |
| 111 | + |
109 | 112 | //Make sure the timed text sources are loaded: |
110 | 113 | player.timedText.setupTextSources( function(){ |
111 | 114 | |
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js |
— | — | @@ -1463,8 +1463,7 @@ |
1464 | 1464 | _this['parent_' + method] = _this[method]; |
1465 | 1465 | } |
1466 | 1466 | _this[ method ] = playerInterface[method]; |
1467 | | - } |
1468 | | - |
| 1467 | + } |
1469 | 1468 | _this.getDuration(); |
1470 | 1469 | _this.showPlayer(); |
1471 | 1470 | _this.ready_to_play = true; |