r107753 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107752‎ | r107753 | r107754 >
Date:22:40, 31 December 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Trying to address my fixme in r107305 by hiding private stuff
Modified paths:
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.quickedit.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -189,6 +189,7 @@
190190 'jquery.form',
191191 'jquery.ui.dialog',
192192 'jquery.autoresize',
 193+ 'mediawiki.util',
193194 ),
194195 ) + $resourcePaths;
195196
Index: trunk/extensions/Translate/resources/ext.translate.quickedit.js
@@ -11,128 +11,126 @@
1212 *
1313 * TODO list:
1414 * * On succesful save, update the MessageTable display too.
15 - * * Autoload ui classes
1615 * * Instead of hc'd onscript, give them a class and use necessary triggers
1716 *
1817 * @author Niklas Laxström
19 - * @copyright Copyright © 2009-2011 Niklas Laxström
 18+ * @copyright Copyright © 2009-2012 Niklas Laxström
2019 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
2120 */
2221
23 -(function( $ ) {
 22+(function ( $, mw, undefined ) {
2423 "use strict";
25 - var mw = mediaWiki;
 24+ var dialogwidth = false,
 25+ translate;
2626
27 - var translate = {
28 - dialogwidth: false,
29 -
30 - init: function() {
31 - mw.translate.dialogwidth = parseInt( mw.translate.windowWidth()*0.8, 10 );
32 - },
 27+ function MessageCheckUpdater( callback ) {
 28+ this.act = function() {
 29+ callback();
 30+ delete this.timeoutID;
 31+ };
3332
34 - MessageCheckUpdater: function( callback ) {
35 - this.act = function() {
36 - callback();
 33+ this.setup = function() {
 34+ this.cancel();
 35+ var self = this;
 36+ this.timeoutID = window.setTimeout( self.act, 1000 );
 37+ };
 38+
 39+ this.cancel = function() {
 40+ if ( typeof this.timeoutID === 'number' ) {
 41+ window.clearTimeout( this.timeoutID );
3742 delete this.timeoutID;
38 - };
 43+ }
 44+ };
 45+ }
3946
40 - this.setup = function() {
41 - this.cancel();
42 - var self = this;
43 - this.timeoutID = window.setTimeout( self.act, 1000 );
44 - };
 47+ function windowWidth() {
 48+ return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
 49+ }
4550
46 - this.cancel = function() {
47 - if ( typeof this.timeoutID === 'number' ) {
48 - window.clearTimeout( this.timeoutID );
49 - delete this.timeoutID;
50 - }
51 - };
52 - },
 51+ function addAccessKeys( dialog ) {
 52+ var buttons = {
 53+ a: '.mw-translate-save',
 54+ s: '.mw-translate-next',
 55+ d: '.mw-translate-skip',
 56+ h: '.mw-translate-history'
 57+ };
5358
54 - windowWidth: function() {
55 - return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
56 - },
 59+ for ( var key in buttons ) {
 60+ if ( !buttons.hasOwnProperty( key ) ) {
 61+ continue;
 62+ }
5763
58 - addAccessKeys: function( dialog ) {
59 - var buttons = {
60 - a: '.mw-translate-save',
61 - s: '.mw-translate-next',
62 - d: '.mw-translate-skip',
63 - h: '.mw-translate-history'
64 - };
 64+ $( buttons[key] )
 65+ .val( function( i, b ) { return b.replace( / \(.\)$/, '' ); } )
 66+ .removeAttr( 'accesskey' )
 67+ .attr( 'title', '' );
6568
66 - for ( var key in buttons ) {
67 - if ( !buttons.hasOwnProperty( key ) ) {
68 - continue;
69 - }
 69+ dialog.find( buttons[key] )
 70+ .val( function( i, b ) { return b + ' (_)'.replace( '_', key ); } )
 71+ .attr( 'accesskey', key )
 72+ .attr( 'title', '[' + mw.util.tooltipAccessKeyPrefix + key + ']' );
 73+ }
 74+ }
7075
71 - $( buttons[key] )
72 - .val( function( i, b ) { return b.replace( / \(.\)$/, '' ); } )
73 - .removeAttr( 'accesskey' )
74 - .attr( 'title', '' );
 76+ function registerFeatures( dialog, form, page, group ) {
 77+ // Enable the collapsible element
 78+ var $identical = $( '.mw-identical-title' );
 79+ if ( $.isFunction( $identical.makeCollapsible ) ) {
 80+ $identical.makeCollapsible();
 81+ }
 82+
 83+ if ( mw.config.get( 'trlKeys' ) ) {
 84+ form.find( '.mw-translate-next' ).click( function() {
 85+ mw.translate.openNext( page, group );
 86+ } );
7587
76 - dialog.find( buttons[key] )
77 - .val( function( i, b ) { return b + ' (_)'.replace( '_', key ); } )
78 - .attr( 'accesskey', key )
79 - .attr( 'title', '[' + tooltipAccessKeyPrefix + key + ']' );
80 - }
81 - },
82 -
83 - registerFeatures: function( dialog, form, page, group ) {
84 - // Enable the collapsible element
85 - var $identical = $( '.mw-identical-title' );
86 - if ( $.isFunction( $identical.makeCollapsible ) ) {
87 - $identical.makeCollapsible();
88 - }
89 -
90 - if ( mw.config.get( 'trlKeys' ) ) {
91 - form.find( '.mw-translate-next' ).click( function() {
92 - mw.translate.openNext( page, group );
93 - } );
94 -
95 - form.find( '.mw-translate-skip' ).click( function() {
96 - mw.translate.openNext( page, group );
97 - dialog.dialog( 'close' );
98 - return false;
99 - } );
100 - } else {
101 - form.find( '.mw-translate-next, .mw-translate-skip' )
102 - .attr( 'disabled', 'disabled' )
103 - .css( 'display', 'none' );
104 - }
105 -
106 - form.find( '.mw-translate-history' ).click( function() {
107 - window.open( mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?action=history&title=' + form.find( 'input[name=title]' ).val() );
 88+ form.find( '.mw-translate-skip' ).click( function() {
 89+ mw.translate.openNext( page, group );
 90+ dialog.dialog( 'close' );
10891 return false;
10992 } );
110 -
111 - form.find( '.mw-translate-support, .mw-translate-askpermission' ).click( function() {
112 - // Can use .data() only with 1.4.3 or newer
113 - window.open( $(this).attr( 'data-load-url' ) );
114 - return false;
115 - } );
 93+ } else {
 94+ form.find( '.mw-translate-next, .mw-translate-skip' )
 95+ .attr( 'disabled', 'disabled' )
 96+ .css( 'display', 'none' );
 97+ }
11698
117 - form.find( 'input#summary' ).focus( function() {
118 - $(this).css( 'width', '85%' );
119 - } );
120 -
121 - var textarea = form.find( '.mw-translate-edit-area' );
122 - textarea.css( 'display', 'block' );
123 - textarea.autoResize( {extraSpace: 15, limit: 200} ).trigger( 'change' );
124 - textarea.focus();
 99+ form.find( '.mw-translate-history' ).click( function() {
 100+ window.open( mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?action=history&title=' + form.find( 'input[name=title]' ).val() );
 101+ return false;
 102+ } );
 103+
 104+ form.find( '.mw-translate-support, .mw-translate-askpermission' ).click( function() {
 105+ // Can use .data() only with 1.4.3 or newer
 106+ window.open( $(this).attr( 'data-load-url' ) );
 107+ return false;
 108+ } );
125109
126 - if ( form.find( '.mw-translate-messagechecks' ) ) {
127 - var checker = new mw.translate.MessageCheckUpdater( function() {
128 - var url = mw.config.get( 'wgScript' ) + '?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2';
129 - url = url.replace( '$1', encodeURIComponent( page ) ).replace( '$2', encodeURIComponent( group ) );
130 - $.post( url, { translation: textarea.val() }, function( mydata ) {
131 - form.find( '.mw-translate-messagechecks' ).replaceWith( mydata );
132 - } );
 110+ form.find( 'input#summary' ).focus( function() {
 111+ $(this).css( 'width', '85%' );
 112+ } );
 113+
 114+ var textarea = form.find( '.mw-translate-edit-area' );
 115+ textarea.css( 'display', 'block' );
 116+ textarea.autoResize( {extraSpace: 15, limit: 200} ).trigger( 'change' );
 117+ textarea.focus();
 118+
 119+ if ( form.find( '.mw-translate-messagechecks' ) ) {
 120+ var checker = new MessageCheckUpdater( function() {
 121+ var url = mw.config.get( 'wgScript' ) + '?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2';
 122+ url = url.replace( '$1', encodeURIComponent( page ) ).replace( '$2', encodeURIComponent( group ) );
 123+ $.post( url, { translation: textarea.val() }, function( mydata ) {
 124+ form.find( '.mw-translate-messagechecks' ).replaceWith( mydata );
133125 } );
 126+ } );
134127
135 - textarea.keyup( function() { checker.setup(); } );
136 - }
 128+ textarea.keyup( function() { checker.setup(); } );
 129+ }
 130+ }
 131+
 132+ translate = {
 133+ init: function() {
 134+ dialogwidth = parseInt( windowWidth()*0.8, 10 );
137135 },
138136
139137 openDialog: function( page, group ) {
@@ -156,8 +154,8 @@
157155 dialog.load( url, false, function() {
158156 var form = $( '#' + id + ' form' );
159157
160 - mw.translate.registerFeatures( dialog, form, page, group );
161 - mw.translate.addAccessKeys( form );
 158+ registerFeatures( dialog, form, page, group );
 159+ addAccessKeys( form );
162160 form.hide().slideDown();
163161
164162 form.ajaxForm( {
@@ -178,13 +176,13 @@
179177
180178 dialog.dialog( {
181179 bgiframe: true,
182 - width: mw.translate.dialogwidth,
 180+ width: dialogwidth,
183181 title: page,
184182 position: 'top',
185183 resize: function() { $( '#' + id + ' textarea' ).width( '100%' ); },
186 - resizeStop: function() { mw.translate.dialogwidth = $( '#' + id ).width(); },
187 - focus: function() { mw.translate.addAccessKeys( dialog ); },
188 - close: function() { mw.translate.addAccessKeys( $([]) ); }
 184+ resizeStop: function() { dialogwidth = $( '#' + id ).width(); },
 185+ focus: function() { addAccessKeys( dialog ); },
 186+ close: function() { addAccessKeys( $([]) ); }
189187 } );
190188
191189 return false;
@@ -212,6 +210,6 @@
213211 };
214212
215213 mw.translate = translate;
216 - $( document ).ready( mw.translate.init );
 214+ $( document ).ready( translate.init );
217215
218 -} )( jQuery );
\ No newline at end of file
 216+} )( jQuery, mediaWiki );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107305Rework ext.translate.quickedit.js from global functions into mw.translate...nikerabbit23:19, 25 December 2011

Status & tagging log