2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-includes/js/wp-embed-template.js
|
|
|
|
*/
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
(function ( window, document ) {
|
|
|
|
'use strict';
|
|
|
|
|
2015-11-08 19:08:27 -05:00
|
|
|
var supportedBrowser = ( document.querySelector && window.addEventListener ),
|
2015-10-31 00:38:25 -04:00
|
|
|
loaded = false,
|
2015-11-08 19:08:27 -05:00
|
|
|
secret,
|
|
|
|
secretTimeout,
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
resizing;
|
|
|
|
|
|
|
|
function sendEmbedMessage( message, value ) {
|
|
|
|
window.parent.postMessage( {
|
|
|
|
message: message,
|
|
|
|
value: value,
|
|
|
|
secret: secret
|
|
|
|
}, '*' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLoad() {
|
2015-10-31 00:38:25 -04:00
|
|
|
if ( loaded ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
var share_dialog = document.querySelector( '.wp-embed-share-dialog' ),
|
|
|
|
share_dialog_open = document.querySelector( '.wp-embed-share-dialog-open' ),
|
|
|
|
share_dialog_close = document.querySelector( '.wp-embed-share-dialog-close' ),
|
|
|
|
share_input = document.querySelectorAll( '.wp-embed-share-input' ),
|
|
|
|
share_dialog_tabs = document.querySelectorAll( '.wp-embed-share-tab-button button' ),
|
2016-07-05 12:16:57 -04:00
|
|
|
featured_image = document.querySelector( '.wp-embed-featured-image img' ),
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
i;
|
|
|
|
|
|
|
|
if ( share_input ) {
|
|
|
|
for ( i = 0; i < share_input.length; i++ ) {
|
|
|
|
share_input[ i ].addEventListener( 'click', function ( e ) {
|
|
|
|
e.target.select();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openSharingDialog() {
|
|
|
|
share_dialog.className = share_dialog.className.replace( 'hidden', '' );
|
2015-11-03 10:49:27 -05:00
|
|
|
// Initial focus should go on the currently selected tab in the dialog.
|
|
|
|
document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' ).focus();
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeSharingDialog() {
|
|
|
|
share_dialog.className += ' hidden';
|
|
|
|
document.querySelector( '.wp-embed-share-dialog-open' ).focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( share_dialog_open ) {
|
2015-11-03 10:49:27 -05:00
|
|
|
share_dialog_open.addEventListener( 'click', function () {
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
openSharingDialog();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( share_dialog_close ) {
|
2015-11-03 10:49:27 -05:00
|
|
|
share_dialog_close.addEventListener( 'click', function () {
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
closeSharingDialog();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
function shareClickHandler( e ) {
|
|
|
|
var currentTab = document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' );
|
|
|
|
currentTab.setAttribute( 'aria-selected', 'false' );
|
|
|
|
document.querySelector( '#' + currentTab.getAttribute( 'aria-controls' ) ).setAttribute( 'aria-hidden', 'true' );
|
|
|
|
|
|
|
|
e.target.setAttribute( 'aria-selected', 'true' );
|
|
|
|
document.querySelector( '#' + e.target.getAttribute( 'aria-controls' ) ).setAttribute( 'aria-hidden', 'false' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function shareKeyHandler( e ) {
|
|
|
|
var target = e.target,
|
|
|
|
previousSibling = target.parentElement.previousElementSibling,
|
|
|
|
nextSibling = target.parentElement.nextElementSibling,
|
|
|
|
newTab, newTabChild;
|
|
|
|
|
|
|
|
if ( 37 === e.keyCode ) {
|
|
|
|
newTab = previousSibling;
|
|
|
|
} else if ( 39 === e.keyCode ) {
|
|
|
|
newTab = nextSibling;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'rtl' === document.documentElement.getAttribute( 'dir' ) ) {
|
|
|
|
newTab = ( newTab === previousSibling ) ? nextSibling : previousSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newTab ) {
|
|
|
|
newTabChild = newTab.firstElementChild;
|
|
|
|
|
|
|
|
target.setAttribute( 'tabindex', '-1' );
|
|
|
|
target.setAttribute( 'aria-selected', false );
|
|
|
|
document.querySelector( '#' + target.getAttribute( 'aria-controls' ) ).setAttribute( 'aria-hidden', 'true' );
|
|
|
|
|
|
|
|
newTabChild.setAttribute( 'tabindex', '0' );
|
|
|
|
newTabChild.setAttribute( 'aria-selected', 'true' );
|
|
|
|
newTabChild.focus();
|
|
|
|
document.querySelector( '#' + newTabChild.getAttribute( 'aria-controls' ) ).setAttribute( 'aria-hidden', 'false' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( share_dialog_tabs ) {
|
|
|
|
for ( i = 0; i < share_dialog_tabs.length; i++ ) {
|
|
|
|
share_dialog_tabs[ i ].addEventListener( 'click', shareClickHandler );
|
|
|
|
|
|
|
|
share_dialog_tabs[ i ].addEventListener( 'keydown', shareKeyHandler );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener( 'keydown', function ( e ) {
|
2015-11-03 10:49:27 -05:00
|
|
|
if ( 27 === e.keyCode && -1 === share_dialog.className.indexOf( 'hidden' ) ) {
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
closeSharingDialog();
|
2015-11-03 10:49:27 -05:00
|
|
|
} else if ( 9 === e.keyCode ) {
|
|
|
|
constrainTabbing( e );
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
}
|
|
|
|
}, false );
|
|
|
|
|
2015-11-03 10:49:27 -05:00
|
|
|
function constrainTabbing( e ) {
|
|
|
|
// Need to re-get the selected tab each time.
|
|
|
|
var firstFocusable = document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' );
|
|
|
|
|
|
|
|
if ( share_dialog_close === e.target && ! e.shiftKey ) {
|
|
|
|
firstFocusable.focus();
|
|
|
|
e.preventDefault();
|
|
|
|
} else if ( firstFocusable === e.target && e.shiftKey ) {
|
|
|
|
share_dialog_close.focus();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
if ( window.self === window.top ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send this document's height to the parent (embedding) site.
|
|
|
|
*/
|
|
|
|
sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) );
|
|
|
|
|
2016-06-18 06:00:29 -04:00
|
|
|
// Send the document's height again after the featured image has been loaded.
|
2016-07-05 12:16:57 -04:00
|
|
|
if ( featured_image ) {
|
|
|
|
featured_image.addEventListener( 'load', function() {
|
|
|
|
sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) );
|
|
|
|
} );
|
|
|
|
}
|
2016-06-18 06:00:29 -04:00
|
|
|
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
/**
|
|
|
|
* Detect clicks to external (_top) links.
|
|
|
|
*/
|
|
|
|
function linkClickHandler( e ) {
|
|
|
|
var target = e.target,
|
|
|
|
href;
|
|
|
|
if ( target.hasAttribute( 'href' ) ) {
|
|
|
|
href = target.getAttribute( 'href' );
|
|
|
|
} else {
|
|
|
|
href = target.parentElement.getAttribute( 'href' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send link target to the parent (embedding) site.
|
|
|
|
*/
|
2016-02-23 12:16:26 -05:00
|
|
|
if ( href ) {
|
|
|
|
sendEmbedMessage( 'link', href );
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
}
|
|
|
|
|
2016-02-23 12:16:26 -05:00
|
|
|
document.addEventListener( 'click', linkClickHandler );
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iframe resize handler.
|
|
|
|
*/
|
|
|
|
function onResize() {
|
|
|
|
if ( window.self === window.top ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearTimeout( resizing );
|
|
|
|
|
|
|
|
resizing = setTimeout( function () {
|
|
|
|
sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) );
|
|
|
|
}, 100 );
|
|
|
|
}
|
|
|
|
|
2015-11-08 19:08:27 -05:00
|
|
|
/**
|
|
|
|
* Re-get the secret when it was added later on.
|
|
|
|
*/
|
|
|
|
function getSecret() {
|
|
|
|
if ( window.self === window.top || !!secret ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
secret = window.location.hash.replace( /.*secret=([\d\w]{10}).*/, '$1' );
|
|
|
|
|
|
|
|
clearTimeout( secretTimeout );
|
|
|
|
|
|
|
|
secretTimeout = setTimeout( function () {
|
|
|
|
getSecret();
|
|
|
|
}, 100 );
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:38:25 -04:00
|
|
|
if ( supportedBrowser ) {
|
2015-11-08 19:08:27 -05:00
|
|
|
getSecret();
|
2015-10-31 00:38:25 -04:00
|
|
|
document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/, '' ) + ' js';
|
|
|
|
document.addEventListener( 'DOMContentLoaded', onLoad, false );
|
|
|
|
window.addEventListener( 'load', onLoad, false );
|
|
|
|
window.addEventListener( 'resize', onResize, false );
|
|
|
|
}
|
Embeds: Add oEmbed provider support.
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
2015-10-07 06:36:25 -04:00
|
|
|
})( window, document );
|