Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86966
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, 49 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/66/86966/1
diff --git a/javascripts/common/PageApi.js b/javascripts/common/PageApi.js
index 5905927..510457a 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -3,10 +3,18 @@
var Api = M.require( 'api' ).Api, PageApi;
function transformSections( sections ) {
- var result = [], $tmpContainer = $( '<div>' );
+ var
+ collapseLevel = '2',
+ result = [], $tmpContainer = $( '<div>' );
+ // FIXME: should be possible to do this in a single loop
$.each( sections, function( i, section ) {
- if ( !section.level || section.level === '2' ) {
+ if ( section.level === '1' ) {
+ collapseLevel = '1';
+ }
+ } );
+ $.each( sections, function( i, section ) {
+ 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: newchange
Gerrit-Change-Id: I8cbabc5b758d525327012dc6798e2bdee497a3da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits