This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Components/BlockVideoOembed): add component (#184)
* feat(Components/BlockVideoOembed): refactored component * refactor(Components/BlockVideoOembed): refactored js, optimized fields.json and changed howto
- Loading branch information
1 parent
bb9ccfd
commit 4f1835d
Showing
11 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
Components/BlockVideoOembed/Partials/OembedVideo/_playButton.styl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
$colorGray = lookup('$global-color-gray') || #333 | ||
$colorWhite = lookup('$global-color-white') || #fff | ||
$backgroundOpacity = .5 | ||
$borderWidth = 5px | ||
$transitionTime = .3s | ||
$transitionEasing = ease | ||
|
||
$playButtonCircleDiameter = { | ||
'desktop': 100px, | ||
'mobile': 60px | ||
} | ||
|
||
$playButtonTriangleSize = { | ||
'desktop': 40px, | ||
'mobile': 20px | ||
} | ||
|
||
$pseudoElementDefaults = { | ||
content: '' | ||
left: 50% | ||
position: absolute | ||
top: 50% | ||
transition: transform $transitionTime $transitionEasing | ||
} | ||
|
||
playButton(pseudoElementDefaults, colorPlayButton, backgroundOpacity, borderWidth, colorBorder, playButtonCircleDiameter, colorTriangle, playButtonTriangleSize) | ||
&::before | ||
{pseudoElementDefaults} | ||
background-color: rgba(colorPlayButton, backgroundOpacity) | ||
border: borderWidth solid colorBorder | ||
border-radius: (playButtonCircleDiameter.desktop / 2) | ||
height: playButtonCircleDiameter.desktop | ||
margin-top: -(playButtonCircleDiameter.desktop / 2) | ||
margin-left: -(playButtonCircleDiameter.desktop / 2) | ||
width: playButtonCircleDiameter.desktop | ||
|
||
+below('s') | ||
height: playButtonCircleDiameter.mobile | ||
margin-top: -(playButtonCircleDiameter.mobile / 2) | ||
margin-left: -(playButtonCircleDiameter.mobile / 2) | ||
width: playButtonCircleDiameter.mobile | ||
|
||
&::after | ||
{pseudoElementDefaults} | ||
border-bottom: (playButtonTriangleSize.desktop / 2) solid transparent | ||
border-left: playButtonTriangleSize.desktop solid colorTriangle | ||
border-top: (playButtonTriangleSize.desktop / 2) solid transparent | ||
height: 0 | ||
margin-top: -(playButtonTriangleSize.desktop / 2) | ||
margin-left:-(playButtonTriangleSize.desktop / 2 * .9) | ||
width: 0 | ||
|
||
+below('s') | ||
border-bottom: (playButtonTriangleSize.mobile / 2) solid transparent | ||
border-left: playButtonTriangleSize.mobile solid colorTriangle | ||
border-top: (playButtonTriangleSize.mobile / 2) solid transparent | ||
margin-top: -(playButtonTriangleSize.mobile / 2) | ||
margin-left: -(playButtonTriangleSize.mobile / 2 * .9) | ||
|
||
&:hover::before, | ||
&:hover::after | ||
transform: scale(1.1) |
37 changes: 37 additions & 0 deletions
37
Components/BlockVideoOembed/Partials/OembedVideo/_style.styl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@import '_playButton' | ||
|
||
.oembedVideo | ||
position: relative | ||
|
||
&-posterImage | ||
cursor: pointer | ||
position: absolute | ||
transition: visibility $transitionTime $transitionEasing | ||
visibility: visible | ||
z-index: 1 | ||
|
||
playButton($pseudoElementDefaults, $colorGray, $backgroundOpacity, $borderWidth, $colorWhite, $playButtonCircleDiameter, $colorWhite, $playButtonTriangleSize) | ||
|
||
&-isHidden | ||
visibility: hidden | ||
|
||
&-imageElement | ||
display: block | ||
height: auto | ||
width: 100% | ||
|
||
&-video | ||
height: 0 | ||
padding-bottom: percentage(9 / 16) | ||
visibility: hidden | ||
|
||
&-isVisible | ||
visibility: visible | ||
|
||
iframe | ||
display: block | ||
height: 100% | ||
left: 0 | ||
position: absolute | ||
top: 0 | ||
width: 100% |
14 changes: 14 additions & 0 deletions
14
Components/BlockVideoOembed/Partials/OembedVideo/index.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="oembedVideo"> | ||
<div class="oembedVideo-posterImage"> | ||
<img class="oembedVideo-imageElement" srcset=" | ||
{{ posterImage.src | resize(576, 324) }} 576w, | ||
{{ posterImage.src | resize(768, 432) }} 768w, | ||
{{ posterImage.src | resize(1200, 675) }} 1200w" | ||
src="{{ posterImage.src | resize(1200, 675) }}" | ||
sizes="(min-width: 1140px) 1140px, 100vw" | ||
alt="{{ posterImage.alt }}"> | ||
</div> | ||
<div class="oembedVideo-video"> | ||
{{ oembedLazyLoad }} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"layout": { | ||
"name": "blockVideoOembed", | ||
"label": "Block: Video Oembed", | ||
"sub_fields": [ | ||
{ | ||
"name": "posterImage", | ||
"label": "Poster Image", | ||
"type": "image", | ||
"mime_types": "jpg,jpeg", | ||
"min_width": 1200, | ||
"min_height": 675, | ||
"instructions": "Recommended Size: Min-Width 1200px; Min-Height: 675px; Image-Format: JPG, Aspect Ratio 16/9.", | ||
"required": 1 | ||
}, | ||
{ | ||
"label": "BlockVideoOembed", | ||
"name": "oembed", | ||
"type": "oembed", | ||
"required": 1 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Flynt\Components\BlockVideoOembed; | ||
|
||
use Flynt\Features\Components\Component; | ||
use Flynt\Utils\Oembed; | ||
|
||
add_action('wp_enqueue_scripts', function () { | ||
Component::enqueueAssets('BlockVideoOembed'); | ||
}); | ||
|
||
add_filter('Flynt/addComponentData?name=BlockVideoOembed', function ($data) { | ||
$data['oembedLazyLoad'] = Oembed::setOembedSrcAsDataAttribute( | ||
$data['oembed'], | ||
[ | ||
'autoplay' => 'true' | ||
] | ||
); | ||
|
||
return $data; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Developer HowTo´s | ||
|
||
## Global Default Poster Image | ||
|
||
`fields.json` | ||
```json | ||
{ | ||
"globalOptions": [ | ||
{ | ||
"name": "defaultPosterImage", | ||
"label": "Default Poster Image", | ||
"type": "image", | ||
"mime_types": "jpg,jpeg", | ||
"instructions": "Image-Format: JPG" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
`functions.php` | ||
```php | ||
<?php | ||
add_filter('Flynt/addComponentData?name=BlockVideoOembed', function ($data) { | ||
if (empty($data['posterImage'])) { | ||
$data['posterImage'] = $data['defaultPosterImage']; | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div is="flynt-block-video-oembed" class="flyntComponent"> | ||
<div class="blockVideoOembed"> | ||
{% include 'Partials/OembedVideo/index.twig' %} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Title: BlockVideoOembed | ||
|
||
---- | ||
|
||
Category: Block | ||
|
||
---- | ||
|
||
Tags: oembed, video, oembed, image | ||
|
||
---- | ||
|
||
Text: BlockVideoOembed component, can set a oembed video with a poster image. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class BlockVideoOembed extends window.HTMLDivElement { | ||
constructor (self) { | ||
self = super(self) | ||
self.$ = $(self) | ||
self.resolveElements() | ||
return self | ||
} | ||
|
||
resolveElements () { | ||
this.$posterImage = $('.oembedVideo-posterImage', this) | ||
this.$video = $('.oembedVideo-video', this) | ||
this.$iframe = $('iframe', this) | ||
} | ||
|
||
connectedCallback () { | ||
this.$iframe.on('load', this.onIframeLoad) | ||
this.$.on('click', this.$posterImage.selector, this.setIframeSrc) | ||
} | ||
|
||
setIframeSrc = () => { | ||
this.$iframe.attr('src', this.$iframe.data('src')) | ||
} | ||
|
||
onIframeLoad = () => { | ||
this.$video.addClass('oembedVideo-video-isVisible') | ||
this.$posterImage.addClass('oembedVideo-posterImage-isHidden') | ||
} | ||
} | ||
|
||
window.customElements.define('flynt-block-video-oembed', BlockVideoOembed, {extends: 'div'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
$rupture.scale = lookup('$global-layout-scale') || (0 576px 768px 992px 1200px) | ||
$rupture.anti-overlap = lookup('$global-layout-overlap') || -1px | ||
$gutterWidth = lookup('$global-layout-gutterWidth') || 15px | ||
$containerMaxWidth = lookup('$global-layout-containerMaxWidth') || 1140px | ||
|
||
[is='flynt-block-video-oembed'] | ||
*, | ||
*:before, | ||
*:after | ||
box-sizing: border-box | ||
|
||
.blockVideoOembed | ||
center($containerMaxWidth, $gutterWidth) | ||
|
||
@import 'Partials/OembedVideo/_style.styl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters