[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/js/ -> wp-embed.js (source)

   1  /**
   2   * WordPress inline HTML embed
   3   *
   4   * @since 4.4.0
   5   * @output wp-includes/js/wp-embed.js
   6   *
   7   * This file cannot have ampersands in it. This is to ensure
   8   * it can be embedded in older versions of WordPress.
   9   * See https://core.trac.wordpress.org/changeset/35708.
  10   */
  11  (function ( window, document ) {
  12      'use strict';
  13  
  14      var supportedBrowser = false,
  15          loaded = false;
  16  
  17          if ( document.querySelector ) {
  18              if ( window.addEventListener ) {
  19                  supportedBrowser = true;
  20              }
  21          }
  22  
  23      /** @namespace wp */
  24      window.wp = window.wp || {};
  25  
  26      if ( !! window.wp.receiveEmbedMessage ) {
  27          return;
  28      }
  29  
  30      window.wp.receiveEmbedMessage = function( e ) {
  31          var data = e.data;
  32  
  33          if ( ! data ) {
  34              return;
  35          }
  36  
  37          if ( ! ( data.secret || data.message || data.value ) ) {
  38              return;
  39          }
  40  
  41          if ( /[^a-zA-Z0-9]/.test( data.secret ) ) {
  42              return;
  43          }
  44  
  45          var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ),
  46              blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ),
  47              i, source, height, sourceURL, targetURL;
  48  
  49          for ( i = 0; i < blockquotes.length; i++ ) {
  50              blockquotes[ i ].style.display = 'none';
  51          }
  52  
  53          for ( i = 0; i < iframes.length; i++ ) {
  54              source = iframes[ i ];
  55  
  56              if ( e.source !== source.contentWindow ) {
  57                  continue;
  58              }
  59  
  60              source.removeAttribute( 'style' );
  61  
  62              /* Resize the iframe on request. */
  63              if ( 'height' === data.message ) {
  64                  height = parseInt( data.value, 10 );
  65                  if ( height > 1000 ) {
  66                      height = 1000;
  67                  } else if ( ~~height < 200 ) {
  68                      height = 200;
  69                  }
  70  
  71                  source.height = height;
  72              }
  73  
  74              /* Link to a specific URL on request. */
  75              if ( 'link' === data.message ) {
  76                  sourceURL = document.createElement( 'a' );
  77                  targetURL = document.createElement( 'a' );
  78  
  79                  sourceURL.href = source.getAttribute( 'src' );
  80                  targetURL.href = data.value;
  81  
  82                  /* Only continue if link hostname matches iframe's hostname. */
  83                  if ( targetURL.host === sourceURL.host ) {
  84                      if ( document.activeElement === source ) {
  85                          window.top.location.href = data.value;
  86                      }
  87                  }
  88              }
  89          }
  90      };
  91  
  92  	function onLoad() {
  93          if ( loaded ) {
  94              return;
  95          }
  96  
  97          loaded = true;
  98  
  99          var isIE10 = -1 !== navigator.appVersion.indexOf( 'MSIE 10' ),
 100              isIE11 = !!navigator.userAgent.match( /Trident.*rv:11\./ ),
 101              iframes = document.querySelectorAll( 'iframe.wp-embedded-content' ),
 102              iframeClone, i, source, secret;
 103  
 104          for ( i = 0; i < iframes.length; i++ ) {
 105              source = iframes[ i ];
 106  
 107              if ( ! source.getAttribute( 'data-secret' ) ) {
 108                  /* Add secret to iframe */
 109                  secret = Math.random().toString( 36 ).substr( 2, 10 );
 110                  source.src += '#?secret=' + secret;
 111                  source.setAttribute( 'data-secret', secret );
 112              }
 113  
 114              /* Remove security attribute from iframes in IE10 and IE11. */
 115              if ( ( isIE10 || isIE11 ) ) {
 116                  iframeClone = source.cloneNode( true );
 117                  iframeClone.removeAttribute( 'security' );
 118                  source.parentNode.replaceChild( iframeClone, source );
 119              }
 120          }
 121      }
 122  
 123      if ( supportedBrowser ) {
 124          window.addEventListener( 'message', window.wp.receiveEmbedMessage, false );
 125          document.addEventListener( 'DOMContentLoaded', onLoad, false );
 126          window.addEventListener( 'load', onLoad, false );
 127      }
 128  })( window, document );


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7