Robmoen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/171994
Change subject: Only assume sections are collapsible if they are wrapped in a
div
......................................................................
Only assume sections are collapsible if they are wrapped in a div
Now toggle doesn't add collapsible-heading and icon classes by default
It first checks to see if there the section is wrapped in a div
meaning it has been modified by MobileFormatter. If the section is
not wrapped in a div, collapsible sections are not enabled on that page
Plus small code refactor in enable method
Change-Id: I79df94a6ba3c4893af1fbac5d79215f57275e377
---
M javascripts/modules/toggling/toggle.js
1 file changed, 34 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/94/171994/1
diff --git a/javascripts/modules/toggling/toggle.js
b/javascripts/modules/toggling/toggle.js
index 90ed7fe..8f29cc6 100644
--- a/javascripts/modules/toggling/toggle.js
+++ b/javascripts/modules/toggling/toggle.js
@@ -157,7 +157,7 @@
}
function enable( $container ) {
- var tagName, $headings, expandSections,
+ var tagName, expandSections,
$firstHeading,
iconClass = iconDown.getClassName(),
collapseSectionsByDefault = mw.config.get(
'wgMFCollapseSectionsByDefault' );
@@ -166,10 +166,6 @@
$( 'html' ).removeClass( 'stub' );
$firstHeading = $container.find( 'h1,h2,h3,h4,h5,h6' ).eq( 0 );
tagName = $firstHeading.prop( 'tagName' ) || 'H1';
- $container.find( tagName ).addClass( 'collapsible-heading ' +
iconClass );
-
- $headings = $container.find( '.collapsible-heading' );
- $headings.next( 'div' ).addClass( 'collapsible-block' );
if ( collapseSectionsByDefault === undefined ) {
// Old default behavior if on cached output
@@ -178,35 +174,42 @@
expandSections = !collapseSectionsByDefault ||
( M.isAlphaGroupMember() && M.settings.getUserSetting(
'expandSections', true ) === 'true' );
- $headings.each( function ( i ) {
- var $elem = $( this ),
+ $container.find( tagName ).each( function ( i ) {
+ var $heading = $( this ),
id = 'collapsible-block-' + i;
+ // Be sure there is a div wrapping the section content.
+ // Otherwise, collapsible sections for this page is not
enabled.
+ if ( $heading.next().is( 'div' ) ) {
+ $heading
+ .addClass( 'collapsible-heading ' +
iconClass )
+ .attr( {
+ tabindex: 0,
+ 'aria-haspopup': 'true',
+ 'aria-controls': id
+ } )
+ .on( 'click', function ( ev ) {
+ // prevent taps/clicks on edit
button after toggling (bug 56209)
+ ev.preventDefault();
+ toggle( $( this ) );
+ } );
+ $heading.next( 'div' )
+ .addClass( 'collapsible-block' )
+ .eq( 0 )
+ .attr( {
+ // We need to give each content
block a unique id as that's
+ // the only way we can tell
screen readers what element we're
+ // referring to (aria-controls)
+ id: id,
+ 'aria-pressed': 'false',
+ 'aria-expanded': 'false'
+ } );
- $elem.next( '.collapsible-block' ).eq( 0 )
- .attr( {
- // We need to give each content block a
unique id as that's
- // the only way we can tell screen
readers what element we're
- // referring to (aria-controls)
- id: id,
- 'aria-pressed': 'false',
- 'aria-expanded': 'false'
- } );
+ enableKeyboardActions( $heading );
+ if ( M.isWideScreen() || expandSections ) {
+ // Expand sections by default on wide
screen devices or if the expand sections setting is set (alpha only)
+ toggle( $heading );
+ }
- $elem.attr( {
- tabindex: 0,
- 'aria-haspopup': 'true',
- 'aria-controls': id
- } )
- .on( 'click', function ( ev ) {
- // prevent taps/clicks on edit button after
toggling (bug 56209)
- ev.preventDefault();
- toggle( $( this ) );
- } );
-
- enableKeyboardActions( $elem );
- if ( M.isWideScreen() || expandSections ) {
- // Expand sections by default on wide screen
devices or if the expand sections setting is set (alpha only)
- toggle( $elem );
}
} );
--
To view, visit https://gerrit.wikimedia.org/r/171994
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I79df94a6ba3c4893af1fbac5d79215f57275e377
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Robmoen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits