Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | |
94 | 94 | $wgResourceModules['ext.livetranslate'] = $moduleTemplate + array( |
95 | 95 | 'scripts' => array( 'includes/ext.livetranslate.js' ), |
96 | | - 'dependencies' => array(), |
| 96 | + 'dependencies' => array( 'jquery' ), |
97 | 97 | 'messages' => $egLTJSMessages |
98 | 98 | ); |
99 | 99 | |
Index: trunk/extensions/LiveTranslate/includes/ext.lt.google.js |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | google.load("language", "1"); |
3 | 3 | google.setOnLoadCallback(function(){google.language.getBranding("googlebranding");}); |
4 | 4 | |
5 | | -( window.translationService = function( $ ) { |
| 5 | +(function( $ ){ window.translationService = function() { |
6 | 6 | |
7 | 7 | var self = this; |
8 | 8 | |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * 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. |
115 | 115 | * |
116 | 116 | * @param {jQuery} element |
117 | 117 | * @param {string} sourceLang |
— | — | @@ -118,22 +118,18 @@ |
119 | 119 | */ |
120 | 120 | this.translateElement = function( element, sourceLang, targetLang ) { |
121 | 121 | ltdebug( 'Google: Translating element' ); |
122 | | - runningJobs++; |
| 122 | + this.runningJobs++; |
123 | 123 | |
124 | 124 | var maxChunkLength = 500; |
125 | | - |
| 125 | + |
126 | 126 | 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 | | - } |
131 | 127 | ltdebug( 'Google: Element conent item' ); |
132 | 128 | |
133 | 129 | // 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 ) { |
135 | 131 | ltdebug( 'Google: Found content node' ); |
136 | 132 | |
137 | | - runningJobs++; |
| 133 | + self.runningJobs++; |
138 | 134 | self.translateChunk( |
139 | 135 | this.data.split( new RegExp( "(\\S.+?[.!?])(?=\\s+|$)", "gi" ) ), |
140 | 136 | [], |
— | — | @@ -144,7 +140,8 @@ |
145 | 141 | ); |
146 | 142 | } |
147 | 143 | // 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 |
149 | 146 | && !$( this ).hasClass( 'notranslate' ) && !$( this ).hasClass( 'printfooter' ) |
150 | 147 | && $( this ).text().length > 0 ) { |
151 | 148 | |
— | — | @@ -172,4 +169,4 @@ |
173 | 170 | } |
174 | 171 | } |
175 | 172 | |
176 | | -} )( jQuery ); |
\ No newline at end of file |
| 173 | +}; })( jQuery ); |
\ No newline at end of file |