r89745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89744‎ | r89745 | r89746 >
Date:20:32, 8 June 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed several js issues
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.lt.google.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.php
@@ -92,7 +92,7 @@
9393
9494 $wgResourceModules['ext.livetranslate'] = $moduleTemplate + array(
9595 'scripts' => array( 'includes/ext.livetranslate.js' ),
96 - 'dependencies' => array(),
 96+ 'dependencies' => array( 'jquery' ),
9797 'messages' => $egLTJSMessages
9898 );
9999
Index: trunk/extensions/LiveTranslate/includes/ext.lt.google.js
@@ -1,7 +1,7 @@
22 google.load("language", "1");
33 google.setOnLoadCallback(function(){google.language.getBranding("googlebranding");});
44
5 -( window.translationService = function( $ ) {
 5+(function( $ ){ window.translationService = function() {
66
77 var self = this;
88
@@ -110,7 +110,7 @@
111111
112112 /**
113113 * Translates a single DOM element using Google Translate.
114 - * Loops through child elements and recursivly calls itself to translate these.
 114+ * Loops through child elements and recursively calls itself to translate these.
115115 *
116116 * @param {jQuery} element
117117 * @param {string} sourceLang
@@ -118,22 +118,18 @@
119119 */
120120 this.translateElement = function( element, sourceLang, targetLang ) {
121121 ltdebug( 'Google: Translating element' );
122 - runningJobs++;
 122+ this.runningJobs++;
123123
124124 var maxChunkLength = 500;
125 -
 125+
126126 element.contents().each( function() {
127 - if ( this.nodeType == 3 && ( typeof this.data != undefined ) ) {
128 - console.log( $.trim( this.data ) );
129 - console.log( typeof $.trim( this.data ) );
130 - }
131127 ltdebug( 'Google: Element conent item' );
132128
133129 // If it's a text node, then translate it.
134 - if ( this.nodeType == 3 && this.data != undefined && $.trim( this.data ).length > 0 ) {
 130+ if ( this.nodeType == 3 && typeof this.data === 'string' && $.trim( this.data ).length > 0 ) {
135131 ltdebug( 'Google: Found content node' );
136132
137 - runningJobs++;
 133+ self.runningJobs++;
138134 self.translateChunk(
139135 this.data.split( new RegExp( "(\\S.+?[.!?])(?=\\s+|$)", "gi" ) ),
140136 [],
@@ -144,7 +140,8 @@
145141 );
146142 }
147143 // If it's an html element, check to see if it should be ignored, and if not, apply function again.
148 - else if ( $.inArray( $( this ).attr( 'id' ), [ 'siteSub', 'jump-to-nav' ] ) == -1
 144+ else if ( this.nodeType != 3
 145+ && $.inArray( $( this ).attr( 'id' ), [ 'siteSub', 'jump-to-nav' ] ) == -1
149146 && !$( this ).hasClass( 'notranslate' ) && !$( this ).hasClass( 'printfooter' )
150147 && $( this ).text().length > 0 ) {
151148
@@ -172,4 +169,4 @@
173170 }
174171 }
175172
176 -} )( jQuery );
\ No newline at end of file
 173+}; })( jQuery );
\ No newline at end of file

Status & tagging log