r78985 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78984‎ | r78985 | r78986 >
Date:23:19, 24 December 2010
Author:krinkle
Status:deferred
Tags:
Comment:
Fixing jslint errors
* var callback already defined
* Missing semi colons
* var b already defined
* Missing radix parameter (parseInt)
* 'trlVpWidth' called before it was defined (Moved higher up in the code)
* 'addAccessKeys' called before it was defined (Moved higher up in the code)
Modified paths:
  • /trunk/extensions/Translate/js/quickedit.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/js/quickedit.js
@@ -22,49 +22,62 @@
2323 */
2424
2525 function MessageCheckUpdater( callback ) {
26 - var callback = callback;
2726
2827 this.act = function() {
2928 callback();
3029 delete this.timeoutID;
31 - },
 30+ };
3231
3332 this.setup = function() {
3433 this.cancel();
3534 var self = this;
3635 this.timeoutID = window.setTimeout( self.act, 600 );
37 - },
 36+ };
3837
3938 this.cancel = function() {
40 - if(typeof this.timeoutID == "number") {
41 - window.clearTimeout(this.timeoutID);
 39+ if ( typeof this.timeoutID == 'number' ) {
 40+ window.clearTimeout( this.timeoutID );
4241 delete this.timeoutID;
4342 }
44 - }
 43+ };
4544 }
4645
 46+function trlVpWidth() {
 47+ return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
 48+}
 49+
 50+function addAccessKeys(dialog) {
 51+ jQuery( '[accesskey=a], [accesskey=s], [accesskey=d], [accesskey=h]' ).each(
 52+ function(i) { jQuery(this).removeAttr( 'accesskey' ); }
 53+ );
 54+ dialog.find( '.mw-translate-save' ).attr( 'accesskey', 'a' ).attr( 'title', '[' + tooltipAccessKeyPrefix + 'a]' );
 55+ dialog.find( '.mw-translate-next' ).attr( 'accesskey', 's' ).attr( 'title', '[' + tooltipAccessKeyPrefix + 's]' );
 56+ dialog.find( '.mw-translate-skip' ).attr( 'accesskey', 'd' ).attr( 'title', '[' + tooltipAccessKeyPrefix + 'd]' );
 57+ dialog.find( '.mw-translate-history' ).attr( 'accesskey', 'h' ).attr( 'title', '[' + tooltipAccessKeyPrefix + 'h]' );
 58+}
 59+
4760 var dialogwidth = false;
4861
4962 function trlOpenJsEdit( page, group ) {
50 - var url = wgScript + "?title=Special:Translate/editpage&suggestions=async&page=$1&loadgroup=$2";
51 - url = url.replace( "$1", encodeURIComponent( page ) ).replace( "$2", encodeURIComponent( group ) );
52 - var id = "jsedit" + page.replace( /[^a-zA-Z0-9_]/g, '_' );
 63+ var url = wgScript + '?title=Special:Translate/editpage&suggestions=async&page=$1&loadgroup=$2';
 64+ url = url.replace( '$1', encodeURIComponent( page ) ).replace( '$2', encodeURIComponent( group ) );
 65+ var id = 'jsedit' + page.replace( /[^a-zA-Z0-9_]/g, '_' );
5366
54 - var dialog = jQuery('#' + id);
 67+ var dialog = jQuery( '#' + id );
5568 if ( dialog.size() > 0 ) {
56 - dialog.dialog('option', 'position', 'top' );
57 - dialog.dialog('open');
 69+ dialog.dialog( 'option', 'position', 'top' );
 70+ dialog.dialog( 'open' );
5871 return false;
5972 }
6073
61 - jQuery('<div/>').attr('id', id).appendTo( jQuery('body') );
62 - dialog = jQuery('#' + id);
 74+ jQuery( '<div/>' ).attr( 'id', id ).appendTo( jQuery( 'body' ) );
 75+ dialog = jQuery( '#' + id );
6376
64 - var spinner = jQuery('<div/>').attr('class', 'mw-ajax-loader' );
65 - dialog.html( jQuery('<div/>').attr('class', 'mw-ajax-dialog').html( spinner ) );
 77+ var spinner = jQuery( '<div/>' ).attr( 'class', 'mw-ajax-loader' );
 78+ dialog.html( jQuery( '<div/>' ).attr( 'class', 'mw-ajax-dialog' ).html( spinner ) );
6679
6780 dialog.load(url, false, function() {
68 - var form = jQuery('#' + id + ' form');
 81+ var form = jQuery( '#' + id + ' form' );
6982
7083 form.hide().slideDown();
7184
@@ -73,70 +86,71 @@
7487
7588 form.find( '.mw-translate-next' ).click( function() {
7689 trlLoadNext( page );
77 - });
 90+ } );
7891
7992 form.find( '.mw-translate-skip' ).click( function() {
8093 trlLoadNext( page );
81 - dialog.dialog('close');
 94+ dialog.dialog( 'close' );
8295 return false;
83 - });
 96+ } );
8497
8598 form.find( '.mw-translate-history' ).click( function() {
86 - window.open( wgServer + wgScript + "?action=history&title=" + form.find( "input[name=title]" ).val() );
 99+ window.open( wgServer + wgScript + '?action=history&title=' + form.find( 'input[name=title]' ).val() );
87100 return false;
88 - });
 101+ } );
89102
90 - var textarea = form.find( ".mw-translate-edit-area" );
 103+ var textarea = form.find( '.mw-translate-edit-area' );
