Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/244583
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
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/test_lib.js
2 files changed, 17 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys
refs/changes/83/244583/1
diff --git a/resources/ext.quicksurveys.lib/lib.js
b/resources/ext.quicksurveys.lib/lib.js
index 1b9c58c..bd124be 100644
--- a/resources/ext.quicksurveys.lib/lib.js
+++ b/resources/ext.quicksurveys.lib/lib.js
@@ -18,7 +18,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 ) {
@@ -26,12 +27,15 @@
} 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' )
.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, > div'
);
+ $panel.insertAfter( $place );
}
}
}
diff --git a/tests/qunit/ext.quicksurveys.lib/test_lib.js
b/tests/qunit/ext.quicksurveys.lib/test_lib.js
index a672ea5..97f8f5e 100644
--- a/tests/qunit/ext.quicksurveys.lib/test_lib.js
+++ b/tests/qunit/ext.quicksurveys.lib/test_lib.js
@@ -58,7 +58,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)', 3, 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(),
@@ -70,9 +70,13 @@
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(),
@@ -82,6 +86,10 @@
qSurveys.showSurvey( $locationMinerva, true );
qSurveys.showSurvey( $locationMinervaTablet );
+ 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( 0 ) ),
+ '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: newchange
Gerrit-Change-Id: Id8ac93547cde07f45390aad05cac5c61b200c130
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits