Skip to content

Commit

Permalink
Merge branch 'release/v1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmark committed Jan 18, 2023
2 parents be4000e + 35b7d19 commit 4e83ae3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 34 deletions.
3 changes: 2 additions & 1 deletion assets/css/better-core-video-embeds.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.hd-bcve-wrapper {
position: relative;
cursor: pointer;
}
.hd-bcve-thumbnail {
height: auto;
max-width: 100%;
width: 100%;
cursor: pointer;
}
.hd-bcve-wrapper .play-button {
--hd-play-button-size: 80px;
Expand All @@ -19,6 +19,7 @@
z-index: 2;
width: var(--hd-play-button-size);
height: var(--hd-play-button-size);
cursor: pointer;
}
.hd-bcve-wrapper .play-button:after {
--hd-play-button-opacity: .8;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/better-core-video-embeds.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 31 additions & 21 deletions assets/js/better-core-video-embeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// these are the elements that should contain the thumbnail.
document.querySelectorAll( '.hd-bcve-wrapper' ).forEach(( el, i ) => {

// get the youtube video id for the data attribute on the wrapper.
var videoId = el.getAttribute( 'data-id' );

// get the associated template element which holds the embed code.
var template = document.querySelector( '#hd-bcve-embed-html-' + videoId );
// it is the next element after the wrapper.
var template = el.nextElementSibling;

/**
* Add autoplay on the iframe as well as loading from youtube no cookie.
Expand All @@ -24,39 +22,51 @@ document.querySelectorAll( '.hd-bcve-wrapper' ).forEach(( el, i ) => {
// set an allows attribute on the iframe with an autoplay value.
iframe.setAttribute( 'allow', 'autoplay' );

// get the text content of the embed element - this is the caption.
var caption = template.content.textContent.trim();
// get the first child of the figure - the caption.
var caption = template.content.children[0].querySelector( 'figcaption' );

// if we have a caption.
if ( '' !== caption ) {
if ( caption ) {

// create an element for the embed caption.
var captionEl = document.createElement('figcaption');
captionEl.classList.add( 'wp-element-caption' );
captionEl.textContent = caption;
captionEl.innerHTML = caption.innerHTML;

// add the caption, after the thumbnail.
el.append( captionEl );

}

// when the wrapper is clicked.
el.addEventListener( 'click', () => {
// create an array for storing the click event elements.
var clickEls = [];

// clone the template element.
var contentOuter = template.content.cloneNode( true );

// grab just the first child of the template - this is the figure block element which wraps the iframe.
var content = contentOuter.children[0];
// grab the thumbnail and play button of this embed.
clickEls.push( el.querySelector( '.hd-bcve-thumbnail' ) );
clickEls.push( el.querySelector( '.play-button' ) );

// add the iframe embed content before the embed wrapper.
el.before( content );
// loop through each click event - play button and thumbnail.
clickEls.forEach(( clickEls, i ) => {

// remove the embed wrapper including thumbnail.
el.remove();
// when the element is clicked.
clickEls.addEventListener( 'click', () => {

// remove the template item which holds the iframe.
template.remove();
// clone the template element.
var contentOuter = template.content.cloneNode( true );

// grab just the first child of the template - this is the figure block element which wraps the iframe.
var content = contentOuter.children[0];

// add the iframe embed content before the embed wrapper.
el.before( content );

// remove the embed wrapper including thumbnail.
el.remove();

// remove the template item which holds the iframe.
template.remove();

});

});

Expand Down
2 changes: 1 addition & 1 deletion assets/js/better-core-video-embeds.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 28 additions & 5 deletions better-core-video-embeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Description: A plugin which enhances the core video embeds for Youtube and Vimeo videos by not loading unnecessary scripts until they are needed.
Requires at least: 6.0
Requires PHP: 7.0
Version: 1.1.1
Version: 1.1.2
Author: Highrise Digital
Author URI: https://highrise.digital/
License: GPL-2.0-or-later
Expand Down Expand Up @@ -392,11 +392,12 @@ function hd_job_allowed_innerblock_html() {

/**
* Return the allowed html
* These are the elements in the rendered embed block for youtube and vimeo videos.
* These are the elements in the rendered embed block for supported videos.
* This also includes everything you can add to an embed caption.
* Therefore we need to allow these to keep the same structure.
*/
return [
'iframe' => [
'iframe' => [
'src' => true,
'height' => true,
'width' => true,
Expand All @@ -409,9 +410,31 @@ function hd_job_allowed_innerblock_html() {
'figcaption' => [
'class' => true,
],
'div' => [
'div' => [
'class' => true,
]
],
'a' => [
'class' => true,
'href' => true,
'data-type' => true,
],
'strong' => [],
'em' => [],
'sub' => [],
'sup' => [],
's' => [],
'kbd' => [],
'img' => [
'class' => true,
'style' => true,
'src' => true,
'alt' => true,
],
'code' => [],
'mark' => [
'style' => true,
'class' => true,
],
];

}
Expand Down
14 changes: 9 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Better Core Video Embeds ===
Contributors: highrisedigital,wpmarkuk
Donate link: https://example.com/
Tags: embed, oembed, youtube, vimeo
Tags: embed, oembed, youtube, vimeo, performance, blocks
Requires at least: 6.0
Tested up to: 6.1.1
Stable tag: 1.1.1
Stable tag: 1.1.2
Requires PHP: 7.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -13,11 +13,11 @@ A plugin which enhances the core embed block for Youtube, Daily Motion and Vimeo

== Description ==

This plugin provides page optimisations for pages and posts which have embedded Youtube or Vimeo videos which have been added using the core embed block.
This plugin provides page optimisations for pages and posts which have embedded Youtube, Vimeo or Daily Motion videos which have been added using the core embed block.

Without this plugin, when using the core embed block, when your page loads, lots of Youtube and/or Vimeo scripts and styles are loaded, regardless of whether a visitor actually interacts with the embedded video.
Without this plugin, when using the core embed block, when your page loads, lots of external scripts and styles are loaded from the embed service, regardless of whether a visitor actually interacts with the embedded video.

This plugin prevents these scripts and styles from loading until the user actually interacts with the video. It does this by replacing the video embed, on page load with the video thumbnail image (added on Youtube or Vimeo). When a user clicks the thumbnail the embedded video, along with associated scripts and styles in then loaded.
This plugin prevents these scripts and styles from loading until the user actually interacts with the video. It does this by replacing the video embed, on page load with the video thumbnail image (added on Youtube, Vimeo or Daily Motion). When a user clicks the thumbnail the embedded video, along with associated scripts and styles are loaded.

https://www.youtube.com/watch?v=k7A2kZWUb9Q

Expand Down Expand Up @@ -45,6 +45,10 @@ The plugin provides progressive enhancement, therefore if you no longer use this

== Changelog ==

= 1.1.2 (18/01/2023) =
* Allow HTML allowed in a caption to be used with videos. Previously HTML was stripped from the caption.
* Ensure that any links added to embed captions are clickable.

= 1.1.1 (20/12/2022) =
* Fixed a bug where the <figcaption> element was removed when the video thumbnail was clicked.

Expand Down

0 comments on commit 4e83ae3

Please sign in to comment.