MediaWiki:Common.js: Difference between revisions
Dragon 12dk (talk | contribs) No edit summary |
Dragon 12dk (talk | contribs) No edit summary |
||
| Line 11: | Line 11: | ||
} | } | ||
/* ── Embed: dynamic height + anchor scroll ── */ | |||
( function () { | ( function () { | ||
if ( window === window.top ) return; | if ( window === window.top ) return; | ||
| Line 17: | Line 18: | ||
var h = document.body ? document.body.scrollHeight : 0; | var h = document.body ? document.body.scrollHeight : 0; | ||
if ( h > 0 ) window.parent.postMessage( { embedHeight: h }, '*' ); | if ( h > 0 ) window.parent.postMessage( { embedHeight: h }, '*' ); | ||
} | } | ||
document.addEventListener( 'DOMContentLoaded', sendHeight ); | document.addEventListener( 'DOMContentLoaded', sendHeight ); | ||
window.addEventListener( 'load', function () { | window.addEventListener( 'load', function () { | ||
sendHeight(); | sendHeight(); | ||
setTimeout( sendHeight, 500 ); | setTimeout( sendHeight, 500 ); | ||
| Line 36: | Line 27: | ||
} ); | } ); | ||
if ( typeof mw !== 'undefined' ) { | if ( typeof mw !== 'undefined' ) { | ||
mw.hook( 'wikipage.content' ).add( | mw.hook( 'wikipage.content' ).add( sendHeight ); | ||
} | } | ||
| Line 55: | Line 41: | ||
window.parent.postMessage( { embedScrollTo: target.getBoundingClientRect().top + window.scrollY }, '*' ); | window.parent.postMessage( { embedScrollTo: target.getBoundingClientRect().top + window.scrollY }, '*' ); | ||
} ); | } ); | ||
} )(); | |||
/* ── Embed: open links in new tab ── */ | |||
( function () { | |||
if ( window === window.top ) return; | |||
function retargetLinks() { | |||
var links = document.querySelectorAll( 'a[href]' ); | |||
for ( var i = 0; i < links.length; i++ ) { | |||
var href = links[ i ].getAttribute( 'href' ); | |||
if ( !href || href.charAt( 0 ) === '#' ) continue; | |||
links[ i ].setAttribute( 'target', '_blank' ); | |||
links[ i ].setAttribute( 'rel', 'noopener noreferrer' ); | |||
} | |||
} | |||
window.addEventListener( 'load', retargetLinks ); | |||
if ( typeof mw !== 'undefined' ) { | |||
mw.hook( 'wikipage.content' ).add( retargetLinks ); | |||
} | |||
} )(); | } )(); | ||