| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /** 2 * WordPress inline HTML embed 3 * 4 * @param {Window} window The global window object. 5 * @param {Document} document The global document object. 6 * @since 4.4.0 7 * @output wp-includes/js/wp-embed.js 8 * 9 * Single line comments should not be used since they will break 10 * the script when inlined in get_post_embed_html(), specifically 11 * when the comments are not stripped out due to SCRIPT_DEBUG 12 * being turned on. 13 */ 14 (function ( window, document ) { 15 'use strict'; 16 17 /* Abort for ancient browsers. */ 18 if ( ! document.querySelector || ! window.addEventListener || typeof URL === 'undefined' ) { 19 return; 20 } 21 22 /** @namespace wp */ 23 window.wp = window.wp || {}; 24 25 /* Abort if script was already executed. */ 26 if ( !! window.wp.receiveEmbedMessage ) { 27 return; 28 } 29 30 /** 31 * Receive embed message. 32 * 33 * @param {MessageEvent} e The message event. 34 */ 35 window.wp.receiveEmbedMessage = function( e ) { 36 var data = e.data; 37 38 /* Verify shape of message. */ 39 if ( 40 ! ( data || data.secret || data.message || data.value ) || 41 /[^a-zA-Z0-9]/.test( data.secret ) 42 ) { 43 return; 44 } 45 46 var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ), 47 blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ), 48 allowedProtocols = new RegExp( '^https?:$', 'i' ), 49 i, source, height, sourceURL, targetURL; 50 51 for ( i = 0; i < blockquotes.length; i++ ) { 52 blockquotes[ i ].style.display = 'none'; 53 } 54 55 for ( i = 0; i < iframes.length; i++ ) { 56 source = iframes[ i ]; 57 58 if ( e.source !== source.contentWindow ) { 59 continue; 60 } 61 62 source.removeAttribute( 'style' ); 63 64 if ( 'height' === data.message ) { 65 /* Resize the iframe on request. */ 66 height = parseInt( data.value, 10 ); 67 if ( height > 1000 ) { 68 height = 1000; 69 } else if ( ~~height < 200 ) { 70 height = 200; 71 } 72 73 source.height = height; 74 } else if ( 'link' === data.message ) { 75 /* Link to a specific URL on request. */ 76 sourceURL = new URL( source.getAttribute( 'src' ) ); 77 targetURL = new URL( data.value ); 78 79 if ( 80 allowedProtocols.test( targetURL.protocol ) && 81 targetURL.host === sourceURL.host && 82 document.activeElement === source 83 ) { 84 window.top.location.href = data.value; 85 } 86 } 87 } 88 }; 89 90 function onLoad() { 91 var iframes = document.querySelectorAll( 'iframe.wp-embedded-content' ), 92 i, source, secret; 93 94 for ( i = 0; i < iframes.length; i++ ) { 95 /** @type {HTMLIFrameElement}} */ 96 source = iframes[ i ]; 97 98 secret = source.getAttribute( 'data-secret' ); 99 if ( ! secret ) { 100 /* Add secret to iframe */ 101 secret = Math.random().toString( 36 ).substring( 2, 12 ); 102 source.src += '#?secret=' + secret; 103 source.setAttribute( 'data-secret', secret ); 104 } 105 106 /* 107 * Let post embed window know that the parent is ready for receiving the height message, in case the iframe 108 * loaded before wp-embed.js was loaded. When the ready message is received by the post embed window, the 109 * window will then (re-)send the height message right away. 110 */ 111 source.contentWindow.postMessage( { 112 message: 'ready', 113 secret: secret 114 }, '*' ); 115 } 116 } 117 118 window.addEventListener( 'message', window.wp.receiveEmbedMessage, false ); 119 document.addEventListener( 'DOMContentLoaded', onLoad, false ); 120 })( window, document );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sun Sep 6 08:20:27 2026 | Cross-referenced by PHPXref |