' ).addClass( 'vc_parallax-inner' ).appendTo( $( this ) );
$parallaxElement.height( skrollrSize + '%' );
parallaxImage = $( this ).data( 'vcParallaxImage' );
youtubeId = vcExtractYoutubeId( parallaxImage );
if ( youtubeId ) {
insertYoutubeVideoAsBackground( $parallaxElement, youtubeId );
} else if ( parallaxImage !== undefined ) {
$parallaxElement.css( 'background-image', 'url(' + parallaxImage + ')' );
}
skrollrSpeed = skrollrSize - 100;
skrollrStart = - skrollrSpeed;
skrollrEnd = 0;
$parallaxElement.attr( 'data-bottom-top', 'top: ' + skrollrStart + '%;' ).attr( 'data-top-bottom',
'top: ' + skrollrEnd + '%;' );
} );
if ( callSkrollInit && window.skrollr ) {
vcSkrollrOptions = {
forceHeight: false,
smoothScrolling: false,
mobileCheck: function () {
return false;
}
};
vcParallaxSkroll = skrollr.init( vcSkrollrOptions );
return vcParallaxSkroll;
}
return false;
};
/**
* @todo refactor as plugin.
* @returns {*}
*/
var fullHeightRow = function () {
$( '.vc_row-o-full-height:first' ).each( function () {
var $window,
windowHeight,
offsetTop,
fullHeight;
$window = $( window );
windowHeight = $window.height();
offsetTop = $( this ).offset().top;
if ( offsetTop < windowHeight ) {
fullHeight = 100 - offsetTop / (windowHeight / 100);
$( this ).css( 'min-height', fullHeight + 'vh' );
}
} );
};
$( window ).unbind( 'resize.vcRowBehaviour' ).bind( 'resize.vcRowBehaviour', local_function );
$( window ).bind( 'resize.vcRowBehaviour', fullHeightRow );
local_function();
fullHeightRow();
initVideoBackgrounds(); // must be called before parallax
parallaxRow();
}
}
if ( typeof window[ 'vc_gridBehaviour' ] !== 'function' ) {
window.vc_gridBehaviour = function () {
jQuery.fn.vcGrid && jQuery( '[data-vc-grid]' ).vcGrid();
}
}
/* Helper
---------------------------------------------------------- */
if ( typeof window[ 'getColumnsCount' ] !== 'function' ) {
window.getColumnsCount = function ( el ) {
var find = false,
i = 1;
while ( find == false ) {
if ( el.hasClass( 'columns_count_' + i ) ) {
find = true;
return i;
}
i ++;
}
}
}
var screen_size = getSizeName();
function getSizeName() {
var screen_size = '',
screen_w = jQuery( window ).width();
if ( screen_w > 1170 ) {
screen_size = "desktop_wide";
}
else if ( screen_w > 960 && screen_w < 1169 ) {
screen_size = "desktop";
}
else if ( screen_w > 768 && screen_w < 959 ) {
screen_size = "tablet";
}
else if ( screen_w > 300 && screen_w < 767 ) {
screen_size = "mobile";
}
else if ( screen_w < 300 ) {
screen_size = "mobile_portrait";
}
return screen_size;
}
function loadScript( url, $obj, callback ) {
var script = document.createElement( "script" );
script.type = "text/javascript";
if ( script.readyState ) { //IE
script.onreadystatechange = function () {
if ( script.readyState == "loaded" ||
script.readyState == "complete" ) {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
/*
script.onload = function(){
callback();
};
*/
}
script.src = url;
$obj.get( 0 ).appendChild( script );
}
if ( typeof window[ 'wpb_prepare_tab_content' ] !== 'function' ) {
/**
* Prepare html to correctly display inside tab container
*
* @param event - ui tab event 'show'
* @param ui - jquery ui tabs object
*/
window.wpb_prepare_tab_content = function ( event, ui ) {
var panel = ui.panel || ui.newPanel,
$pie_charts = panel.find( '.vc_pie_chart:not(.vc_ready)' ),
$round_charts = panel.find( '.vc_round-chart' ),
$line_charts = panel.find( '.vc_line-chart' ),
$carousel = panel.find( '[data-ride="vc_carousel"]' ),
$ui_panel, $google_maps;
vc_carouselBehaviour();
vc_plugin_flexslider( panel );
if ( ui.newPanel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).length ) {
ui.newPanel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).each( function () {
var grid = jQuery( this ).data( 'vcGrid' );
grid && grid.gridBuilder && grid.gridBuilder.setMasonry && grid.gridBuilder.setMasonry();
} );
}
if ( panel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).length ) {
panel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).each( function () {
var grid = jQuery( this ).data( 'vcGrid' );
grid && grid.gridBuilder && grid.gridBuilder.setMasonry && grid.gridBuilder.setMasonry();
} );
}
$pie_charts.length && jQuery.fn.vcChat && $pie_charts.vcChat();
$round_charts.length && jQuery.fn.vcRoundChart && $round_charts.vcRoundChart( { reload: false } );
$line_charts.length && jQuery.fn.vcLineChart && $line_charts.vcLineChart( { reload: false } );
$carousel.length && jQuery.fn.carousel && $carousel.carousel( 'resizeAction' );
$ui_panel = panel.find( '.isotope, .wpb_image_grid_ul' ); // why var name '$ui_panel'?
$google_maps = panel.find( '.wpb_gmaps_widget' );
if ( $ui_panel.length > 0 ) {
$ui_panel.isotope( "layout" );
}
if ( $google_maps.length && ! $google_maps.is( '.map_ready' ) ) {
var $frame = $google_maps.find( 'iframe' );
$frame.attr( 'src', $frame.attr( 'src' ) );
$google_maps.addClass( 'map_ready' );
}
if ( panel.parents( '.isotope' ).length ) {
panel.parents( '.isotope' ).each( function () {
jQuery( this ).isotope( "layout" );
} );
}
}
}
var vc_ttaActivation = function () {
jQuery( '[data-vc-accordion]' ).on( 'show.vc.accordion', function ( e ) {
var $ = window.jQuery, ui = {};
ui.newPanel = $( this ).data( 'vc.accordion' ).getTarget();
window.wpb_prepare_tab_content( e, ui );
} );
};
var vc_accordionActivate = function ( event, ui ) {
if ( ui.newPanel.length && ui.newHeader.length ) {
var $pie_charts = ui.newPanel.find( '.vc_pie_chart:not(.vc_ready)' ),
$round_charts = ui.newPanel.find( '.vc_round-chart' ),
$line_charts = ui.newPanel.find( '.vc_line-chart' ),
$carousel = ui.newPanel.find( '[data-ride="vc_carousel"]' );
if ( jQuery.fn.isotope != undefined ) {
ui.newPanel.find( '.isotope, .wpb_image_grid_ul' ).isotope( "layout" );
}
if ( ui.newPanel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).length ) {
ui.newPanel.find( '.vc_masonry_media_grid, .vc_masonry_grid' ).each( function () {
var grid = jQuery( this ).data( 'vcGrid' );
grid && grid.gridBuilder && grid.gridBuilder.setMasonry && grid.gridBuilder.setMasonry();
} );
}
//jQuery('html, body').animate({scrollTop: ui.newHeader.offset().top - 100}, 1000); // #1370 enhancement, #1762 issue.
vc_carouselBehaviour( ui.newPanel );
vc_plugin_flexslider( ui.newPanel );
$pie_charts.length && jQuery.fn.vcChat && $pie_charts.vcChat();
$round_charts.length && jQuery.fn.vcRoundChart && $round_charts.vcRoundChart( { reload: false } );
$line_charts.length && jQuery.fn.vcLineChart && $line_charts.vcLineChart( { reload: false } );
$carousel.length && jQuery.fn.carousel && $carousel.carousel( 'resizeAction' );
if ( ui.newPanel.parents( '.isotope' ).length ) {
ui.newPanel.parents( '.isotope' ).each( function () {
jQuery( this ).isotope( "layout" );
} );
}
}
};
/**
* Reinitialize all video backgrounds
*/
function initVideoBackgrounds() {
jQuery( '.vc_row' ).each( function () {
var $row = jQuery( this ),
youtubeUrl,
youtubeId;
if ( $row.data( 'vcVideoBg' ) ) {
youtubeUrl = $row.data( 'vcVideoBg' );
youtubeId = vcExtractYoutubeId( youtubeUrl );
if ( youtubeId ) {
$row.find( '.vc_video-bg' ).remove();
insertYoutubeVideoAsBackground( $row, youtubeId );
}
jQuery( window ).on( 'grid:items:added', function ( event, $grid ) {
if ( ! $row.has( $grid ).length ) {
return;
}
vcResizeVideoBackground( $row );
} );
} else {
$row.find( '.vc_video-bg' ).remove();
}
} );
}
/**
* Insert youtube video into element.
*
* Video will be w/o controls, muted, autoplaying and looping.
*/
function insertYoutubeVideoAsBackground( $element, youtubeId, counter ) {
if ( 'undefined' === typeof( YT.Player ) ) {
// wait for youtube iframe api to load. try for 10sec, then abort
counter = 'undefined' === typeof( counter ) ? 0 : counter;
if ( counter > 100 ) {
console.warn( 'Too many attempts to load YouTube api' );
return;
}
setTimeout( function () {
insertYoutubeVideoAsBackground( $element, youtubeId, counter ++ );
}, 100 );
return;
}
var player,
$container = $element.prepend( '
' ).find( '.inner' );
player = new YT.Player( $container[ 0 ], {
width: '100%',
height: '100%',
videoId: youtubeId,
playerVars: {
playlist: youtubeId,
iv_load_policy: 3, // hide annotations
enablejsapi: 1,
disablekb: 1,
autoplay: 1,
controls: 0,
showinfo: 0,
rel: 0,
loop: 1
},
events: {
onReady: function ( event ) {
event.target.mute().setLoop( true );
}
}
} );
vcResizeVideoBackground( $element );
jQuery( window ).bind( 'resize', function () {
vcResizeVideoBackground( $element );
} );
}
/**
* Resize background video iframe so that video content covers whole area
*/
function vcResizeVideoBackground( $element ) {
var iframeW,
iframeH,
marginLeft,
marginTop,
containerW = $element.innerWidth(),
containerH = $element.innerHeight(),
ratio1 = 16,
ratio2 = 9;
if ( ( containerW / containerH ) < ( ratio1 / ratio2 ) ) {
iframeW = containerH * (ratio1 / ratio2);
iframeH = containerH;
marginLeft = - Math.round( ( iframeW - containerW ) / 2 ) + 'px';
marginTop = - Math.round( ( iframeH - containerH ) / 2 ) + 'px';
iframeW += 'px';
iframeH += 'px';
} else {
iframeW = containerW;
iframeH = containerW * (ratio2 / ratio1);
marginTop = - Math.round( ( iframeH - containerH ) / 2 ) + 'px';
marginLeft = - Math.round( ( iframeW - containerW ) / 2 ) + 'px';
iframeW += 'px';
iframeH += 'px';
}
$element.find( '.vc_video-bg iframe' ).css( {
maxWidth: '1000%',
marginLeft: marginLeft,
marginTop: marginTop,
width: iframeW,
height: iframeH
} );
}
/**
* Extract video ID from youtube url
*/
function vcExtractYoutubeId( url ) {
if ( 'undefined' === typeof(url) ) {
return false;
}
var id = url.match( /(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/ );
if ( null != id ) {
return id[ 1 ];
}
return false;
}