Amire80 has uploaded a new change for review. https://gerrit.wikimedia.org/r/171615
Change subject: Show the header with publish button only in translation view ...................................................................... Show the header with publish button only in translation view Change-Id: I463349cceb4b45a295a5ab0ce6261707731db6a0 --- M modules/header/ext.cx.header.js 1 file changed, 48 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/15/171615/1 diff --git a/modules/header/ext.cx.header.js b/modules/header/ext.cx.header.js index be59b3c..abcb414 100644 --- a/modules/header/ext.cx.header.js +++ b/modules/header/ext.cx.header.js @@ -22,8 +22,11 @@ this.$container = $( element ); this.siteMapper = siteMapper; - this.$publishButton = null; + this.$headerTitle = null; + this.$headerBar = null; this.$infoBar = null; + + this.$publishButton = null; this.init(); } @@ -38,7 +41,11 @@ * @param {object} weights */ ContentTranslationHeader.prototype.setPublishButtonState = function ( weights ) { - this.$publishButton.show().prop( 'disabled', weights.any === 0 ); + if ( this.$publishButton ) { + this.$publishButton + .prop( 'disabled', weights.any === 0 ) + .show(); + } }; /** @@ -129,10 +136,6 @@ }; ContentTranslationHeader.prototype.listen = function () { - this.$publishButton.on( 'click', function () { - mw.hook( 'mw.cx.publish' ).fire(); - } ); - // Click handler for remove icon in info bar. this.$infoBar.on( 'click', '.remove', function () { $( this ).parent().hide(); @@ -143,34 +146,25 @@ mw.hook( 'mw.cx.success' ).add( $.proxy( this.showSuccess, this ) ); mw.hook( 'mw.cx.error.anonuser' ).add( $.proxy( this.showLoginMessage, this ) ); mw.hook( 'mw.cx.translation.ready' ).add( $.proxy( this.checkTargetTitle, this ) ); + + // Show the header with the publish button only if the source was loaded, + // i.e. not on dashboard, source selector, etc. + mw.hook( 'mw.cx.source.loaded' ).add( $.proxy( this.renderHeaderBar, this ) ); }; /** - * Render the header + * Render the header bar showing useful links, status and publish button */ - ContentTranslationHeader.prototype.render = function () { - var $logo, $titleText, $headerTitle, - $translationCenterLink, $translationCenter, $publishArea, - $headerBar; + ContentTranslationHeader.prototype.renderHeaderBar = function () { + var $translationCenterArea, $publishArea; - $logo = $( '<a>' ) - .prop( 'href', mw.config.get( 'wgScript' ) ) - .addClass( 'cx-header__logo' ); - $titleText = $( '<span>' ) - .addClass( 'cx-header__title__name' ) - .text( mw.msg( 'cx' ) ); - $headerTitle = $( '<div>' ) - .addClass( 'cx-header__title' ) - .append( $logo, $titleText ); - - $translationCenterLink = $( '<a>' ) - // TODO update the text when the dashboard is ready - .text( mw.msg( 'cx-header-new-translation' ) ) - .attr( 'href', mw.util.getUrl( 'Special:ContentTranslation' ) ); - - $translationCenter = $( '<div>' ) + $translationCenterArea = $( '<div>' ) .addClass( 'cx-header__translation-center' ) - .append( $translationCenterLink ); + .append( $( '<a>' ) + // TODO update the text when the dashboard is ready + .text( mw.msg( 'cx-header-new-translation' ) ) + .attr( 'href', mw.util.getUrl( 'Special:ContentTranslation' ) ) + ); this.$publishButton = $( '<button>' ) .addClass( 'publish mw-ui-button mw-ui-constructive' ) @@ -178,13 +172,36 @@ .text( mw.msg( 'cx-publish-button' ) ) .hide(); + this.$publishButton.on( 'click', function () { + mw.hook( 'mw.cx.publish' ).fire(); + } ); + $publishArea = $( '<div>' ) .addClass( 'cx-header__publish' ) .append( this.$publishButton ); - $headerBar = $( '<div>' ) + this.$headerBar = $( '<div>' ) .addClass( 'cx-header__bar' ) - .append( $translationCenter, $publishArea ); + .append( $translationCenterArea, $publishArea ); + + this.$headerTitle.after( this.$headerBar ); + } + + /** + * Render the header + */ + ContentTranslationHeader.prototype.render = function () { + var $logo, $titleText; + + $logo = $( '<a>' ) + .prop( 'href', mw.config.get( 'wgScript' ) ) + .addClass( 'cx-header__logo' ); + $titleText = $( '<span>' ) + .addClass( 'cx-header__title__name' ) + .text( mw.msg( 'cx' ) ); + this.$headerTitle = $( '<div>' ) + .addClass( 'cx-header__title' ) + .append( $logo, $titleText ); this.$infoBar = $( '<div>' ) .addClass( 'cx-header__infobar' ) @@ -194,7 +211,7 @@ this.$container .addClass( 'cx-header' ) - .append( $headerTitle, $headerBar, this.$infoBar ); + .append( this.$headerTitle, this.$infoBar ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/171615 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I463349cceb4b45a295a5ab0ce6261707731db6a0 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