Skip to content

Instantly share code, notes, and snippets.

@maykbrito
Created October 3, 2017 21:44
Show Gist options
  • Save maykbrito/40837c809e29e5d4cdb74a4e44f15469 to your computer and use it in GitHub Desktop.
Save maykbrito/40837c809e29e5d4cdb74a4e44f15469 to your computer and use it in GitHub Desktop.
<?php
class VimeoBackground {
public function __construct(){}
public function do_shortcode()
{
add_shortcode( 'vimeobackground', array($this, 'vimeo_wrapper'));
}
public function style($boxed = false)
{
// se for pra ficar dentro de alguma div, use relative
// se for pra ficar fixo, use ... you got it!
$position = $boxed ? "relative" : "fixed";
echo "<style>
.vimeo-wrapper {
position: " . $position . ";
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
pointer-events: none;
overflow: hidden;
}
.vimeo-wrapper iframe {
width: 100vw;
height: 56.25vw; /* Given a 16:9 aspect ratio, 9/16*100 = 56.25 */
min-height: 100vh;
min-width: 177.77vh; /* Given a 16:9 aspect ratio, 16/9*100 = 177.77 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}</style>";
}
public function vimeo_wrapper($att)
{
if (array_key_exists("video", $att)) {
if (array_key_exists("boxed", $att))
$this->style(true);
else $this->style();
return sprintf('<div class="vimeo-wrapper"><iframe src="https://player.vimeo.com/video/%s?background=1&autoplay=1&loop=1&byline=0&title=0"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>', $att['video']);
} else
{
return "Atributo 'video' not foi especificado no shortcode";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment