Index: trunk/phase3/js2/mwEmbed/mv_embed.js |
— | — | @@ -144,7 +144,8 @@ |
145 | 145 | "mvFirefoggRender" : "libSequencer/mvFirefoggRender.js", |
146 | 146 | "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js", |
147 | 147 | |
148 | | - "mvTextInterface" : "libTimedText/mvTextInterface.js" |
| 148 | + "mvTextInterface" : "libTimedText/mvTextInterface.js", |
| 149 | + "mvTimedTextEdit" : "libTimedText/mvTimedTextEdit.js" |
149 | 150 | }); |
150 | 151 | |
151 | 152 | // Dependency mapping for CSS files for self-contained included plugins: |
— | — | @@ -2022,4 +2023,4 @@ |
2023 | 2024 | function js_error( string ) { |
2024 | 2025 | alert( string ); |
2025 | 2026 | return false; |
2026 | | -} |
\ No newline at end of file |
| 2027 | +} |
Index: trunk/phase3/js2/mwEmbed/libTimedText/mvTimeTextEdit.js |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +/* |
| 3 | + * JS2-style edit.js |
| 4 | + */ |
| 5 | + |
| 6 | +// Setup configuration vars (if not set already) |
| 7 | +if( !mwAddMediaConfig ) |
| 8 | + var mwAddMediaConfig = {}; |
| 9 | + |
| 10 | +var mvTimedTextEdit = {}; |
| 11 | + |
| 12 | +js2AddOnloadHook( function() { |
| 13 | + function getSubtitle(f) { |
| 14 | + var name = f.files[0].name; |
| 15 | + var srtData = f.files[0].getAsBinary(); |
| 16 | + srtData = srtData.replace('\r\n', '\n'); |
| 17 | + return srtData; |
| 18 | + } |
| 19 | + function uploadSubtitles() { |
| 20 | + do_api_req({ |
| 21 | + 'data': { |
| 22 | + 'meta' : 'siteinfo', |
| 23 | + 'siprop' : 'languages' |
| 24 | + } |
| 25 | + }, function( langDataRaw ) { |
| 26 | + var langData = {}; |
| 27 | + var languageSelect = '<select id="timed_text_language">'; |
| 28 | + |
| 29 | + var lagRaw = langDataRaw.query.languages; |
| 30 | + for(var j in lagRaw){ |
| 31 | + var code = lagRaw[j].code; |
| 32 | + var language = lagRaw[j]['*']; |
| 33 | + langData[ code ] = language; |
| 34 | + languageSelect += '<option value="'+code+'">'+language+'('+code+')</option>'; |
| 35 | + } |
| 36 | + languageSelect += '/</select>'; |
| 37 | + var cBtn = {}; |
| 38 | + cBtn[ gM('mwe-cancel') ] = function(){ |
| 39 | + $j(this).dialog('close'); |
| 40 | + } |
| 41 | + cBtn[ gM('mwe-ok') ] = function(){ |
| 42 | + var file = $j('#timed_text_file_upload'); |
| 43 | + var langKey = file[0].files[0].name.split('.'); |
| 44 | + var extension = langKey.pop(); |
| 45 | + langKey = langKey.pop(); |
| 46 | + var mimeTypes = { |
| 47 | + 'srt': 'text/x-srt', |
| 48 | + 'cmml': 'text/cmml' |
| 49 | + } |
| 50 | + if( !mimeTypes[ extension ] ){ |
| 51 | + js_log('Error: unknown extension:'+ extension); |
| 52 | + } |
| 53 | + //get language from form |
| 54 | + langKey = $j('#timed_text_language').val(); |
| 55 | + |
| 56 | + if(extension == "srt") { |
| 57 | + var srt = getSubtitle(file[0]); |
| 58 | + $j(this).html("saving..."); |
| 59 | + $j('.ui-dialog-buttonpane').remove(); |
| 60 | + |
| 61 | + var editToken = $j('input[name=wpEditToken]').val(); |
| 62 | + var title = wgTitle.split('.'); |
| 63 | + title.pop(); |
| 64 | + title.pop(); |
| 65 | + title = title.join('.') + '.' + langKey + '.srt'; |
| 66 | + do_api_req({ |
| 67 | + 'data': { |
| 68 | + 'action' : 'edit', |
| 69 | + 'title' : title, |
| 70 | + 'text' : srt, |
| 71 | + 'token': editToken |
| 72 | + } |
| 73 | + }, function(dialog) { |
| 74 | + return function( result ) { |
| 75 | + document.location.href = wgArticlePath.replace('/$1', '?title=' + title + '&action=edit'); |
| 76 | + $j(dialog).dialog('close'); |
| 77 | + }}(this) |
| 78 | + ); |
| 79 | + } else { |
| 80 | + $j(this).html("error only srt works right now."); |
| 81 | + } |
| 82 | + } |
| 83 | + $j.addDialog("Select Subtitle to upload", |
| 84 | + '<input type="file" id="timed_text_file_upload"></input><br>' + languageSelect, |
| 85 | + cBtn); |
| 86 | + $j('#timed_text_file_upload').change(function(ev) { |
| 87 | + var langKey = this.files[0].name.split('.'); |
| 88 | + var extension = langKey.pop(); |
| 89 | + langKey = langKey.pop(); |
| 90 | + $j('#timed_text_language').val( langKey ); |
| 91 | + }); |
| 92 | + }); |
| 93 | + } |
| 94 | + var button = $j('<button>'); |
| 95 | + button.click(uploadSubtitles) |
| 96 | + button.text("Upload Subtitle"); |
| 97 | + $j('#toolbar').append(button); |
| 98 | +}); |
| 99 | + |
Index: trunk/phase3/js2/remoteMwEmbed.js |
— | — | @@ -24,7 +24,9 @@ |
25 | 25 | |
26 | 26 | //timed text dispaly: |
27 | 27 | if(wgPageName.indexOf("TimedText") === 0){ |
28 | | - |
| 28 | + load_mv_embed( function() { |
| 29 | + loadExternalJs( mwEmbedHostPath + '/mwEmbed/libTimedText/mvTimeTextEdit.js' + reqAguments ); |
| 30 | + } ); |
29 | 31 | } |
30 | 32 | |
31 | 33 | // Firefogg integration |