diff options
Diffstat (limited to 'MLEB/Translate/resources/js/ext.translate.special.pagemigration.js')
-rw-r--r-- | MLEB/Translate/resources/js/ext.translate.special.pagemigration.js | 117 |
1 files changed, 59 insertions, 58 deletions
diff --git a/MLEB/Translate/resources/js/ext.translate.special.pagemigration.js b/MLEB/Translate/resources/js/ext.translate.special.pagemigration.js index 3713ac56..19b5651d 100644 --- a/MLEB/Translate/resources/js/ext.translate.special.pagemigration.js +++ b/MLEB/Translate/resources/js/ext.translate.special.pagemigration.js @@ -54,18 +54,18 @@ titles: pageTitle } ).then( function ( data ) { var pageContent, oldTranslationUnits, obj, page, - errorBox = $( '.mw-tpm-sp-error__message' ); + $errorBox = $( '.mw-tpm-sp-error__message' ); for ( page in data.query.pages ) { obj = data.query.pages[ page ]; } - if ( typeof obj === undefined ) { + if ( obj === undefined ) { // obj was not initialized - errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).show( 'fast' ); return $.Deferred().reject(); } if ( obj.revisions === undefined ) { // the case of /en subpage where first edit is by FuzzyBot - errorBox.text( mw.msg( 'pm-old-translations-missing', pageTitle ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-old-translations-missing', pageTitle ) ).show( 'fast' ); return $.Deferred().reject(); } pageContent = obj.revisions[ 0 ][ '*' ]; @@ -96,18 +96,18 @@ } ).then( function ( data ) { var timestampFB, dateFB, timestampOld, page, obj, - errorBox = $( '.mw-tpm-sp-error__message' ); + $errorBox = $( '.mw-tpm-sp-error__message' ); for ( page in data.query.pages ) { obj = data.query.pages[ page ]; } // Page does not exist if missing field is present - if ( obj.missing === '' ) { - errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).show( 'fast' ); + if ( obj === undefined || obj.missing === '' ) { + $errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).show( 'fast' ); return $.Deferred().reject(); } // Page exists, but no edit by FuzzyBot if ( obj.revisions === undefined ) { - errorBox.text( mw.msg( 'pm-old-translations-missing', pageTitle ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-old-translations-missing', pageTitle ) ).show( 'fast' ); return $.Deferred().reject(); } else { // FB over here refers to FuzzyBot @@ -142,7 +142,7 @@ var result, i, sUnit, key; sourceUnits = []; result = data.query.messagecollection; - for ( i = 1; i < result.length; i++ ) { + for ( i = 0; i < result.length; i++ ) { sUnit = {}; key = result[ i ].key; sUnit.identifier = key.slice( key.lastIndexOf( '/' ) + 1 ); @@ -205,15 +205,15 @@ */ function createNewUnit( sourceText, targetText ) { - var newUnit, sourceUnit, targetUnit, actionUnit; + var $newUnit, $sourceUnit, $targetUnit, $actionUnit; - newUnit = $( '<div>' ).addClass( 'mw-tpm-sp-unit row' ); - sourceUnit = $( '<textarea>' ).addClass( 'mw-tpm-sp-unit__source five columns' ) + $newUnit = $( '<div>' ).addClass( 'mw-tpm-sp-unit row' ); + $sourceUnit = $( '<textarea>' ).addClass( 'mw-tpm-sp-unit__source five columns' ) .prop( 'readonly', true ).attr( 'tabindex', '-1' ).val( sourceText ); - targetUnit = $( '<textarea>' ).addClass( 'mw-tpm-sp-unit__target five columns' ) + $targetUnit = $( '<textarea>' ).addClass( 'mw-tpm-sp-unit__target five columns' ) .val( targetText ).prop( 'dir', $.uls.data.getDir( langCode ) ); - actionUnit = $( '<div>' ).addClass( 'mw-tpm-sp-unit__actions two columns' ); - actionUnit.append( + $actionUnit = $( '<div>' ).addClass( 'mw-tpm-sp-unit__actions two columns' ); + $actionUnit.append( $( '<span>' ).addClass( 'mw-tpm-sp-action mw-tpm-sp-action--add' ) .attr( 'title', mw.msg( 'pm-add-icon-hover-text' ) ), $( '<span>' ).addClass( 'mw-tpm-sp-action mw-tpm-sp-action--swap' ) @@ -221,8 +221,8 @@ $( '<span>' ).addClass( 'mw-tpm-sp-action mw-tpm-sp-action--delete' ) .attr( 'title', mw.msg( 'pm-delete-icon-hover-text' ) ) ); - newUnit.append( sourceUnit, targetUnit, actionUnit ); - return newUnit; + $newUnit.append( $sourceUnit, $targetUnit, $actionUnit ); + return $newUnit; } /** @@ -232,14 +232,14 @@ * @param {Array} translations */ function displayUnits( sourceUnits, translations ) { - var i, totalUnits, newUnit, unitListing, + var i, totalUnits, $newUnit, $unitListing, sourceText, targetText; noOfSourceUnits = sourceUnits.length; noOfTranslationUnits = translations.length; totalUnits = noOfSourceUnits > noOfTranslationUnits ? noOfSourceUnits : noOfTranslationUnits; - unitListing = $( '.mw-tpm-sp-unit-listing' ); - unitListing.html( '' ); + $unitListing = $( '.mw-tpm-sp-unit-listing' ); + $unitListing.html( '' ); for ( i = 0; i < totalUnits; i++ ) { sourceText = targetText = ''; if ( sourceUnits[ i ] !== undefined ) { @@ -248,8 +248,8 @@ if ( translations[ i ] !== undefined ) { targetText = translations[ i ]; } - newUnit = createNewUnit( sourceText, targetText ); - unitListing.append( newUnit ); + $newUnit = createNewUnit( sourceText, targetText ); + $unitListing.append( $newUnit ); } } @@ -260,7 +260,7 @@ * @return {string[]} Array having the headers split into new unit */ function splitHeaders( translations ) { - return $.map( translations, function ( elem ) { + return translations.map( function ( elem ) { // Check https://regex101.com/r/oT7fZ2 for details return elem.match( /(^==.+$|(?:(?!^==).+\n?)+)/gm ); } ); @@ -364,6 +364,7 @@ $( '.mw-tpm-sp-instructions' ).text( mw.msg( 'pm-on-save-message-text' ) ).show( 'fast' ); } ).fail( function ( errmsg ) { $( 'input' ).prop( 'disabled', false ); + // eslint-disable-next-line mediawiki/msg-doc $( '.mw-tpm-sp-error__message' ).text( mw.msg( errmsg ) ).show( 'fast' ); } ); } @@ -387,17 +388,17 @@ * @param {jQuery.Event} event */ function addHandler( event ) { - var nextRow, text, newUnit, targetUnit; - - nextRow = $( event.target ).closest( '.mw-tpm-sp-unit' ).next(); - targetUnit = nextRow.find( '.mw-tpm-sp-unit__target' ); - text = targetUnit.val(); - targetUnit.val( '' ); - nextRow = nextRow.next(); - text = shiftRowsDown( nextRow, text ); + var $nextRow, text, $newUnit, $targetUnit; + + $nextRow = $( event.target ).closest( '.mw-tpm-sp-unit' ).next(); + $targetUnit = $nextRow.find( '.mw-tpm-sp-unit__target' ); + text = $targetUnit.val(); + $targetUnit.val( '' ); + $nextRow = $nextRow.next(); + text = shiftRowsDown( $nextRow, text ); if ( text ) { - newUnit = createNewUnit( '', text ); - $( '.mw-tpm-sp-unit-listing' ).append( newUnit ); + $newUnit = createNewUnit( '', text ); + $( '.mw-tpm-sp-unit-listing' ).append( $newUnit ); } noOfTranslationUnits += 1; } @@ -409,14 +410,14 @@ * @param {jQuery.Event} event */ function deleteHandler( event ) { - var sourceText, rowUnit; - rowUnit = $( event.target ).closest( '.mw-tpm-sp-unit' ); - sourceText = rowUnit.find( '.mw-tpm-sp-unit__source' ).val(); + var sourceText, $rowUnit; + $rowUnit = $( event.target ).closest( '.mw-tpm-sp-unit' ); + sourceText = $rowUnit.find( '.mw-tpm-sp-unit__source' ).val(); if ( !sourceText ) { - rowUnit.remove(); + $rowUnit.remove(); } else { - rowUnit.find( '.mw-tpm-sp-unit__target' ).val( '' ); - shiftRowsUp( rowUnit ); + $rowUnit.find( '.mw-tpm-sp-unit__target' ).val( '' ); + shiftRowsUp( $rowUnit ); } noOfTranslationUnits -= 1; } @@ -428,12 +429,12 @@ * @param {jQuery.Event} event */ function swapHandler( event ) { - var rowUnit, tempText, nextVal; - rowUnit = $( event.target ).closest( '.mw-tpm-sp-unit' ); - tempText = rowUnit.find( '.mw-tpm-sp-unit__target' ).val(); - nextVal = rowUnit.next().find( '.mw-tpm-sp-unit__target' ).val(); - rowUnit.find( '.mw-tpm-sp-unit__target' ).val( nextVal ); - rowUnit.next().find( '.mw-tpm-sp-unit__target' ).val( tempText ); + var $rowUnit, tempText, nextVal; + $rowUnit = $( event.target ).closest( '.mw-tpm-sp-unit' ); + tempText = $rowUnit.find( '.mw-tpm-sp-unit__target' ).val(); + nextVal = $rowUnit.next().find( '.mw-tpm-sp-unit__target' ).val(); + $rowUnit.find( '.mw-tpm-sp-unit__target' ).val( nextVal ); + $rowUnit.next().find( '.mw-tpm-sp-unit__target' ).val( tempText ); } /** @@ -444,21 +445,21 @@ */ function importHandler( e ) { var pageTitle, slashPos, titleObj, - errorBox = $( '.mw-tpm-sp-error__message' ), - messageBox = $( '.mw-tpm-sp-instructions' ); + $errorBox = $( '.mw-tpm-sp-error__message' ), + $messageBox = $( '.mw-tpm-sp-instructions' ); e.preventDefault(); pageTitle = $( '#title' ).val().trim(); if ( pageTitle === '' ) { - errorBox.text( mw.msg( 'pm-pagetitle-missing' ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-pagetitle-missing' ) ).show( 'fast' ); return; } titleObj = mw.Title.newFromText( pageTitle ); - messageBox.hide( 'fast' ); + $messageBox.hide( 'fast' ); if ( titleObj === null ) { - errorBox.text( mw.msg( 'pm-pagetitle-invalid' ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-pagetitle-invalid' ) ).show( 'fast' ); return; } @@ -466,7 +467,7 @@ slashPos = pageTitle.lastIndexOf( '/' ); if ( slashPos === -1 ) { - errorBox.text( mw.msg( 'pm-langcode-missing' ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-langcode-missing' ) ).show( 'fast' ); return; } @@ -474,11 +475,11 @@ langCode = pageTitle.substring( slashPos + 1 ); if ( pageName === '' ) { - errorBox.text( mw.msg( 'pm-pagetitle-invalid' ) ).show( 'fast' ); + $errorBox.text( mw.msg( 'pm-pagetitle-invalid' ) ).show( 'fast' ); return; } - errorBox.hide( 'fast' ); + $errorBox.hide( 'fast' ); $.when( getSourceUnits( pageName ), getFuzzyTimestamp( pageTitle ) ) .then( function ( sourceUnits, fuzzyTimestamp ) { @@ -490,7 +491,7 @@ displayUnits( sourceUnits, translationUnits ); $( '#action-save, #action-cancel' ).removeClass( 'hide' ); $( '#action-import' ).addClass( 'hide' ); - messageBox.text( mw.msg( 'pm-on-import-message-text' ) ).show( 'fast' ); + $messageBox.text( mw.msg( 'pm-on-import-message-text' ) ).show( 'fast' ); } ); } ); } @@ -501,10 +502,10 @@ function listen() { var $listing = $( '.mw-tpm-sp-unit-listing' ); - $( '#mw-tpm-sp-primary-form' ).submit( importHandler ); - $( '#action-import' ).click( importHandler ); - $( '#action-save' ).click( saveHandler ); - $( '#action-cancel' ).click( cancelHandler ); + $( '#mw-tpm-sp-primary-form' ).on( 'submit', importHandler ); + $( '#action-import' ).on( 'click', importHandler ); + $( '#action-save' ).on( 'click', saveHandler ); + $( '#action-cancel' ).on( 'click', cancelHandler ); $listing.on( 'click', '.mw-tpm-sp-action--swap', swapHandler ); $listing.on( 'click', '.mw-tpm-sp-action--delete', deleteHandler ); $listing.on( 'click', '.mw-tpm-sp-action--add', addHandler ); |