MediaWiki:Common.js: Difference between revisions
Dragon 12dk (talk | contribs) No edit summary |
Dragon 12dk (talk | contribs) No edit summary |
||
| Line 39: | Line 39: | ||
setTimeout( sendHeight, 500 ); | setTimeout( sendHeight, 500 ); | ||
setTimeout( sendHeight, 1500 ); | setTimeout( sendHeight, 1500 ); | ||
} ); | |||
} )(); | |||
// Forward anchor link clicks to parent page scroll | |||
( function () { | |||
if ( !window.location.search.includes( 'embed=1' ) ) return; | |||
document.addEventListener( 'click', function ( e ) { | |||
var link = e.target.closest( 'a' ); | |||
if ( !link ) return; | |||
var href = link.getAttribute( 'href' ); | |||
if ( !href || !href.startsWith( '#' ) ) return; | |||
var id = href.slice( 1 ); | |||
var target = document.getElementById( id ) || document.querySelector( '[name="' + id + '"]' ); | |||
if ( !target ) return; | |||
e.preventDefault(); | |||
window.parent.postMessage( { embedScrollTo: target.getBoundingClientRect().top + window.scrollY }, '*' ); | |||
} ); | } ); | ||
} )(); | } )(); | ||