User:Kaldari/translate.js

// if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get( 'wgAction' ) === 'view' && $( 'table.translations' ).length ) { // Script depends on jQuery dialog widget mw.loader.using( 'jquery.ui', function {		// Construct object (to prevent namespace conflicts)		translations = {

displayProgress: function( message ) { $('#translationForm div').hide; // remove everything else from the dialog box $('#translationForm').append ( $(' ').html( message+' ' ) ); },			displayError: function( error ) { $('#translationForm div').hide; // remove everything else from the dialog box $('#translationForm').append ( $(' ').html( 'Error: '+error ) ); },			editPage: function( summary, template ) { var editToken = mw.user.tokens.get( 'csrfToken' ); if ( !editToken ) { translations.displayError( 'Could not retrieve edit token.' ); } else { summary = "t+"; $.ajax({						url: wgScriptPath + '/api.php?',						data: 'action=edit&title='+encodeURIComponent(mw.config.get('wgPageName'))+'&section=new&summary='+encodeURIComponent(summary)+'&text='+encodeURIComponent(template)+'&format=json&token='+encodeURIComponent(editToken),						dataType: 'json',						type: 'POST',						success: function( data ) {							if ( data.edit.result == "Success" ) {								window.location.reload;							} else {								translations.displayError( 'Unknown result from API.' );							}						},						error: function( xhr ) {							translations.displayError( 'Edit failed.' );							//console.debug( xhr.responseText );						}					}); }			},			initialize: function { // Define interface $translationDialog = $(' ') .append(						$(' ')							.html( 'Language code: ' )							.append( $('') )					) .append(						$(' ')							.html( 'Translation: ' )							.append( $('') )					) .dialog({						width: 500,						autoOpen: false,						title: 'Add a translation',						modal: false,						buttons: { "Add translation": function {							$(this).dialog({buttons:{}});							// Perform edit to page							translations.displayProgress( 'Adding translation to page...' );							var message = $('#wordMessage').val;							var template = + message +;							translations.editPage( message, template );						}}					}); // Insert new button into page var addButton = 'Add a translation'; $( 'table.translations:not([data-gloss="Translations to be checked"]' ).after( addButton );

} // close initialize function

}; // close translations object

// Remove old translation adding interface if present //$( 'table.translations:not([data-gloss="Translations to be checked"]) tr:last-child' ).remove;

$( document ).ready( translations.initialize ); } ); // close mw.loader } // close if //