jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/344792 )

Change subject: Add a scroll offset when a table of contents anchor link is 
clicked
......................................................................


Add a scroll offset when a table of contents anchor link is clicked

Patch is by @smkent

Bug: T157532
Change-Id: I2ef002f7daeb0f215c7b36fa31344090b0ae6db9
---
A js/fixed-header-scroll-fix.js
M skin.json
2 files changed, 19 insertions(+), 1 deletion(-)

Approvals:
  Paladox: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/fixed-header-scroll-fix.js b/js/fixed-header-scroll-fix.js
new file mode 100644
index 0000000..d2fe16d
--- /dev/null
+++ b/js/fixed-header-scroll-fix.js
@@ -0,0 +1,17 @@
+/* Add offset when scrolling to an anchor from a table of contents link */
+var href = $( this ).attr( 'href' ),
+       dest = ( $( href ).offset().top -
+               ( $( 'div.vectorMenu#usermenu' ).height() + 10 ) ),
+       d = ( $( ':target' ).offset().top -
+               ( $( 'div.vectorMenu#usermenu' ).height() + 10 ) );
+
+$( '.toc ul a[href^=#]' ).on( 'click', function( e ) {
+       window.history.pushState( {}, '', $( this ).prop( 'href' ) );
+       $( 'html, body' ).scrollTop( dest );
+       e.preventDefault();
+} );
+
+/* Add offset when scrolling to an anchor present at page load time */
+if ( $( ':target' ).length > 0 ) {
+       $( 'html, body' ).scrollTop( d );
+}
diff --git a/skin.json b/skin.json
index ae9e5c6..d64876b 100644
--- a/skin.json
+++ b/skin.json
@@ -99,7 +99,8 @@
                                "js/metrolook.js",
                                "js/metrolook.search.js",
                                "js/vector.js",
-                               "js/overthrow.js"
+                               "js/overthrow.js",
+                               "js/fixed-header-scroll-fix.js"
                        ],
                        "position": "top",
                        "dependencies": [

-- 
To view, visit https://gerrit.wikimedia.org/r/344792
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2ef002f7daeb0f215c7b36fa31344090b0ae6db9
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/skins/Metrolook
Gerrit-Branch: master
Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to