Index: trunk/extensions/Translate/js/quickedit.js |
— | — | @@ -22,49 +22,62 @@ |
23 | 23 | */ |
24 | 24 | |
25 | 25 | function MessageCheckUpdater( callback ) { |
26 | | - var callback = callback; |
27 | 26 | |
28 | 27 | this.act = function() { |
29 | 28 | callback(); |
30 | 29 | delete this.timeoutID; |
31 | | - }, |
| 30 | + }; |
32 | 31 | |
33 | 32 | this.setup = function() { |
34 | 33 | this.cancel(); |
35 | 34 | var self = this; |
36 | 35 | this.timeoutID = window.setTimeout( self.act, 600 ); |
37 | | - }, |
| 36 | + }; |
38 | 37 | |
39 | 38 | 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 ); |
42 | 41 | delete this.timeoutID; |
43 | 42 | } |
44 | | - } |
| 43 | + }; |
45 | 44 | } |
46 | 45 | |
| 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 | + |
47 | 60 | var dialogwidth = false; |
48 | 61 | |
49 | 62 | 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, '_' ); |
53 | 66 | |
54 | | - var dialog = jQuery('#' + id); |
| 67 | + var dialog = jQuery( '#' + id ); |
55 | 68 | if ( dialog.size() > 0 ) { |
56 | | - dialog.dialog('option', 'position', 'top' ); |
57 | | - dialog.dialog('open'); |
| 69 | + dialog.dialog( 'option', 'position', 'top' ); |
| 70 | + dialog.dialog( 'open' ); |
58 | 71 | return false; |
59 | 72 | } |
60 | 73 | |
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 ); |
63 | 76 | |
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 ) ); |
66 | 79 | |
67 | 80 | dialog.load(url, false, function() { |
68 | | - var form = jQuery('#' + id + ' form'); |
| 81 | + var form = jQuery( '#' + id + ' form' ); |
69 | 82 | |
70 | 83 | form.hide().slideDown(); |
71 | 84 | |
— | — | @@ -73,70 +86,71 @@ |
74 | 87 | |
75 | 88 | form.find( '.mw-translate-next' ).click( function() { |
76 | 89 | trlLoadNext( page ); |
77 | | - }); |
| 90 | + } ); |
78 | 91 | |
79 | 92 | form.find( '.mw-translate-skip' ).click( function() { |
80 | 93 | trlLoadNext( page ); |
81 | | - dialog.dialog('close'); |
| 94 | + dialog.dialog( 'close' ); |
82 | 95 | return false; |
83 | | - }); |
| 96 | + } ); |
84 | 97 | |
85 | 98 | 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() ); |
87 | 100 | return false; |
88 | | - }); |
| 101 | + } ); |
89 | 102 | |
90 | | - var textarea = form.find( ".mw-translate-edit-area" ); |
| 103 | + var textarea = form.find( '.mw-translate-edit-area' ); |
91 | 104 | textarea.focus(); |
92 | 105 | |
93 | | - if ( form.find( ".mw-translate-messagechecks" ) ) { |
| 106 | + if ( form.find( '.mw-translate-messagechecks' ) ) { |
94 | 107 | 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 | + } ); |
101 | 114 | |
102 | 115 | textarea.keyup( function() { checker.setup(); } ); |
103 | 116 | } |
104 | 117 | |
105 | 118 | 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)' ); |
114 | 128 | |
115 | | - form.ajaxForm({ |
116 | | - dataType: "json", |
| 129 | + form.ajaxForm( { |
| 130 | + dataType: 'json', |
117 | 131 | success: function(json) { |
118 | 132 | 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' ); |
124 | 138 | } else { |
125 | | - alert(trlMsgSaveFailed); |
| 139 | + alert( trlMsgSaveFailed ); |
126 | 140 | } |
127 | 141 | } |
128 | | - }); |
129 | | - }); |
| 142 | + } ); |
| 143 | + } ); |
130 | 144 | |
131 | | - dialog.dialog({ |
| 145 | + dialog.dialog( { |
132 | 146 | bgiframe: true, |
133 | | - width: dialogwidth ? dialogwidth : parseInt(trlVpWidth()*0.8), |
| 147 | + width: dialogwidth ? dialogwidth : parseInt( trlVpWidth()*0.8, 10 ), |
134 | 148 | title: page, |
135 | | - position: "top", |
| 149 | + position: 'top', |
136 | 150 | resize: function(event, ui) { |
137 | | - jQuery("#"+ id + " textarea").width( "100%" ); |
| 151 | + jQuery( '#' + id + ' textarea' ).width( '100%' ); |
138 | 152 | }, |
139 | 153 | resizeStop: function(event, ui) { |
140 | | - dialogwidth = jQuery("#"+ id).width(); |
| 154 | + dialogwidth = jQuery( '#' + id ).width(); |
141 | 155 | }, |
142 | 156 | focus: function(event, ui) { |
143 | 157 | addAccessKeys( dialog ); |
— | — | @@ -144,34 +158,20 @@ |
145 | 159 | close: function(event, ui) { |
146 | 160 | addAccessKeys( jQuery([]) ); |
147 | 161 | } |
148 | | - }); |
| 162 | + } ); |
149 | 163 | |
150 | 164 | return false; |
151 | 165 | } |
152 | 166 | |
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 | | - |
167 | 167 | function trlLoadNext( title ) { |
168 | | - var page = title.replace( /[^:]+:/, ""); |
169 | | - var namespace = title.replace( /:.*/, ""); |
| 168 | + var page = title.replace( /[^:]+:/, '' ); |
| 169 | + var namespace = title.replace( /:.*/, '' ); |
170 | 170 | var found = false; |
171 | 171 | for ( key in trlKeys ) { |
172 | 172 | if ( !trlKeys.hasOwnProperty(key) ) { continue; } |
173 | 173 | value = trlKeys[key]; |
174 | 174 | if (found) { |
175 | | - return trlOpenJsEdit( namespace + ":" + value ); |
| 175 | + return trlOpenJsEdit( namespace + ':' + value ); |
176 | 176 | } else if( page === value ) { |
177 | 177 | found = true; |
178 | 178 | } |