Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
feat(Components/BlockVideoOembed): add component (#184)
Browse files Browse the repository at this point in the history
* feat(Components/BlockVideoOembed): refactored component

* refactor(Components/BlockVideoOembed): refactored js, optimized fields.json and changed howto
  • Loading branch information
usingthesystem authored and Doğa Gürdal committed May 11, 2017
1 parent bb9ccfd commit 4f1835d
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Components/BlockVideoOembed/Partials/OembedVideo/_playButton.styl
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 Components/BlockVideoOembed/Partials/OembedVideo/_style.styl
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 Components/BlockVideoOembed/Partials/OembedVideo/index.twig
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>
24 changes: 24 additions & 0 deletions Components/BlockVideoOembed/fields.json
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
}
]
}
}
20 changes: 20 additions & 0 deletions Components/BlockVideoOembed/functions.php
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;
});
28 changes: 28 additions & 0 deletions Components/BlockVideoOembed/howto.md
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'];
}
});
```
5 changes: 5 additions & 0 deletions Components/BlockVideoOembed/index.twig
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>
13 changes: 13 additions & 0 deletions Components/BlockVideoOembed/readme.md
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.
30 changes: 30 additions & 0 deletions Components/BlockVideoOembed/script.js
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'})
15 changes: 15 additions & 0 deletions Components/BlockVideoOembed/style.styl
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'
1 change: 1 addition & 0 deletions config/fieldGroups/pageComponents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"layouts": [
"Flynt/Components/BlockImage/Fields/Layout",
"Flynt/Components/BlockMediaText/Fields/Layout",
"Flynt/Components/BlockVideoOembed/Fields/Layout",
"Flynt/Components/BlockWysiwyg/Fields/Layout",
"Flynt/Components/SliderMedia/Fields/Layout"
]
Expand Down

0 comments on commit 4f1835d

Please sign in to comment.