Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/370087 )
Change subject: Page.js getLeadSectionElement ...................................................................... Page.js getLeadSectionElement * Add tests * When pages are not mobile formatted return entire content as lead - this avoids breakages with editor and page issues Change-Id: I41e4ff1c35425b69a0fb8f007cc0c2a1b1a1c6a5 --- M resources/mobile.startup/Page.js M tests/qunit/mobile.startup/test_Page.js 2 files changed, 19 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/87/370087/1 diff --git a/resources/mobile.startup/Page.js b/resources/mobile.startup/Page.js index ab7ecfa..9668d84 100644 --- a/resources/mobile.startup/Page.js +++ b/resources/mobile.startup/Page.js @@ -104,6 +104,8 @@ /** * Get the lead section of the page view. + * If it's impossible to locate any sections in the page via HTML markup, the element that + * represents the entire page content is returned. * @method * @return {jQuery.Object|null} */ @@ -119,15 +121,11 @@ * </div> * </div> */ - if ( $( '.mf-section-0' ).length ) { - return $( '.mf-section-0' ); - } - // for cached pages that are still using mw-mobilefrontend-leadsection - if ( $( '.mw-mobilefrontend-leadsection' ).length ) { - return $( '.mw-mobilefrontend-leadsection' ); + if ( this.$( '.mf-section-0' ).length ) { + return this.$( '.mf-section-0' ); } // no lead section found - return null; + return this.$el; }, /** diff --git a/tests/qunit/mobile.startup/test_Page.js b/tests/qunit/mobile.startup/test_Page.js index 58f31ed..6460184 100644 --- a/tests/qunit/mobile.startup/test_Page.js +++ b/tests/qunit/mobile.startup/test_Page.js @@ -15,6 +15,20 @@ assert.strictEqual( p2.isMainPage(), false, 'check not marked as main page' ); } ); + QUnit.test( '#getLeadSectionElement', 2, function ( assert ) { + var nonMobileFormattedPage, formattedPage; + nonMobileFormattedPage = new Page( { + el: $( '<div id="bodyContent" class="content"><div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div class="mw-parser-output"><h2 class="section-heading"><span class="mw-headline" id="Test">Test</span><span><a href="/w/index.php?title=No_lead&action=edit&section=1" title="Edit section: Test" data-section="1" class="mw-ui-icon mw-ui-icon-element mw-ui-icon-edit-enabled edit-page">Edit</a></span></h2><p>Hello</p></div></div></div>' ) + } ); + formattedPage = new Page( { + el: $( '<div id="bodyContent" class="content"><div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div class="mw-parser-output"><div class="mf-section-0" id="mf-section-0"></div><h2 class="in-block section-heading collapsible-heading open-block" tabindex="0" aria-haspopup="true" aria-controls="content-collapsible-block-0"><div class="mw-ui-icon mw-ui-icon-arrow mw-ui-icon-element mf-mw-ui-icon-rotate-flip indicator" title=""></div><span class="mw-headline" id="Test">Test</span><span><a href="/w/index.php?title=No_lead&action=edit&section=1" title="Edit section: Test" data-section="1" class="mw-ui-icon mw-ui-icon-element mw-ui-icon-edit-enabled edit-page">Edit</a></span></h2><div class="mf-section-1 collapsible-block open-block" id="content-collapsible-block-0" aria-pressed="true" aria-expanded="true"><p>Hello</p></div></div></div>' ) + } ); + assert.strictEqual( nonMobileFormattedPage.getLeadSectionElement().attr( 'class' ) + , 'mw-parser-output', 'When no sections found, return the entire page content.' ); + assert.strictEqual( nonMobileFormattedPage.getLeadSectionElement().attr( 'class' ) + , 'mf-section-0', 'When no sections found, return the entire page content.' ); + } ); + QUnit.test( '#getThumbnails', 11, function ( assert ) { var p, textPage, pLegacyUrls, thumbs, pNoViewer, pMetadata, pLazyImages, metadataTable, pLazyImagesTypo, pMetadataNested; -- To view, visit https://gerrit.wikimedia.org/r/370087 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I41e4ff1c35425b69a0fb8f007cc0c2a1b1a1c6a5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits