From 60dd426ee6f078bb530d26b41e3409204e3d97f9 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Fri, 24 Aug 2018 16:32:06 -0700 Subject: [PATCH] Make edit click handling consistent Previously, the main edit icon in the page actions was handled indirectly by changing the URL and then routing the edit via detecting the hash fragment has changed. On the other hand section edit links were hijacked via a click handler. The latter is better as it doesn't modify the DOM, which allows the editor to override the JavaScript behaviour. It's also preferable as it doesn't interfere with EventLogging - this subtle difference was supressing edits to the Edit and PageIssues schema. Bug: T202786 Change-Id: I4175bc6f0ddda28397d185502d1839716d051c56 --- resources/skins.minerva.editor/init.js | 30 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/resources/skins.minerva.editor/init.js b/resources/skins.minerva.editor/init.js index 0831923..a3cce8a 100644 --- a/resources/skins.minerva.editor/init.js +++ b/resources/skins.minerva.editor/init.js @@ -52,6 +52,21 @@ blockInfo = false; } + /** + * Event handler for edit link clicks. Will prevent default link + * behaviour and will not allow propagation + * @method + * @ignore + * @return {boolean} + */ + function onEditLinkClick() { + issues.log( { action: 'editClicked' } ); + + router.navigate( '#/editor/' + $( this ).data( 'section' ) ); + // prevent folding section when clicking Edit by stopping propagation + return false; + } + // TODO: rename addEditSectionButton and evaluate whether the page edit button // can leverage the same code. Also: change the CSS class name to use // the word "section" instead of "page". @@ -67,10 +82,8 @@ function addEditButton( section, container ) { $( container ).find( 'a' ).remove(); return $( '' ) - .attr( { - href: '#/editor/' + section, - title: $( container ).attr( 'title' ) - } ) + .data( 'section', section ) + .on( 'click', onEditLinkClick ) .text( mw.msg( 'mobile-frontend-editor-edit' ) ) .prependTo( container ); } @@ -161,13 +174,8 @@ alert( mw.msg( 'mobile-frontend-editor-undo-unsupported' ) ); } - page.$( '.edit-page, .edit-link' ).removeClass( disabledClass ).on( 'click', function () { - issues.log( { action: 'editClicked' } ); - - router.navigate( '#/editor/' + $( this ).data( 'section' ) ); - // prevent folding section when clicking Edit by stopping propagation - return false; - } ); + page.$( '.edit-page, .edit-link' ).removeClass( disabledClass ) + .on( 'click', onEditLinkClick ); overlayManager.add( /^\/editor\/(\d+|all)$/, function ( sectionId ) { var $content = $( '#mw-content-text' ),