MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 29: Line 29:
}
}


// Report page height to parent when embedded in an iframe
( function () {
( function () {
   if ( window === window.top ) return; // not in an iframe
   if ( window === window.top ) return;


   function sendHeight() {
   function sendHeight() {
Line 38: Line 37:
   }
   }


   mw.hook( 'wikipage.content' ).add( function () {
   // Fire on multiple events to catch all page types
  document.addEventListener( 'DOMContentLoaded', sendHeight );
  window.addEventListener( 'load', function () {
     sendHeight();
     sendHeight();
     setTimeout( sendHeight, 500 );
     setTimeout( sendHeight, 500 );
     setTimeout( sendHeight, 1500 );
     setTimeout( sendHeight, 1500 );
   } );
   } );
  if ( typeof mw !== 'undefined' ) {
    mw.hook( 'wikipage.content' ).add( sendHeight );
  }


   // Also intercept anchor clicks for scroll forwarding
   // Anchor scroll forwarding
   document.addEventListener( 'click', function ( e ) {
   document.addEventListener( 'click', function ( e ) {
     var link = e.target.closest( 'a' );
     var link = e.target.closest( 'a' );