http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89745

Revision: 89745
Author:   jeroendedauw
Date:     2011-06-08 20:32:37 +0000 (Wed, 08 Jun 2011)
Log Message:
-----------
fixed several js issues

Modified Paths:
--------------
    trunk/extensions/LiveTranslate/LiveTranslate.php
    trunk/extensions/LiveTranslate/includes/ext.lt.google.js

Modified: trunk/extensions/LiveTranslate/LiveTranslate.php
===================================================================
--- trunk/extensions/LiveTranslate/LiveTranslate.php    2011-06-08 20:31:36 UTC 
(rev 89744)
+++ trunk/extensions/LiveTranslate/LiveTranslate.php    2011-06-08 20:32:37 UTC 
(rev 89745)
@@ -92,7 +92,7 @@
        
        $wgResourceModules['ext.livetranslate'] = $moduleTemplate + array(
                'scripts' => array( 'includes/ext.livetranslate.js' ),
-               'dependencies' => array(),
+               'dependencies' => array( 'jquery' ),
                'messages' => $egLTJSMessages
        );
        

Modified: trunk/extensions/LiveTranslate/includes/ext.lt.google.js
===================================================================
--- trunk/extensions/LiveTranslate/includes/ext.lt.google.js    2011-06-08 
20:31:36 UTC (rev 89744)
+++ trunk/extensions/LiveTranslate/includes/ext.lt.google.js    2011-06-08 
20:32:37 UTC (rev 89745)
@@ -1,7 +1,7 @@
 google.load("language", "1");
 
google.setOnLoadCallback(function(){google.language.getBranding("googlebranding");});
 
-( window.translationService = function( $ ) {
+(function( $ ){ window.translationService = function() {
        
        var self = this;
        
@@ -110,7 +110,7 @@
        
        /**
         * Translates a single DOM element using Google Translate.
-        * Loops through child elements and recursivly calls itself to 
translate these.
+        * Loops through child elements and recursively calls itself to 
translate these.
         * 
         * @param {jQuery} element
         * @param {string} sourceLang
@@ -118,22 +118,18 @@
         */
        this.translateElement = function( element, sourceLang, targetLang ) {
                ltdebug( 'Google: Translating element' );
-               runningJobs++;
+               this.runningJobs++;
                
                var maxChunkLength = 500;
-               
+
                element.contents().each( function() {
-                       if ( this.nodeType == 3 && ( typeof this.data != 
undefined ) ) {
-                               console.log( $.trim( this.data ) );
-                               console.log( typeof $.trim( this.data ) );
-                       }
                        ltdebug( 'Google: Element conent item' );
                        
                        // If it's a text node, then translate it.
-                       if ( this.nodeType == 3 && this.data != undefined && 
$.trim( this.data ).length > 0 ) {
+                       if ( this.nodeType == 3 && typeof this.data === 
'string' && $.trim( this.data ).length > 0 ) {
                                ltdebug( 'Google: Found content node' );
                                
-                               runningJobs++;
+                               self.runningJobs++;
                                self.translateChunk(
                                        this.data.split( new RegExp( 
"(\\S.+?[.!?])(?=\\s+|$)", "gi" ) ),
                                        [],
@@ -144,7 +140,8 @@
                                );
                        }
                        // If it's an html element, check to see if it should 
be ignored, and if not, apply function again.
-                       else if ( $.inArray( $( this ).attr( 'id' ), [ 
'siteSub', 'jump-to-nav' ] ) == -1
+                       else if ( this.nodeType != 3
+                               && $.inArray( $( this ).attr( 'id' ), [ 
'siteSub', 'jump-to-nav' ] ) == -1
                                && !$( this ).hasClass( 'notranslate' ) && !$( 
this ).hasClass( 'printfooter' )
                                && $( this ).text().length > 0 ) {
                                
@@ -172,4 +169,4 @@
                }
        }
        
-} )( jQuery );
\ No newline at end of file
+}; })( jQuery );
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to