jenkins-bot has submitted this change and it was merged.
Change subject: Fix placement of quick survey
......................................................................
Fix placement of quick survey
* On desktop it will not appears above the first heading and if no
headings are available after the first paragraph.. e.g. stubs and
articles without a lead section
* Checked all browser test pages and no regressions from previous
pages
* Add tests to ensure only one survey gets added after bug in code
review
Note: this doesn't fix any styling issues that might be associated
with the quick surveys, it simply identifies the correct position it
should be located
Bug: T113651
Change-Id: Id8ac93547cde07f45390aad05cac5c61b200c130
---
M resources/ext.quicksurveys.lib/lib.js
M tests/qunit/ext.quicksurveys.lib/templates/vector-4.html
M tests/qunit/ext.quicksurveys.lib/test_lib.js
3 files changed, 43 insertions(+), 5 deletions(-)
Approvals:
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/resources/ext.quicksurveys.lib/lib.js
b/resources/ext.quicksurveys.lib/lib.js
index 486ff4e..6d63139 100644
--- a/resources/ext.quicksurveys.lib/lib.js
+++ b/resources/ext.quicksurveys.lib/lib.js
@@ -19,7 +19,8 @@
var $place;
if ( isMobileLayout ) {
- $place = $bodyContent.find( '> div > p' ).eq( 0 );
+ // Find a paragraph in the first section to insert after
+ $place = $bodyContent.find( '> div' ).eq( 0 ).find( ' >
p' ).eq( 0 );
}
if ( $place && $place.length ) {
@@ -27,12 +28,25 @@
} else {
$place = $bodyContent
// Account for the Mobile Frontend section
wrapper around .thumb.
- .find( '.infobox, > div > .thumb, > .thumb, >
h1, > h2, > h3, > h4, > h5, > h6' )
+ .find( '.infobox, > div > .thumb, > .thumb, h1,
h2, h3, h4, h5, h6' )
+ .filter( ':not(.toc h2)' )
.eq( 0 );
if ( $place.length ) {
$panel.insertBefore( $place );
} else {
- $panel.appendTo( $bodyContent );
+ // Insert in this after the first paragraph
(for pages with just one paragraph
+ // or the lead section/content container when
no suitable element can be found (empty pages)
+ $place = $bodyContent.find( '> div > p' ).eq( 0
);
+ // Do this test separately for cases where no
paragraphs
+ // elements are returned in document order so >
div would always come first.
+ // See
http://blog.jquery.com/2009/02/20/jquery-1-3-2-released/
+ if ( !$place.length ) {
+ // Note that this will only ever happen
if you have an article with no headings
+ // and only an empty lead section. We
only apply to the first one but technically there
+ // should only ever be one.
+ $place = $( '> div' ).eq( 0 );
+ }
+ $panel.insertAfter( $place );
}
}
}
diff --git a/tests/qunit/ext.quicksurveys.lib/templates/vector-4.html
b/tests/qunit/ext.quicksurveys.lib/templates/vector-4.html
index 6d0ff8f..b56d9de 100644
--- a/tests/qunit/ext.quicksurveys.lib/templates/vector-4.html
+++ b/tests/qunit/ext.quicksurveys.lib/templates/vector-4.html
@@ -1,5 +1,15 @@
<div id="bodyContent">
<div id="mw-content-text">
+ <div id="toc" class="toc">
+ <div id="toctitle">
+ <h2>Contents</h2>
+ </div>
+ <ul>
+ <li class="toclevel-1 tocsection-1">
+ <a href="#A"><span
class="tocnumber">1</span> <span class="toctext">A</span></a>
+ </li>
+ </ul>
+ </div>
<h2>Heading</h2>
<p>first paragraph</p>
<p>second paragraph</p>
diff --git a/tests/qunit/ext.quicksurveys.lib/test_lib.js
b/tests/qunit/ext.quicksurveys.lib/test_lib.js
index 5f9ed82..119241d 100644
--- a/tests/qunit/ext.quicksurveys.lib/test_lib.js
+++ b/tests/qunit/ext.quicksurveys.lib/test_lib.js
@@ -49,7 +49,7 @@
'Check it is inserted in correct place (after first
paragraph)' );
} );
- QUnit.test( 'showSurvey: Placement (no headings)', 1, function ( assert
) {
+ QUnit.test( 'showSurvey: Placement (no headings)', 6, function ( assert
) {
var template = mw.template.get( 'ext.quicksurveys.lib.tests',
'minerva-3.html' ),
$locationVector = mw.template.get(
'ext.quicksurveys.lib.tests', 'vector-3.html' ).render(),
$locationMinerva = template.render(),
@@ -59,11 +59,21 @@
qSurveys._insertPanel( $locationMinerva, this.getPanel(), true
);
qSurveys._insertPanel( $locationMinervaTablet, this.getPanel()
);
+ assert.ok( $locationVector.find( '.test-panel' ).length === 1,
+ 'Check only one panel got added.' );
+ assert.ok( $locationMinervaTablet.find( '.test-panel' ).length
=== 1,
+ 'Check only one panel got added.' );
+ assert.ok( $locationMinerva.find( '.test-panel' ).length === 1,
+ 'Check only one panel got added.' );
assert.ok( this.isPanelElement( $locationMinerva.find( '> div'
).eq( 0 ).children().eq( 1 ) ),
'Check it is inserted in correct place on mobile (after
first paragraph)' );
+ assert.ok( this.isPanelElement( $locationVector.find( '> div'
).eq( 0 ).children().eq( 1 ) ),
+ 'Check it is inserted in correct place on vector (after
first paragraph)' );
+ assert.ok( this.isPanelElement( $locationMinervaTablet.find( '>
div' ).eq( 0 ).children().eq( 1 ) ),
+ 'Check it is inserted in correct place on tablet (after
first paragraph)' );
} );
- QUnit.test( 'showSurvey: Placement (plain)', 1, function ( assert ) {
+ QUnit.test( 'showSurvey: Placement (plain)', 3, function ( assert ) {
var template = mw.template.get( 'ext.quicksurveys.lib.tests',
'minerva-4.html' ),
$locationVector = mw.template.get(
'ext.quicksurveys.lib.tests', 'vector-4.html' ).render(),
$locationMinerva = template.render(),
@@ -73,6 +83,10 @@
qSurveys._insertPanel( $locationMinerva, this.getPanel(), true
);
qSurveys._insertPanel( $locationMinervaTablet, this.getPanel()
);
+ assert.ok( this.isPanelElement( $locationMinerva.find( '> div'
).eq( 1 ) ),
+ 'Check it is inserted in correct place on mobile
(before first heading)' );
+ assert.ok( this.isPanelElement( $locationVector.find( '> div'
).children().eq( 1 ) ),
+ 'Check it is inserted in correct place on vector
(before first heading)' );
assert.ok( this.isPanelElement( $locationMinervaTablet.find( '>
div' ).eq ( 1 ) ),
'Check it is inserted in correct place on tablet
(before first heading)' );
} );
--
To view, visit https://gerrit.wikimedia.org/r/244583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id8ac93547cde07f45390aad05cac5c61b200c130
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits