Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -189,6 +189,7 @@ |
190 | 190 | 'jquery.form', |
191 | 191 | 'jquery.ui.dialog', |
192 | 192 | 'jquery.autoresize', |
| 193 | + 'mediawiki.util', |
193 | 194 | ), |
194 | 195 | ) + $resourcePaths; |
195 | 196 | |
Index: trunk/extensions/Translate/resources/ext.translate.quickedit.js |
— | — | @@ -11,128 +11,126 @@ |
12 | 12 | * |
13 | 13 | * TODO list: |
14 | 14 | * * On succesful save, update the MessageTable display too. |
15 | | - * * Autoload ui classes |
16 | 15 | * * Instead of hc'd onscript, give them a class and use necessary triggers |
17 | 16 | * |
18 | 17 | * @author Niklas Laxström |
19 | | - * @copyright Copyright © 2009-2011 Niklas Laxström |
| 18 | + * @copyright Copyright © 2009-2012 Niklas Laxström |
20 | 19 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
21 | 20 | */ |
22 | 21 | |
23 | | -(function( $ ) { |
| 22 | +(function ( $, mw, undefined ) { |
24 | 23 | "use strict"; |
25 | | - var mw = mediaWiki; |
| 24 | + var dialogwidth = false, |
| 25 | + translate; |
26 | 26 | |
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 | + }; |
33 | 32 | |
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 ); |
37 | 42 | delete this.timeoutID; |
38 | | - }; |
| 43 | + } |
| 44 | + }; |
| 45 | + } |
39 | 46 | |
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 | + } |
45 | 50 | |
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 | + }; |
53 | 58 | |
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 | + } |
57 | 63 | |
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', '' ); |
65 | 68 | |
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 | + } |
70 | 75 | |
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 | + } ); |
75 | 87 | |
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' ); |
108 | 91 | return false; |
109 | 92 | } ); |
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 | + } |
116 | 98 | |
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 | + } ); |
125 | 109 | |
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 ); |
133 | 125 | } ); |
| 126 | + } ); |
134 | 127 | |
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 ); |
137 | 135 | }, |
138 | 136 | |
139 | 137 | openDialog: function( page, group ) { |
— | — | @@ -156,8 +154,8 @@ |
157 | 155 | dialog.load( url, false, function() { |
158 | 156 | var form = $( '#' + id + ' form' ); |
159 | 157 | |
160 | | - mw.translate.registerFeatures( dialog, form, page, group ); |
161 | | - mw.translate.addAccessKeys( form ); |
| 158 | + registerFeatures( dialog, form, page, group ); |
| 159 | + addAccessKeys( form ); |
162 | 160 | form.hide().slideDown(); |
163 | 161 | |
164 | 162 | form.ajaxForm( { |
— | — | @@ -178,13 +176,13 @@ |
179 | 177 | |
180 | 178 | dialog.dialog( { |
181 | 179 | bgiframe: true, |
182 | | - width: mw.translate.dialogwidth, |
| 180 | + width: dialogwidth, |
183 | 181 | title: page, |
184 | 182 | position: 'top', |
185 | 183 | 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( $([]) ); } |
189 | 187 | } ); |
190 | 188 | |
191 | 189 | return false; |
— | — | @@ -212,6 +210,6 @@ |
213 | 211 | }; |
214 | 212 | |
215 | 213 | mw.translate = translate; |
216 | | - $( document ).ready( mw.translate.init ); |
| 214 | + $( document ).ready( translate.init ); |
217 | 215 | |
218 | | -} )( jQuery ); |
\ No newline at end of file |
| 216 | +} )( jQuery, mediaWiki ); |