Index: branches/MwEmbedStandAlone/modules/MiroSubs/mw.MiroSubsConfig.js |
— | — | @@ -1,4 +1,7 @@ |
2 | 2 | |
| 3 | +// include all our module messages |
| 4 | +mw.includeAllModuleMessages(); |
| 5 | + |
3 | 6 | /** |
4 | 7 | * Generates a miro subs config also see: |
5 | 8 | * http://dev.universalsubtitles.org/widget/api_demo.html |
— | — | @@ -76,15 +79,34 @@ |
77 | 80 | }, |
78 | 81 | 'videoURL' : _this.getVideoURL(), |
79 | 82 | 'save': function( miroSubs, doneSaveCallback, cancelCallback) { |
| 83 | + // Close down the editor |
| 84 | + // @@( no way to turn off bindings ) |
| 85 | + // @@FIXME add api Close dialog |
| 86 | + // mirosubs.api.closeDialog(); |
| 87 | + doneSaveCallback(); |
| 88 | + $j('.mirosubs-modal-widget-bg,.mirosubs-modal-widget').hide(); |
| 89 | + |
80 | 90 | // Convert the miroSubs to srt |
81 | | - var srtText = _this.miroSubs2Srt( miroSubs ); |
82 | | - _this.saveSrtText( srtText, function(status){ |
83 | | - if( status ){ |
84 | | - doneSaveCallback(); |
85 | | - } else { |
86 | | - cancelCallback(); |
| 91 | + var srtText = _this.miroSubs2Srt( miroSubs ); |
| 92 | + _this.getSaveSummary( function( summary ){ |
| 93 | + if( summary === false ){ |
| 94 | + // Return to current page without saving the text |
| 95 | + location.reload(true); |
| 96 | + return ; |
87 | 97 | } |
88 | | - }); |
| 98 | + _this.saveSrtText( srtText, summary, function(status){ |
| 99 | + // No real error handling right now |
| 100 | + // refresh page regardless of save or cancel |
| 101 | + location.reload(true); |
| 102 | + |
| 103 | + /* @@todo error handling |
| 104 | + if( status ){ |
| 105 | + doneSaveCallback(); |
| 106 | + } else { |
| 107 | + cancelCallback(); |
| 108 | + }*/ |
| 109 | + }); |
| 110 | + }); |
89 | 111 | }, |
90 | 112 | 'permalink': 'http://commons.wikimedia.org', |
91 | 113 | // not sure if this is needed |
— | — | @@ -94,8 +116,43 @@ |
95 | 117 | 'embedCode' : 'some code to embed' |
96 | 118 | }; |
97 | 119 | }, |
98 | | - saveSrtText: function( srtText, calllback ){ |
99 | | - var _this = this; |
| 120 | + getSaveSummary: function( callback ){ |
| 121 | + // Add a dialog to get save summary |
| 122 | + var buttons ={}; |
| 123 | + buttons[ gM('mwe-mirosubs-save-subs') ] = function(){ |
| 124 | + var summary = $j('#mwe-mirosubs-save-summary').val(); |
| 125 | + // Append link to gadget: |
| 126 | + summary+= ' with [[Help:Gadget-MwEmbed/UniversalSubs|UniversalSubs]]'; |
| 127 | + callback( summary ); |
| 128 | + // set dialog to loading |
| 129 | + $j( this ).html( $j('<div />').append( |
| 130 | + gM('mwe-mirosubs-saving-subs'), |
| 131 | + $j('<div />') |
| 132 | + .loadingSpinner() |
| 133 | + ) |
| 134 | + ); |
| 135 | + }; |
| 136 | + buttons[ gM('mwe-cancel') ] = function(){ |
| 137 | + callback( false ); |
| 138 | + $j( this ).dialog( 'close' ); |
| 139 | + }; |
| 140 | + // Reduce the z-index so we can put the model ontop: |
| 141 | + //$j('.mirosubs-modal-widget-bg,.mirosubs-modal-widget').css( 'z-index', 10 ); |
| 142 | + mw.addDialog( { |
| 143 | + 'title' : gM("mwe-mirosubs-save-summary"), |
| 144 | + 'width' : 450, |
| 145 | + 'content' : $j('<div />').append( |
| 146 | + $j('<h3 />').text( gM("mwe-mirosubs-save-summary") ), |
| 147 | + $j('<input/>').attr({ |
| 148 | + 'id' : 'mwe-mirosubs-save-summary', |
| 149 | + 'size': '35' |
| 150 | + }).val( gM('mwe-mirosubs-save-default') ) |
| 151 | + ), |
| 152 | + 'buttons' : buttons |
| 153 | + }); |
| 154 | + }, |
| 155 | + saveSrtText: function( srtText, summary, callback ){ |
| 156 | + var _this = this; |
100 | 157 | var timedTextTitle = 'TimedText:' + |
101 | 158 | this.embedPlayer.apiTitleKey + |
102 | 159 | '.' + this.config.languageKey + '.srt'; |
— | — | @@ -108,15 +165,15 @@ |
109 | 166 | var request = { |
110 | 167 | 'action':'edit', |
111 | 168 | 'title': timedTextTitle, |
112 | | - 'summary': "Updated subtitles with [[Help:Gadget-MwEmbed/UniversalSubs|UniversalSubs]]", |
113 | 169 | 'text': srtText, |
| 170 | + 'summary': summary, |
114 | 171 | 'token': token |
115 | 172 | }; |
116 | 173 | mw.getJSON( apiUrl, request, function(data){ |
117 | 174 | if( data.edit.result == "Success" ){ |
118 | | - calllback( true ); |
| 175 | + callback( true ); |
119 | 176 | } else { |
120 | | - calllback( false ); |
| 177 | + callback( false ); |
121 | 178 | } |
122 | 179 | }); |
123 | 180 | }); |
— | — | @@ -148,10 +205,12 @@ |
149 | 206 | |
150 | 207 | // Get the existing subtitles in miro format |
151 | 208 | getSubsInMiroFormat: function( callback ){ |
152 | | - var _this = this; |
153 | | - var miroSubs = []; |
| 209 | + var _this = this; |
154 | 210 | var playerTimedText = this.embedPlayer.timedText; |
| 211 | + |
| 212 | + var letters = 'abcdefghijklmnopqrstuvwxyz'; |
155 | 213 | playerTimedText.setupTextSources( function(){ |
| 214 | + var miroJsonSubs = []; |
156 | 215 | // NOTE the autoselected default language is a tricky issue |
157 | 216 | // We need to add support for language selection in the config object save callback |
158 | 217 | |
— | — | @@ -161,16 +220,17 @@ |
162 | 221 | _this.config.languageKey = source.srclang; |
163 | 222 | for( var i = 0; i < captions.length ; i ++ ){ |
164 | 223 | var caption = captions[i]; |
165 | | - miroSubs.push({ |
166 | | - 'subtitle_id': i, |
| 224 | + // get random letters |
| 225 | + miroJsonSubs.push({ |
| 226 | + 'subtitle_id': 'sub_' + i, |
167 | 227 | 'text': caption.content, |
168 | 228 | 'start_time': caption.start, |
169 | 229 | 'end_time': caption.end, |
170 | 230 | 'sub_order': i |
171 | 231 | }); |
172 | 232 | } |
173 | | - }); |
174 | | - callback( miroSubs ); |
| 233 | + }); |
| 234 | + callback( miroJsonSubs ); |
175 | 235 | }); |
176 | 236 | } |
177 | 237 | }; |
\ No newline at end of file |
Index: branches/MwEmbedStandAlone/modules/MiroSubs/MiroSubs.i18n.php |
— | — | @@ -12,4 +12,8 @@ |
13 | 13 | 'mwe-mirosubs-add-universal-subtitles' => 'Universal subtitles editor', |
14 | 14 | 'mwe-mirosubs-not-loggedin' => 'Please login to edit subtitles with universal subtitles', |
15 | 15 | 'mwe-mirosubs-loading-universal-subtitles' => 'Loading universal subtitles editor', |
| 16 | + 'mwe-mirosubs-save-summary' => 'Summary of subtitle edits', |
| 17 | + 'mwe-mirosubs-save-default' => 'Edited subtitles', |
| 18 | + 'mwe-mirosubs-save-subs' => 'Save subtitles', |
| 19 | + 'mwe-mirosubs-saving-subs' => 'Saving subtitles ...' |
16 | 20 | ); |
\ No newline at end of file |
Index: branches/MwEmbedStandAlone/modules/TimedText/mw.TimedText.js |
— | — | @@ -345,11 +345,13 @@ |
346 | 346 | |
347 | 347 | // Get the current source sub captions |
348 | 348 | getCurrentSubSource: function( callback ){ |
| 349 | + mw.log("getCurrentSubSource:: enabled source:" + this.enabledSources.length); |
349 | 350 | for( var i =0; i < this.enabledSources.length; i++ ){ |
350 | 351 | var source = this.enabledSources[i]; |
351 | 352 | if( source.category == 'SUB' ){ |
352 | 353 | source.load( function(){ |
353 | 354 | callback( source); |
| 355 | + return ; |
354 | 356 | }); |
355 | 357 | } |
356 | 358 | } |
— | — | @@ -902,6 +904,7 @@ |
903 | 905 | if( _this.loaded ) { |
904 | 906 | if( callback ) { |
905 | 907 | callback(); |
| 908 | + return ; |
906 | 909 | } |
907 | 910 | }; |
908 | 911 | _this.loaded = true; |
— | — | @@ -1007,17 +1010,19 @@ |
1008 | 1011 | //Check if the p matches the "all in one line" match: |
1009 | 1012 | var m = currentPtext.replace('-->', '-->').match(/\d+\s(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?\n?(.*)/); |
1010 | 1013 | if (m) { |
| 1014 | + var startMs = (m[4])? (parseInt(m[4], 10) / 1000):0; |
| 1015 | + var endMs = (m[8])? (parseInt(m[8], 10) / 1000) : 0; |
1011 | 1016 | captions.push({ |
1012 | 1017 | 'start': |
1013 | 1018 | (parseInt(m[1], 10) * 60 * 60) + |
1014 | 1019 | (parseInt(m[2], 10) * 60) + |
1015 | 1020 | (parseInt(m[3], 10)) + |
1016 | | - (parseInt(m[4], 10) / 1000), |
| 1021 | + startMs , |
1017 | 1022 | 'end': |
1018 | 1023 | (parseInt(m[5], 10) * 60 * 60) + |
1019 | 1024 | (parseInt(m[6], 10) * 60) + |
1020 | 1025 | (parseInt(m[7], 10)) + |
1021 | | - (parseInt(m[8], 10) / 1000), |
| 1026 | + endMs, |
1022 | 1027 | 'content': $j.trim( m[9] ) |
1023 | 1028 | }); |
1024 | 1029 | return 'next'; |
— | — | @@ -1035,16 +1040,18 @@ |
1036 | 1041 | //Check only for time match: |
1037 | 1042 | var m = currentPtext.replace('-->', '-->').match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/); |
1038 | 1043 | if (m) { |
| 1044 | + var startMs = (m[4])? (parseInt(m[4], 10) / 1000):0; |
| 1045 | + var endMs = (m[8])? (parseInt(m[8], 10) / 1000) : 0; |
1039 | 1046 | curentCap['start']= |
1040 | 1047 | (parseInt(m[1], 10) * 60 * 60) + |
1041 | 1048 | (parseInt(m[2], 10) * 60) + |
1042 | 1049 | (parseInt(m[3], 10)) + |
1043 | | - (parseInt(m[4], 10) / 1000); |
| 1050 | + startMs; |
1044 | 1051 | curentCap['end']= |
1045 | 1052 | (parseInt(m[5], 10) * 60 * 60) + |
1046 | 1053 | (parseInt(m[6], 10) * 60) + |
1047 | 1054 | (parseInt(m[7], 10)) + |
1048 | | - (parseInt(m[8], 10) / 1000); |
| 1055 | + endMs; |
1049 | 1056 | return 'next'; |
1050 | 1057 | } |
1051 | 1058 | //Else content for the curentCap |