mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 10:38:11 +01:00
83c3e3e00e
For the past 6 years, WordPress has operated as an oEmbed consumer, allowing users to easily embed content from other sites. By adding oEmbed provider support, this allows any oEmbed consumer to embed posts from WordPress sites. In addition to creating an oEmbed provider, WordPress' oEmbed consumer code has been enhanced to work with any site that provides oEmbed data (as long as it matches some strict security rules), and provides a preview from within the post editor. For security, embeds appear within a sandboxed iframe - the iframe content is a template that can be styled or replaced entirely by the theme on the provider site. Props swissspidy, pento, melchoyce, netweb, pfefferle, johnbillion, extendwings, davidbinda, danielbachhuber, SergeyBiryukov, afercia Fixes #32522. Built from https://develop.svn.wordpress.org/trunk@34903 git-svn-id: http://core.svn.wordpress.org/trunk@34868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
(function ( window, document ) {
|
|
'use strict';
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
if ( !! window.wp.receiveEmbedMessage ) {
|
|
return;
|
|
}
|
|
|
|
window.wp.receiveEmbedMessage = function( e ) {
|
|
var data = e.data;
|
|
if ( ! ( data.secret || data.message || data.value ) ) {
|
|
return;
|
|
}
|
|
|
|
var iframes = document.querySelectorAll( '.wp-embedded-content[data-secret="' + data.secret + '"]' );
|
|
|
|
for ( var i = 0; i < iframes.length; i++ ) {
|
|
var source = iframes[ i ];
|
|
|
|
/* Resize the iframe on request. */
|
|
if ( 'height' === data.message ) {
|
|
var height = data.value;
|
|
if ( height > 1000 ) {
|
|
height = 1000;
|
|
} else if ( height < 200 ) {
|
|
height = 200;
|
|
}
|
|
|
|
source.height = (height) + 'px';
|
|
}
|
|
|
|
/* Link to a specific URL on request. */
|
|
if ( 'link' === data.message ) {
|
|
var sourceURL = document.createElement( 'a' ), targetURL = document.createElement( 'a' );
|
|
sourceURL.href = source.getAttribute( 'src' );
|
|
targetURL.href = data.value;
|
|
|
|
/* Only continue if link hostname matches iframe's hostname. */
|
|
if ( targetURL.host === sourceURL.host && document.activeElement === source ) {
|
|
window.top.location.href = data.value;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
window.addEventListener( 'message', window.wp.receiveEmbedMessage, false );
|
|
|
|
function onLoad() {
|
|
var isIE10 = -1 !== navigator.appVersion.indexOf( 'MSIE 10' ),
|
|
isIE11 = !!navigator.userAgent.match( /Trident.*rv\:11\./ );
|
|
|
|
/* Remove security attribute from iframes in IE10 and IE11. */
|
|
if ( isIE10 || isIE11 ) {
|
|
var iframes = document.querySelectorAll( '.wp-embedded-content[security]' ), iframeClone;
|
|
|
|
for ( var i = 0; i < iframes.length; i++ ) {
|
|
iframeClone = iframes[ i ].cloneNode( true );
|
|
iframeClone.removeAttribute( 'security' );
|
|
iframes[ i ].parentNode.insertBefore( iframeClone, iframes[ i ].nextSibling );
|
|
iframes[ i ].parentNode.removeChild( iframes[ i ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
document.addEventListener( 'DOMContentLoaded', onLoad, false );
|
|
})( window, document );
|