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
This commit is contained in:
jdlrobson 2018-08-24 16:32:06 -07:00 committed by Jdrewniak
parent 5fefa5349e
commit 60dd426ee6
1 changed files with 19 additions and 11 deletions

View File

@ -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 $( '<a class="edit-page">' )
.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' ),