jenkins-bot has submitted this change and it was merged.
Change subject: Make lazy loaded pages containing h1s collapse on h1s
......................................................................
Make lazy loaded pages containing h1s collapse on h1s
This makes it consistent with the page html
Bug: 54608
Change-Id: I8cbabc5b758d525327012dc6798e2bdee497a3da
---
M javascripts/common/PageApi.js
M tests/javascripts/common/test_PageApi.js
2 files changed, 43 insertions(+), 2 deletions(-)
Approvals:
MaxSem: Looks good to me, but someone else must approve
JGonera: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/common/PageApi.js b/javascripts/common/PageApi.js
index 5905927..2ef8c2f 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -3,10 +3,12 @@
var Api = M.require( 'api' ).Api, PageApi;
function transformSections( sections ) {
- var result = [], $tmpContainer = $( '<div>' );
+ var
+ collapseLevel = Math.min.apply( this, $.map( sections,
function( s ) { return s.level; } ) ) + '',
+ result = [], $tmpContainer = $( '<div>' );
$.each( sections, function( i, section ) {
- if ( !section.level || section.level === '2' ) {
+ if ( !section.level || section.level === collapseLevel
) {
result.push( section );
} else {
// FIXME: ugly, maintain structure returned by
API and use templates instead
diff --git a/tests/javascripts/common/test_PageApi.js
b/tests/javascripts/common/test_PageApi.js
index 849067c..37d0cd4 100644
--- a/tests/javascripts/common/test_PageApi.js
+++ b/tests/javascripts/common/test_PageApi.js
@@ -7,6 +7,45 @@
}
} );
+ QUnit.test( '#getPage (h1s)', 1, function( assert ) {
+ sinon.stub( PageApi.prototype, 'get' ).returns(
$.Deferred().resolve( {
+ "mobileview": {
+ "sections":[
+ {"id":0,"text":""},
+
{"level":"1","line":"1","anchor":"1","id":1,"text":"<p>Text of 1\n</p>"},
+
{"level":"2","line":"1.1","anchor":"1.1","id":2,"text":"<p>Text of 1.1\n</p>"},
+
{"level":"1","line":"2","anchor":"2","id":3,"text":"<p>Text of 2\n</p>"},
+
{"level":"2","line":"2.1","anchor":"2.1","id":4,"text":"<p>Text of 2.1\n</p>"} ]
+ }
+ } ) );
+
+ pageApi.getPage( 'Test' ).done( function( resp ) {
+ assert.deepEqual( resp, {
+ title: 'Test',
+ id: -1,
+ isMainPage: false,
+ lead: '',
+ sections: [
+ {
+ "level": "1",
+ "line": "1",
+ "anchor": "1",
+ "id": 1,
+ "text": '<p>Text of 1\n</p><h2
id="1.1">1.1</h2><p>Text of 1.1\n</p>'
+ },
+ {
+ "level": "1",
+ "line": "2",
+ "anchor": "2",
+ "id": 3,
+ "text": '<p>Text of 2\n</p><h2
id="2.1">2.1</h2><p>Text of 2.1\n</p>'
+ }
+ ]
+ }, 'return lead and sections' );
+ } );
+ PageApi.prototype.get.restore();
+ } );
+
QUnit.test( '#getPage', 2, function( assert ) {
sinon.stub( PageApi.prototype, 'get' ).returns(
$.Deferred().resolve( {
"mobileview": {
--
To view, visit https://gerrit.wikimedia.org/r/86966
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8cbabc5b758d525327012dc6798e2bdee497a3da
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits