Fix editing of non-mobile-formatted pages

Template pages do not run the MobileFormatter
(see MFMobileFormatterNamespaceBlacklist).

As a result page.getLeadSectionElement() will
return null

When this happens do not change the edit icon to point
to section 1. Instead give them the non-JS editor.

After this patch, the feature remains as:

* Page with lead section get the JS edit overlay for section 0
* Page without lead section but with other sections gets the JS overlay
  editor for section 1
* Pages that didn't run through MobileFormatter don't modify the edit
  link and just link to the fallback editor (useful for Template pages
  at this moment)

Bug: T172948
Change-Id: Icee96e12f62ec13a1cbd3169c687fa4b3af70754
This commit is contained in:
jdlrobson 2018-01-29 11:12:54 -08:00 committed by Jdlrobson
parent 351512265b
commit 6cdcc8ddfa

View file

@ -46,6 +46,7 @@
}
/**
* Prepend an edit page button to the container
* Remove any existing links in the container
* @method
* @ignore
* @param {number} section number
@ -53,6 +54,7 @@
* @return {jQuery.Object} newly created edit page button
*/
function addEditButton( section, container ) {
$( container ).find( 'a' ).remove();
return $( '<a class="edit-page">' )
.attr( {
href: '#/editor/' + section,
@ -256,15 +258,17 @@
// FIXME: split the selector and cache it
if ( $caEdit.find( '.edit-page' ).length === 0 ) {
$( '.nojs-edit' ).removeClass( 'nojs-edit' );
$( '#ca-edit a' ).remove();
if ( isNewPage ||
( leadSection && leadSection.text() ) || page.getSections().length === 0 ) {
// if lead section is not empty, open editor with lead section
// In some namespaces (controlled by MFNamespacesWithoutCollapsibleSections)
// sections are not marked. Use the lead section for such cases.
addEditButton( 0, '#ca-edit' );
} else {
// if lead section is empty or does not exist, open editor with first section
} else if ( leadSection !== null ) {
// if lead section is empty open editor with first section
// be careful not to do this when leadSection is null as this means MobileFormatter has not
// been run and thus we could not identify the lead
addEditButton( 1, '#ca-edit' );
}
}