Index: trunk/phase3/js2/mwEmbed/libTimedText/mvTimeTextEdit.js |
— | — | @@ -8,6 +8,13 @@ |
9 | 9 | |
10 | 10 | var mvTimedTextEdit = {}; |
11 | 11 | |
| 12 | +loadGM({ |
| 13 | + "mwe-add-subs-file" : "Add/Replace Subtitle", |
| 14 | + "mwe-add-subs-file-title": "Select Subtitle to upload", |
| 15 | + "mwe-error-only-srt" : "Only srt files can be uploaded right now." |
| 16 | +}) |
| 17 | + |
| 18 | + |
12 | 19 | js2AddOnloadHook( function() { |
13 | 20 | function getSubtitle(f) { |
14 | 21 | var name = f.files[0].name; |
— | — | @@ -33,35 +40,35 @@ |
34 | 41 | languageSelect += '<option value="'+code+'">'+language+'('+code+')</option>'; |
35 | 42 | } |
36 | 43 | 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(); |
| 44 | + var cBtn = {}; |
| 45 | + cBtn[ gM('mwe-cancel') ] = function(){ |
| 46 | + $j(this).dialog('close'); |
| 47 | + } |
| 48 | + cBtn[ gM('mwe-ok') ] = function(){ |
| 49 | + var file = $j('#timed_text_file_upload'); |
| 50 | + var langKey = file[0].files[0].name.split('.'); |
| 51 | + var extension = langKey.pop(); |
| 52 | + langKey = langKey.pop(); |
| 53 | + var mimeTypes = { |
| 54 | + 'srt': 'text/x-srt', |
| 55 | + 'cmml': 'text/cmml' |
| 56 | + } |
| 57 | + if( !mimeTypes[ extension ] ){ |
| 58 | + js_log('Error: unknown extension:'+ extension); |
| 59 | + } |
| 60 | + //get language from form |
| 61 | + langKey = $j('#timed_text_language').val(); |
55 | 62 | |
56 | | - if(extension == "srt") { |
57 | | - var srt = getSubtitle(file[0]); |
58 | | - $j(this).html("saving..."); |
59 | | - $j('.ui-dialog-buttonpane').remove(); |
| 63 | + if(extension == "srt") { |
| 64 | + var srt = getSubtitle(file[0]); |
| 65 | + $j(this).html("saving..."); |
| 66 | + $j('.ui-dialog-buttonpane').remove(); |
60 | 67 | |
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'; |
| 68 | + var editToken = $j('input[name=wpEditToken]').val(); |
| 69 | + var title = wgTitle.split('.'); |
| 70 | + title.pop(); |
| 71 | + title.pop(); |
| 72 | + title = title.join('.') + '.' + langKey + '.srt'; |
66 | 73 | do_api_req({ |
67 | 74 | 'data': { |
68 | 75 | 'action' : 'edit', |
— | — | @@ -75,24 +82,28 @@ |
76 | 83 | $j(dialog).dialog('close'); |
77 | 84 | }}(this) |
78 | 85 | ); |
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, |
| 86 | + } else { |
| 87 | + $j(this).html(gM("mwe-error-only-srt")); |
| 88 | + } |
| 89 | + } |
| 90 | + $j.addDialog(gM("mwe-add-subs-file-title"), |
| 91 | + '<input type="file" id="timed_text_file_upload"></input><br />' + languageSelect, |
85 | 92 | cBtn); |
86 | 93 | $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 ); |
| 94 | + var langKey = this.files[0].name.split('.'); |
| 95 | + var extension = langKey.pop(); |
| 96 | + langKey = langKey.pop(); |
| 97 | + $j('#timed_text_language').val( langKey ); |
91 | 98 | }); |
92 | 99 | }); |
93 | 100 | } |
| 101 | + $j('#toolbar').hide(); |
| 102 | + var ttoolbar = $j('<div>'); |
| 103 | + $j('#toolbar').after(ttoolbar); |
| 104 | + |
94 | 105 | var button = $j('<button>'); |
95 | 106 | button.click(uploadSubtitles) |
96 | | - button.text("Upload Subtitle"); |
97 | | - $j('#toolbar').append(button); |
| 107 | + button.text(gM("mwe-add-subs-file")); |
| 108 | + ttoolbar.append(button); |
98 | 109 | }); |
99 | 110 | |