jenkins-bot has submitted this change and it was merged.
Change subject: Tweak toggle behaviour
......................................................................
Tweak toggle behaviour
Make sure we only jump to a section an expand it
if the url contains a hash.
Whilst here:
Update all jsdoc documentation so `make jscsdoc` doesn't
throw an errors for this file.
Bug: T76316
Change-Id: Ic8e34e4b4a6e08fe3342a1e85d96f1e9a18dbf63
---
M javascripts/modules/toggling/init.js
1 file changed, 67 insertions(+), 13 deletions(-)
Approvals:
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/modules/toggling/init.js
b/javascripts/modules/toggling/init.js
index 887d4e1..907d4f8 100644
--- a/javascripts/modules/toggling/init.js
+++ b/javascripts/modules/toggling/init.js
@@ -11,6 +11,14 @@
},
Icon = M.require( 'Icon' );
+ /**
+ * Using the settings module looks at what sections were previously
expanded on
+ * existing page.
+ *
+ * @method
+ * @returns {Object} representing open sections
+ * @ignore
+ */
function getExpandedSections() {
var expandedSections = $.parseJSON(
settings.get( 'expandedSections', false ) || '{}'
@@ -19,7 +27,8 @@
return expandedSections;
}
- /*
+ /**
+ * @ignore
* Save expandedSections to localStorage
*/
function saveExpandedSections( expandedSections ) {
@@ -28,11 +37,12 @@
);
}
- /*
+ /**
* Given an expanded heading, store it to localStorage.
* If the heading is collapsed, remove it from localStorage.
*
* @param {jQuery.Object} $heading - A heading belonging to a section
+ * @ignore
*/
function storeSectionToggleState( $heading ) {
var headline = $heading.find( 'span' ).attr( 'id' ),
@@ -50,8 +60,9 @@
}
}
- /*
+ /**
* Expand sections that were previously expanded before leaving this
page.
+ * @ignore
*/
function expandStoredSections( $container ) {
var $sectionHeading, $headline,
@@ -71,9 +82,10 @@
} );
}
- /*
+ /**
* Clean obsolete (saved more than a day ago) expanded sections from
* localStorage.
+ * @ignore
*/
function cleanObsoleteStoredSections() {
var now = ( new Date() ).getTime(),
@@ -92,10 +104,11 @@
saveExpandedSections( expandedSections );
}
- /*
+ /**
* Given a heading, toggle it and any of its children
*
* @param {jQuery.Object} $heading A heading belonging to a section
+ * @ignore
*/
function toggle( $heading ) {
var isCollapsed = $heading.is( '.open-block' ),
@@ -120,9 +133,10 @@
}
}
- /*
+ /**
* Enables toggling via enter and space keys
*
+ * @ignore
* @param {jQuery.Object} $heading
*/
function enableKeyboardActions( $heading ) {
@@ -136,9 +150,10 @@
} );
}
- /*
+ /**
* Reveals an element and its parent section as identified by it's id
*
+ * @ignore
* @param {String} selector A css selector that identifies a single
element
* @param {Object} $container jQuery element to search in
*/
@@ -163,6 +178,14 @@
} catch ( e ) {}
}
+ /**
+ * Enables section toggling in a given container when
wgMFCollapseSectionsByDefault
+ * is enabled.
+ *
+ * @method
+ * @param {jQuery.object} $container to apply toggling to
+ * @ignore
+ */
function enable( $container ) {
var tagName, expandSections, indicator,
$firstHeading,
@@ -221,20 +244,45 @@
}
} );
+ /**
+ * Checks the existing hash and toggles open any section that
contains the fragment.
+ *
+ * @method
+ * @ignore
+ */
function checkHash() {
- var internalRedirect = mw.config.get(
'wgInternalRedirectTargetUrl' ),
- internalRedirectHash = internalRedirect ?
internalRedirect.split( '#' )[1] : false,
- hash = window.location.hash;
-
+ var hash = window.location.hash;
if ( hash.indexOf( '#' ) === 0 ) {
reveal( hash, $container );
- } else if ( internalRedirectHash ) {
+ }
+ }
+
+ /**
+ * Checks the value of wgInternalRedirectTargetUrl and reveals
the collapsed
+ * section that contains it if present
+ *
+ * @method
+ * @ignore
+ */
+ function checkInternalRedirectAndHash() {
+ var internalRedirect = mw.config.get(
'wgInternalRedirectTargetUrl' ),
+ internalRedirectHash = internalRedirect ?
internalRedirect.split( '#' )[1] : false;
+
+ if ( internalRedirectHash ) {
window.location.hash = internalRedirectHash;
reveal( internalRedirectHash, $container );
}
}
+
+ checkInternalRedirectAndHash();
checkHash();
- $( '#content_wrapper a' ).on( 'click', checkHash );
+ $( '#content_wrapper a' ).on( 'click', function () {
+ // the link might be an internal link with a hash.
+ // if it is check if we need to reveal any sections.
+ if ( $( this ).attr( 'href' ).indexOf ( '#' ) > -1 ) {
+ checkHash();
+ }
+ } );
if ( M.isBetaGroupMember() && !M.isWideScreen() ) {
expandStoredSections( $container );
@@ -242,6 +290,12 @@
}
}
+ /**
+ * Initialises toggling code.
+ *
+ * @method
+ * @ignore
+ */
function init( $container ) {
// distinguish headings in content from other headings
$( '#content' ).find( '> h1,> h2,> h3,> h4,> h5,> h6'
).addClass( 'section-heading' );
--
To view, visit https://gerrit.wikimedia.org/r/177885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic8e34e4b4a6e08fe3342a1e85d96f1e9a18dbf63
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Awjrichards <[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