Amire80 has uploaded a new change for review. https://gerrit.wikimedia.org/r/150796
Change subject: Cleanup whitespace ...................................................................... Cleanup whitespace Change-Id: Iea3d46de2e5c814821bc71656eccf0ac6343b913 --- M modules/tools/ext.cx.progressbar.js M modules/tools/ext.cx.tools.js M modules/tools/ext.cx.tools.mtabuse.js M modules/translation/ext.cx.translation.progress.js 4 files changed, 75 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/96/150796/1 diff --git a/modules/tools/ext.cx.progressbar.js b/modules/tools/ext.cx.progressbar.js index 7875fff..aa71847 100644 --- a/modules/tools/ext.cx.progressbar.js +++ b/modules/tools/ext.cx.progressbar.js @@ -29,20 +29,22 @@ }; ProgressBar.prototype.render = function () { - this.$container.append( - $( '<div>' ) + this.$container.append( $( '<div>' ) .addClass( 'cx-progressbar' ) .append( $( '<span>' ).addClass( 'cx-progressbar__bar' ), $( '<span>' ).addClass( 'cx-progressbar__bar--mt' ) ) ); + this.$info = $( '<div>' ) .addClass( 'cx-progressbar__info' ) - .append( $( '<div>' ) - .addClass( 'cx-progressbar__info--total' ), + .append( $( '<div>' ) - .addClass( 'cx-progressbar__info--mt' ) ); + .addClass( 'cx-progressbar__info--total' ), + $( '<div>' ) + .addClass( 'cx-progressbar__info--mt' ) + ); this.$container.append( this.$info.hide() ); this.$bar = this.$container.find( '.cx-progressbar__bar' ); @@ -52,10 +54,13 @@ ProgressBar.prototype.listen = function () { var progressBar = this; + mw.hook( 'mw.cx.progress' ).add( $.proxy( this.update, this ) ); + this.$container.on( 'mouseenter', '.cx-progressbar', function () { progressBar.$info.show(); } ); + this.$container.on( 'mouseleave', '.cx-progressbar', function () { progressBar.$info.hide(); } ); @@ -67,12 +72,18 @@ mtPercentage = parseInt( mtPercentage, 10 ); this.$bar.css( 'width', this.status + '%' ); this.$mtbar.css( 'width', mtPercentage + '%' ); + this.$info.find( '.cx-progressbar__info--total' ) - .text( mw.msg( 'cx-header-progressbar-text', - mw.language.convertNumber( percentage ) ) ); + .text( mw.msg( + 'cx-header-progressbar-text', + mw.language.convertNumber( percentage ) + ) ); + this.$info.find( '.cx-progressbar__info--mt' ) - .text( mw.msg( 'cx-header-progressbar-text-mt', - mw.language.convertNumber( mtPercentage ) ) ); + .text( mw.msg( + 'cx-header-progressbar-text-mt', + mw.language.convertNumber( mtPercentage ) + ) ); }; $.fn.cxProgressBar = function ( options ) { diff --git a/modules/tools/ext.cx.tools.js b/modules/tools/ext.cx.tools.js index b8b65c2..b84da80 100644 --- a/modules/tools/ext.cx.tools.js +++ b/modules/tools/ext.cx.tools.js @@ -25,6 +25,7 @@ ContentTranslationTools.prototype.init = function () { this.render(); this.$toolsContainer.cxtoolmanager(); + // Handle enter key press in the search field. this.$searchBox.find( 'input' ).keypress( function ( event ) { if ( event.which === 13 ) { @@ -33,27 +34,34 @@ mw.hook( 'mw.cx.search.link' ).fire( text ); } } ); + mw.hook( 'mw.cx.tools.ready' ).fire(); }; ContentTranslationTools.prototype.render = function () { - var $progressBar, $loadingIndicator, $search; + var $progressBar, $search, $loadingIndicator; this.$searchBox = $( '<div>' ) .addClass( 'card search cx-tools--container' ); + this.$toolsContainer = $( '<div>' ) .addClass( 'cx-tools--container' ); + $progressBar = $( '<div>' ) .addClass( 'cx-header__progressbar' ) .cxProgressBar(); + $search = $( '<input>' ) .addClass( 'tools-words-search box' ) .attr( { placeholder: mw.msg( 'cx-tools-searchbox-text' ), type: 'search' } ); + this.$searchBox.append( $search ); + $loadingIndicator = getLoadingIndicator(); + this.$container.append( $progressBar, this.$searchBox, @@ -68,7 +76,8 @@ .append( $( '<div>' ).addClass( 'bounce1' ), $( '<div>' ).addClass( 'bounce2' ), - $( '<div>' ).addClass( 'bounce3' ) ) + $( '<div>' ).addClass( 'bounce3' ) + ) .hide(); } @@ -84,7 +93,7 @@ ContentTranslationTools.prototype.scroll = function () { var scrollTop = $( window ).scrollTop(), - // Use the .prev() element as the reference point(anchor) + // Use the .prev() element as the reference point (anchor) offsetTop = this.$container.prev().offset().top; if ( scrollTop > offsetTop ) { @@ -98,11 +107,10 @@ return this.each( function () { var $this = $( this ), data = $this.data( 'cxTools' ); + if ( !data ) { $this.data( 'cxTools', ( data = new ContentTranslationTools( this ) ) ); } - } ); }; - }( jQuery, mediaWiki ) ); diff --git a/modules/tools/ext.cx.tools.mtabuse.js b/modules/tools/ext.cx.tools.mtabuse.js index 8d98f2a..bbd0831 100644 --- a/modules/tools/ext.cx.tools.mtabuse.js +++ b/modules/tools/ext.cx.tools.mtabuse.js @@ -33,7 +33,7 @@ target: '_blank' } ) .text( mw.msg( 'cx-tools-view-guidelines' ) ) - ); + ); }; MTAbuseCard.prototype.onShow = function () { @@ -46,9 +46,14 @@ MTAbuseCard.prototype.start = function ( mtPercentage ) { this.$card.show(); + mtPercentage = parseInt( mtPercentage, 10 ); this.$card.find( '.card__mtabuse-title' ) - .text( mw.msg( 'cx-mt-abuse-warning-title', mw.language.convertNumber( mtPercentage ) ) ); + .text( mw.msg( + 'cx-mt-abuse-warning-title', + mw.language.convertNumber( mtPercentage ) ) + ); + this.onShow(); }; diff --git a/modules/translation/ext.cx.translation.progress.js b/modules/translation/ext.cx.translation.progress.js index 8ab5854..35c0061 100644 --- a/modules/translation/ext.cx.translation.progress.js +++ b/modules/translation/ext.cx.translation.progress.js @@ -15,8 +15,8 @@ translationThreshold = 0.05; /** - * Get the total source weight - * @return {int} total source weight + * Get the total source weight. + * @return {int} Total source weight */ function getTotalSourceWeight() { var $sourceContainer, @@ -25,6 +25,7 @@ if ( totalSourceWeight ) { return totalSourceWeight; } + $sourceContainer = $( '.cx-column--source .cx-column__content' ); $sections = $sourceContainer.children( mw.cx.getSectionSelector() ); @@ -36,11 +37,12 @@ } /** - * Calculate the translation progress + * Calculate the translation progress. */ function showProgress() { var percentage = getTranslationProgress(), mtPercentage = getMachineTranslationPercentage(); + mw.hook( 'mw.cx.progress' ).fire( percentage, mtPercentage ); if ( mtPercentage > 75 ) { mw.hook( 'mw.cx.warning.mtabuse' ).fire( mtPercentage ); @@ -48,70 +50,82 @@ } /** - * Calculate the percentage of machine translation + * Calculate the percentage of machine translation. * @return {float} percentage */ function getMachineTranslationPercentage() { - var completedTranslation = 0, - sourceWeight, - percentage; + var sourceWeight, + percentage, + completedTranslation = 0; $( '.cx-column--translation [data-cx-weight]' ).each( function () { - if ( $( this ).data( 'cx-mt' ) === true ) { - completedTranslation += $( this ).data( 'cx-weight' ); + var $this = $( this ); + + if ( $this.data( 'cx-mt' ) === true ) { + completedTranslation += $this.data( 'cx-weight' ); } } ); + sourceWeight = getTotalSourceWeight(); if ( sourceWeight === 0 ) { return 0; } + percentage = ( completedTranslation / sourceWeight ) * 100; + return percentage; } /** - * Calculate the translation progress + * Calculate the translation progress. * @return {float} percentage */ function getTranslationProgress() { - var completedTranslation = 0, - sourceWeight, - percentage; + var sourceWeight, + percentage, + completedTranslation = 0; $( '.cx-column--translation [data-cx-weight]' ).each( function () { - if ( $( this ).data( 'cx-mt' ) === false ) { - completedTranslation += $( this ).data( 'cx-weight' ); + var $this = $( this ); + + if ( $this.data( 'cx-mt' ) === false ) { + completedTranslation += $this.data( 'cx-weight' ); } } ); + sourceWeight = getTotalSourceWeight(); if ( sourceWeight === 0 ) { return 0; } + percentage = ( completedTranslation / sourceWeight ) * 100; + return percentage; } /** - * Update/Change handler for section + * Update/Change handler for section. * @param {jQuery} $section The source section */ function onSectionUpdate( $section ) { - var $sourceSection, sourceLength, translationLength; + var $sourceSection, translationLength, sourceLength; if ( !$section ) { return; } + $sourceSection = $( '#' + $section.data( 'source' ) ); translationLength = $section.text().length; sourceLength = $sourceSection.text().length; - // Check if the translation is above the defined threshold to count. + // Check if the translation is above the defined threshold to count if ( translationLength / sourceLength < translationThreshold ) { // Do not count the section as translated $section.removeAttr( 'data-cx-weight' ); } else { $section.attr( 'data-cx-weight', sourceLength ); } + // Calculate the total translation progress showProgress(); } @@ -119,9 +133,10 @@ $( function () { mw.hook( 'mw.cx.translation.change' ).add( onSectionUpdate ); window.onbeforeunload = function () { - // Check if progress is greater than 1% + // Check if the progress is greater than 1% if ( parseInt( getTranslationProgress(), 10 ) > 0 || - parseInt( getMachineTranslationPercentage(), 10 ) > 0 ) { + parseInt( getMachineTranslationPercentage(), 10 ) > 0 + ) { return mw.msg( 'cx-warning-unsaved-translation' ); } }; -- To view, visit https://gerrit.wikimedia.org/r/150796 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iea3d46de2e5c814821bc71656eccf0ac6343b913 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits