MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 11: Line 11:
}
}


// Force links to open in new tab when embedded in an iframe
( function () {
( function () {
   if ( window === window.top ) return;
   if ( window === window.top ) return;
  function sendHeight() {
    var h = document.body ? document.body.scrollHeight : 0;
    if ( h > 0 ) window.parent.postMessage( { embedHeight: h }, '*' );
  }


   function retargetLinks() {
   function retargetLinks() {
Line 24: Line 28:
   }
   }


   window.addEventListener( 'load', retargetLinks );
   function init() {
  if ( typeof mw !== 'undefined' ) {
     retargetLinks();
     mw.hook( 'wikipage.content' ).add( retargetLinks );
  }
} )();
 
( function () {
  if ( window === window.top ) return;
 
  function sendHeight() {
    var h = document.body ? document.body.scrollHeight : 0;
    if ( h > 0 ) window.parent.postMessage( { embedHeight: h }, '*' );
  }
 
  // 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 );
   } );
   }
 
  document.addEventListener( 'DOMContentLoaded', retargetLinks );
  window.addEventListener( 'load', init );
   if ( typeof mw !== 'undefined' ) {
   if ( typeof mw !== 'undefined' ) {
     mw.hook( 'wikipage.content' ).add( sendHeight );
     mw.hook( 'wikipage.content' ).add( init );
   }
   }