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

Commit

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

* refactor(Components/BlockMediaText): finetuned naming and optimized image sizes
  • Loading branch information
usingthesystem authored and Doğa Gürdal committed May 11, 2017
1 parent 3db3b60 commit bb9ccfd
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Components/BlockMediaText/Partials/Image/_style.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.image-imageElement
display: block
height: auto
width: 100%
6 changes: 6 additions & 0 deletions Components/BlockMediaText/Partials/Image/index.twig
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 Components/BlockMediaText/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/BlockMediaText/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%
13 changes: 13 additions & 0 deletions Components/BlockMediaText/Partials/OembedVideo/index.twig
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>
94 changes: 94 additions & 0 deletions Components/BlockMediaText/fields.json
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"
}
}
]
}
}
21 changes: 21 additions & 0 deletions Components/BlockMediaText/functions.php
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;
});
28 changes: 28 additions & 0 deletions Components/BlockMediaText/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=BlockMediaText', function ($data) {
if ($data['mediaType'] === 'mediaVideo' && empty($data['posterImage'])) {
$data['posterImage'] = $data['defaultPosterImage'];
}
});
```
14 changes: 14 additions & 0 deletions Components/BlockMediaText/index.twig
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>
13 changes: 13 additions & 0 deletions Components/BlockMediaText/readme.md
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).
30 changes: 30 additions & 0 deletions Components/BlockMediaText/script.js
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'})
35 changes: 35 additions & 0 deletions Components/BlockMediaText/style.styl
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'
1 change: 1 addition & 0 deletions config/fieldGroups/pageComponents.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"button_label": "Add Component",
"layouts": [
"Flynt/Components/BlockImage/Fields/Layout",
"Flynt/Components/BlockMediaText/Fields/Layout",
"Flynt/Components/BlockWysiwyg/Fields/Layout",
"Flynt/Components/SliderMedia/Fields/Layout"
]
Expand Down

0 comments on commit bb9ccfd

Please sign in to comment.