r78654 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78653‎ | r78654 | r78655 >
Date:00:24, 21 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r78652 - added completion code
Modified paths:
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -9,6 +9,8 @@
1010
1111 var currentLang = 'en'; // TODO
1212
 13+ var runningJobs = 0;
 14+
1315 // Compatibility with pre-RL code.
1416 // Messages will have been loaded into wgPushMessages.
1517 if ( typeof mediaWiki === 'undefined' ) {
@@ -81,16 +83,23 @@
8284 }
8385
8486 function translateElement( element, sourceLang, targetLang ) {
 87+ runningJobs++;
 88+
8589 element.contents().each( function() {
 90+ // If it's a text node, then translate it.
8691 if ( this.nodeType == 3 ) {
 92+ runningJobs++;
8793 translateChunk( this.wholeText, [], 500, sourceLang, targetLang, this );
8894 }
 95+ // If it's an html element, check to see if it should be ignored, and if not, apply function again.
8996 else if ( $.inArray( $( this ).attr( 'id' ), [ 'livetranslatediv', 'siteSub', 'jump-to-nav' ] ) == -1
9097 && $.inArray( $( this ).attr( 'class' ), [ 'notranslate', 'printfooter' ] ) == -1
9198 && $( this ).text().trim().length > 0 ) {
9299 translateElement( $( this ), sourceLang, targetLang );
93100 }
94101 } );
 102+
 103+ runningJobs--;
95104 }
96105
97106 function translateChunk( untranslatedText, chunks, currentMaxSize, sourceLang, targetLang, element ) {
@@ -105,6 +114,8 @@
106115
107116 if ( chunkSize < currentMaxSize ) {
108117 element.replaceWholeText( chunks.join() );
 118+ runningJobs--;
 119+ handleTranslationCompletion( targetLang );
109120 }
110121 else {
111122 translateChunk( untranslatedText.substr( chunkSize ), chunks, currentMaxSize, sourceLang, targetLang, element );
@@ -113,13 +124,11 @@
114125 );
115126 }
116127
117 - function handleTranslationCompletion( translation, targetLang ) {
118 - alert(translation);
119 - //$( '#bodyContent' ).innerHTML = result.translation;
120 -
121 - currentLang = targetLang;
122 -
123 - $( '#livetranslatebutton' ).attr( "disabled", false );
 128+ function handleTranslationCompletion( targetLang ) {
 129+ if ( !--runningJobs ) {
 130+ currentLang = targetLang;
 131+ $( '#livetranslatebutton' ).attr( "disabled", false );
 132+ }
124133 }
125134
126135 } ); })(jQuery);
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78652Follow up to r78646jeroendedauw00:18, 21 December 2010

Status & tagging log