91104 textarea.focus();
92105
93 - if ( form.find( ".mw-translate-messagechecks" ) ) {
 106+ if ( form.find( '.mw-translate-messagechecks' ) ) {
94107 var checker = new MessageCheckUpdater( function() {
95 - var url = wgScript + "?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2";
96 - url = url.replace( "$1", encodeURIComponent( page ) ).replace( "$2", encodeURIComponent( group ) );
97 - jQuery.post( url, { translation: textarea.val() } , function(mydata) {
98 - form.find( ".mw-translate-messagechecks" ).replaceWith( mydata );
99 - });
100 - });
 108+ var url = wgScript + '?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2';
 109+ url = url.replace( '$1', encodeURIComponent( page ) ).replace( '$2', encodeURIComponent( group ) );
 110+ jQuery.post( url, { translation: textarea.val() } , function( mydata ) {
 111+ form.find( '.mw-translate-messagechecks' ).replaceWith( mydata );
 112+ } );
 113+ } );
101114
102115 textarea.keyup( function() { checker.setup(); } );
103116 }
104117
105118 addAccessKeys( form );
106 - var b = form.find(".mw-translate-save");
107 - b.val( b.val() + " (a)" );
108 - var b = form.find(".mw-translate-next");
109 - b.val( b.val() + " (s)" );
110 - var b = form.find(".mw-translate-skip");
111 - b.val( b.val() + " (d)" );
112 - var b = form.find(".mw-translate-history");
113 - b.val( b.val() + " (h)" );
 119+ var b = null;
 120+ b = form.find( '.mw-translate-save' );
 121+ b.val( b.val() + ' (a)' );
 122+ b = form.find( '.mw-translate-next' );
 123+ b.val( b.val() + ' (s)' );
 124+ b = form.find( '.mw-translate-skip' );
 125+ b.val( b.val() + ' (d)' );
 126+ b = form.find( '.mw-translate-history' );
 127+ b.val( b.val() + ' (h)' );
114128
115 - form.ajaxForm({
116 - dataType: "json",
 129+ form.ajaxForm( {
 130+ dataType: 'json',
117131 success: function(json) {
118132 if ( json.error ) {
119 - alert( json.error.info + " (" + json.error.code +")" );
120 - } else if ( json.edit.result === "Failure" ) {
121 - alert(trlMsgSaveFailed);
122 - } else if ( json.edit.result === "Success" ) {
123 - dialog.dialog("close");
 133+ alert( json.error.info + ' (' + json.error.code +')' );
 134+ } else if ( json.edit.result === 'Failure' ) {
 135+ alert( trlMsgSaveFailed );
 136+ } else if ( json.edit.result === 'Success' ) {
 137+ dialog.dialog( 'close' );
124138 } else {
125 - alert(trlMsgSaveFailed);
 139+ alert( trlMsgSaveFailed );
126140 }
127141 }
128 - });
129 - });
 142+ } );
 143+ } );
130144
131 - dialog.dialog({
 145+ dialog.dialog( {
132146 bgiframe: true,
133 - width: dialogwidth ? dialogwidth : parseInt(trlVpWidth()*0.8),
 147+ width: dialogwidth ? dialogwidth : parseInt( trlVpWidth()*0.8, 10 ),
134148 title: page,
135 - position: "top",
 149+ position: 'top',
136150 resize: function(event, ui) {
137 - jQuery("#"+ id + " textarea").width( "100%" );
 151+ jQuery( '#' + id + ' textarea' ).width( '100%' );
138152 },
139153 resizeStop: function(event, ui) {
140 - dialogwidth = jQuery("#"+ id).width();
 154+ dialogwidth = jQuery( '#' + id ).width();
141155 },
142156 focus: function(event, ui) {
143157 addAccessKeys( dialog );
@@ -144,34 +158,20 @@
145159 close: function(event, ui) {
146160 addAccessKeys( jQuery([]) );
147161 }
148 - });
 162+ } );
149163
150164 return false;
151165 }
152166
153 -function addAccessKeys(dialog) {
154 - jQuery("[accesskey=a], [accesskey=s], [accesskey=d], [accesskey=h]").each(
155 - function(i) { jQuery(this).removeAttr( "accesskey" ); }
156 - );
157 - dialog.find(".mw-translate-save").attr( "accesskey", "a" ).attr( "title", "[" + tooltipAccessKeyPrefix + "a]" );
158 - dialog.find(".mw-translate-next").attr( "accesskey", "s" ).attr( "title", "[" + tooltipAccessKeyPrefix + "s]" );
159 - dialog.find(".mw-translate-skip").attr( "accesskey", "d" ).attr( "title", "[" + tooltipAccessKeyPrefix + "d]" );
160 - dialog.find(".mw-translate-history").attr( "accesskey", "h" ).attr( "title", "[" + tooltipAccessKeyPrefix + "h]" );
161 -}
162 -
163 -function trlVpWidth() {
164 - return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
165 -}
166 -
167167 function trlLoadNext( title ) {
168 - var page = title.replace( /[^:]+:/, "");
169 - var namespace = title.replace( /:.*/, "");
 168+ var page = title.replace( /[^:]+:/, '' );
 169+ var namespace = title.replace( /:.*/, '' );
170170 var found = false;
171171 for ( key in trlKeys ) {
172172 if ( !trlKeys.hasOwnProperty(key) ) { continue; }
173173 value = trlKeys[key];
174174 if (found) {
175 - return trlOpenJsEdit( namespace + ":" + value );
 175+ return trlOpenJsEdit( namespace + ':' + value );
176176 } else if( page === value ) {
177177 found = true;
178178 }

Status & tagging log