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/BlockMediaText): add component (#183)
* feat(Components/BlockMediaText): refactored component * refactor(Components/BlockMediaText): finetuned naming and optimized image sizes
- Loading branch information
1 parent
3db3b60
commit bb9ccfd
Showing
13 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
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,4 @@ | ||
.image-imageElement | ||
display: block | ||
height: auto | ||
width: 100% |
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,6 @@ | ||
<img class="image-imageElement" srcset=" | ||
{{ image.src | resize(542) }} 542w, | ||
{{ image.src | resize(720) }} 720w" | ||
src="{{ image.src | resize(720) }}" | ||
sizes="(min-width: 1140px) 1140px, 100vw" | ||
alt="{{ image.alt }}"> |
62 changes: 62 additions & 0 deletions
62
Components/BlockMediaText/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/BlockMediaText/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% |
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 @@ | ||
<div class="oembedVideo"> | ||
<div class="oembedVideo-posterImage"> | ||
<img class="oembedVideo-imageElement" srcset=" | ||
{{ posterImage.src | resize(542, 305) }} 542w, | ||
{{ posterImage.src | resize(720, 405) }} 720w" | ||
src="{{ posterImage.src | resize(720, 405) }}" | ||
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,94 @@ | ||
{ | ||
"layout": { | ||
"name": "blockMediaText", | ||
"label": "Block: Media Text", | ||
"sub_fields": [ | ||
{ | ||
"name": "contentTab", | ||
"label": "Content", | ||
"type": "tab" | ||
}, | ||
{ | ||
"name": "mediaType", | ||
"label": "Media Type", | ||
"type": "select", | ||
"choices": { | ||
"image": "Image", | ||
"oembedVideo": "Oembed Video" | ||
} | ||
}, | ||
{ | ||
"name": "image", | ||
"label": "Image", | ||
"type": "image", | ||
"mime_types": "jpg,jpeg", | ||
"instructions": "Image-Format: JPG.", | ||
"required": 1, | ||
"conditional_logic": [ | ||
[ | ||
{ | ||
"fieldPath": "mediaType", | ||
"operator": "==", | ||
"value": "image" | ||
} | ||
] | ||
] | ||
}, | ||
{ | ||
"name": "posterImage", | ||
"label": "Poster Image", | ||
"type": "image", | ||
"mime_types": "jpg,jpeg", | ||
"instructions": "Image-Format: JPG, Aspect Ratio 16/9.", | ||
"required": 1, | ||
"conditional_logic": [ | ||
[ | ||
{ | ||
"fieldPath": "mediaType", | ||
"operator": "==", | ||
"value": "oembedVideo" | ||
} | ||
] | ||
] | ||
}, | ||
{ | ||
"label": "Oembed", | ||
"name": "oembed", | ||
"type": "oembed", | ||
"required": 1, | ||
"conditional_logic": [ | ||
[ | ||
{ | ||
"fieldPath": "mediaType", | ||
"operator": "==", | ||
"value": "oembedVideo" | ||
} | ||
] | ||
] | ||
}, | ||
{ | ||
"name": "contentHTML", | ||
"label": "Content", | ||
"type": "wysiwyg", | ||
"delay": 1, | ||
"toolbar": "full", | ||
"media_upload": 0, | ||
"required": 1 | ||
}, | ||
{ | ||
"name": "settingsTab", | ||
"label": "Settings", | ||
"type": "tab" | ||
}, | ||
{ | ||
"name": "mediaPosition", | ||
"label": "Media Position", | ||
"type": "select", | ||
"choices": { | ||
"mediaLeft": "Left", | ||
"mediaRight": "Right" | ||
} | ||
} | ||
] | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
namespace Flynt\Components\BlockMediaText; | ||
|
||
use Flynt\Features\Components\Component; | ||
use Flynt\Utils\Oembed; | ||
|
||
add_action('wp_enqueue_scripts', function () { | ||
Component::enqueueAssets('BlockMediaText'); | ||
}); | ||
|
||
add_filter('Flynt/addComponentData?name=BlockMediaText', function ($data) { | ||
if ($data['mediaType'] === 'oembedVideo') { | ||
$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=BlockMediaText', function ($data) { | ||
if ($data['mediaType'] === 'mediaVideo' && 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,14 @@ | ||
<div is="flynt-block-media-text" class="flyntComponent"> | ||
<div class="blockMediaText blockMediaText--{{ mediaPosition }}"> | ||
<div class="blockMediaText-columnMedia"> | ||
{% if mediaType == 'image' %} | ||
{% include 'Partials/Image/index.twig' %} | ||
{% elseif mediaType == 'oembedVideo' %} | ||
{% include 'Partials/OembedVideo/index.twig' %} | ||
{% endif %} | ||
</div> | ||
<div class="blockMediaText-columnContentHtml"> | ||
{{ contentHTML }} | ||
</div> | ||
</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: Block Media Text | ||
|
||
---- | ||
|
||
Category: Block | ||
|
||
---- | ||
|
||
Tags: image, embed, video, wysiwyg, content | ||
|
||
---- | ||
|
||
Text: Block Media Text component, can set an image or a video embed (with a required poster image) with some content HTML. You can choose the media position (left or right). |
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 BlockMediaText 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-media-text', BlockMediaText, {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,35 @@ | ||
$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-media-text'] | ||
*, | ||
*:before, | ||
*:after | ||
box-sizing: border-box | ||
|
||
.blockMediaText | ||
center($containerMaxWidth, $gutterWidth) | ||
|
||
&-columnMedia, | ||
&-columnContentHtml | ||
column(1/2, $gutter: 2) | ||
|
||
+below('s') | ||
stack() | ||
|
||
&--mediaRight | ||
.blockMediaText-columnMedia | ||
move(1/2, $gutter: 2) | ||
|
||
.blockMediaText-columnContentHtml | ||
move(-1/2, $gutter: 2) | ||
|
||
.blockMediaText-columnMedia, | ||
.blockMediaText-columnContentHtml | ||
+below('s') | ||
unmove() | ||
|
||
@import 'Partials/Image/_style.styl' | ||
@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