Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/194838
Change subject: Correct the way section headers are added ...................................................................... Correct the way section headers are added Use appropriate hook to trigger adding secton headers instead of using click event. While adding reference list using hook, the section header for reference list was not getting added. Now it get added. Change-Id: I69f58d109b22471ea3c83c0abcc12ebc449abffd --- M modules/translation/ext.cx.translation.js 1 file changed, 23 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/38/194838/1 diff --git a/modules/translation/ext.cx.translation.js b/modules/translation/ext.cx.translation.js index 2be5fc2..e64f469 100644 --- a/modules/translation/ext.cx.translation.js +++ b/modules/translation/ext.cx.translation.js @@ -114,6 +114,7 @@ var cxTranslation = this; mw.hook( 'mw.cx.translation.add' ).add( $.proxy( this.applyTranslationTemplate, this ) ); + mw.hook( 'mw.cx.translation.add' ).add( $.proxy( this.addSectionHeader, this ) ); mw.hook( 'mw.cx.translation.postMT' ).add( $.proxy( this.postProcessMT, this ) ); mw.hook( 'mw.cx.source.loaded' ).add( function () { // Delay adding placeholders. If we calculate the section @@ -278,7 +279,7 @@ * @param {string} tagName * @return {boolean} */ - ContentTranslationEditor.isHeading = function ( tagName ) { + ContentTranslationEditor.prototype.isHeading = function ( tagName ) { return /^H[1-6]$/i.test( tagName ); }; @@ -290,14 +291,14 @@ * @param {string} current tagName * @return {boolean} */ - ContentTranslationEditor.isParentHeading = function ( preceding, current ) { + ContentTranslationEditor.prototype.isParentHeading = function ( preceding, current ) { // Any header goes if this is a non-heading - if ( !ContentTranslationEditor.isHeading( current ) ) { - return ContentTranslationEditor.isHeading( preceding ); + if ( !this.isHeading( current ) ) { + return this.isHeading( preceding ); } // Both are headings, check that the previous one is bigger - if ( ContentTranslationEditor.isHeading( preceding ) ) { + if ( this.isHeading( preceding ) ) { return preceding < current; } @@ -305,30 +306,34 @@ return false; }; - function sectionClick() { - /*jshint validthis:true */ - var sourceSectionId, $currentSection, $previousSection; + /** + * Fill in the preceding parent heading, if not yet filled + * @param {string} sectionId Source section Id + */ + ContentTranslationEditor.prototype.addSectionHeader = function ( sectionId ) { + var $currentSection, $previousSection; - $currentSection = $( this ); + $currentSection = mw.cx.getTranslationSection( sectionId ); $previousSection = $currentSection.prev(); - sourceSectionId = $currentSection.data( 'source' ); - - // The equivalent section in source column - mw.cx.getSourceSection( sourceSectionId ).removeClass( 'cx-highlight' ); - - // Fill in the preceding parent heading, if not yet filled - // TODO: This must be triggerd by 'mw.cx.translation.add' hook and not by - // a click to allow programmatically add sections and get consistent behavior if ( $previousSection.is( '.placeholder' ) && - ContentTranslationEditor.isParentHeading( + this.isParentHeading( $previousSection.data( 'cx-section-type' ), $currentSection.data( 'cx-section-type' ) ) ) { mw.hook( 'mw.cx.translation.add' ).fire( $previousSection.data( 'source' ), 'click' ); } + }; + function sectionClick() { + var sourceSectionId, + /*jshint validthis:true */ + $currentSection = $( this ); + + sourceSectionId = $currentSection.data( 'source' ); + // The equivalent section in source column + mw.cx.getSourceSection( sourceSectionId ).removeClass( 'cx-highlight' ); mw.hook( 'mw.cx.translation.add' ).fire( sourceSectionId, 'click' ); } -- To view, visit https://gerrit.wikimedia.org/r/194838 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I69f58d109b22471ea3c83c0abcc12ebc449abffd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits