ericakfranz
7/31/2015 - 1:48 AM

Autoplay video sliders in Soliloquy. Works with all video types (self-hosted, YouTube, Vimeo and Wistia).

Autoplay video sliders in Soliloquy. Works with all video types (self-hosted, YouTube, Vimeo and Wistia).

<?php
/**
 * Plugin Name: Soliloquy - Autoplay Video Slides
 * Plugin URI: http://soliloquywp.com/
 * Description: Autoplay video sliders in Soliloquy. Works with all video types (self-hosted, YouTube, Vimeo and Wistia).
 * Version: 1.0.0
 * Author: Erica Franz
 * Author URI: https://fatpony.me/
 * License: GPL2
 */
 
 defined( 'ABSPATH' ) or die( 'No jellyfish!' );
 
 
add_action('wp_head', 'ekf_load_isInViewport_script');
function ekf_load_isInViewport_script() {
   echo '<script type="text/javascript">/*
 * @author  Mudit Ameta
 * @license https://github.com/zeusdeux/isInViewport/blob/master/license.md MIT
 */
!function(a,b){function c(b){var c,d=a("<div></div>").css({width:"100%"});return b.append(d),c=b.width()-d.width(),d.remove(),c}function d(e,f){var g=e.getBoundingClientRect(),h=g.top,i=g.bottom,j=g.left,k=g.right,l=a.extend({tolerance:0,viewport:b},f),m=!1,n=l.viewport.jquery?l.viewport:a(l.viewport);n.length||(console.warn("isInViewport: The viewport selector you have provided matches no element on page."),console.warn("isInViewport: Defaulting to viewport as window"),n=a(b));var o=n.height(),p=n.width(),q=n.get(0).toString();if(n[0]!==b&&"[object Window]"!==q&&"[object DOMWindow]"!==q){var r=n.get(0).getBoundingClientRect();h-=r.top,i-=r.top,j-=r.left,k-=r.left,d.scrollBarWidth=d.scrollBarWidth||c(n),p-=d.scrollBarWidth}return l.tolerance=~~Math.round(parseFloat(l.tolerance)),l.tolerance<0&&(l.tolerance=o+l.tolerance),0>=k||j>=p?m:m=l.tolerance?!!(h<=l.tolerance&&i>=l.tolerance):!!(i>0&&o>=h)}String.prototype.hasOwnProperty("trim")||(String.prototype.trim=function(){return this.replace(/^\s*(.*?)\s*$/,"$1")});var e=function(b){if(1===arguments.length&&"function"==typeof b&&(b=[b]),!(b instanceof Array))throw new SyntaxError("isInViewport: Argument(s) passed to .do/.run should be a function or an array of functions");for(var c=0;c<b.length;c++)if("function"==typeof b[c])for(var d=0;d<this.length;d++)b[c].call(a(this[d]));else console.warn("isInViewport: Argument(s) passed to .do/.run should be a function or an array of functions"),console.warn("isInViewport: Ignoring non-function values in array and moving on");return this};a.fn["do"]=function(a){return console.warn("isInViewport: .do causes issues in IE and some browsers since its a reserved. Use $.fn.run instead i.e., $(el).run(fn)."),e(a)},a.fn.run=e,a.extend(a.expr[":"],{"in-viewport":function(a,b,c){if(c[3]){var e=c[3].split(",");return 1===e.length&&isNaN(e[0])&&(e[1]=e[0],e[0]=void 0),d(a,{tolerance:e[0]?e[0].trim():void 0,viewport:e[1]?e[1].trim():void 0})}return d(a)}})}(jQuery,window);</script>';
 
}

add_action( 'soliloquy_api_on_load', 'ekf_autoplay_soliloquy_videos_onload' );
function ekf_autoplay_soliloquy_videos_onload( $data ) {
 
    ob_start();
    ?>
    var slide_video = soliloquy_<?php echo $data['id']; ?>.find('.soliloquy-item:not(.soliloquy-clone):eq(' + currentIndex + ') .soliloquy-video-icon');
    if ( slide_video.length > 0 ) {
                setTimeout(function(){
                    slide_video.trigger('click');
                }, 500);
    }
    <?php
    echo ob_get_clean();
 
}

add_action( 'soliloquy_api_after_transition', 'ekf_autoplay_soliloquy_videos_on_transition' );
function ekf_autoplay_soliloquy_videos_on_transition( $data ) {
 
    ob_start();
    ?>
    var slide_video = $(element).find('.soliloquy-video-icon');
    if ( slide_video.length > 0 ) {
                setTimeout(function(){
                    slide_video.trigger('click');
                }, 500);
    }
    <?php
    echo ob_get_clean();
 
}
?>