(function($) {
// Global functions ---------------------------------
$.fn.isInViewport = function( offtop ) {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + ( $(window).height() / offtop );
return elementBottom > viewportTop && elementTop < viewportBottom;
};
// Animate On Scroll Library ------------
AOS.init({
duration: 1500,
throttleDelay: 50,
anchorPlacement: 'top-bottom'
});
window.addEventListener('load', function () {
AOS.refresh();
});
// Scroll ------------
$('a[href^="#"]').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {
var target = $(this.hash);
if (target.length) {
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
$('html,body').animate({ scrollTop: target.offset().top }, 300);
return false;
}
}
});
// Get url parameter ------------
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
if ( getUrlParameter('updated') ||
getUrlParameter('contact_section') ) {
if ( $('#message').length > 0 ) {
$('html,body').animate({
scrollTop: $('#message').offset().top
}, 300);
}
}
// Chosen ------------
$("select").chosen({disable_search_threshold: 10});
// ACF ------------
$("input[type=hidden]").trigger('change');
$.each($('.acf-field-image'), function (index, acf_field_image) {
var acf_field_image = $(acf_field_image);
var label1 = acf_field_image.find('.acf-label label');
var input = acf_field_image.find('.acf-image-uploader > input');
label1.clone().prependTo(acf_field_image.find('.acf-image-uploader'));
var label2 = acf_field_image.find('.acf-image-uploader > label');
label2.addClass('file-upload');
label2.wrapInner('');
label2.append('Choose File');
input.prependTo( label2 );
var text = label2.find('.text').text();
input = label2.find('> input');
$( acf_field_image.find('.acf-basic-uploader input') ).on('change', function(e){
var fileName = '';
if($(this).files && $(this).files.length > 1){
fileName = ($(this).getAttribute('data-multiple-caption') || '').replace('{count}', $(this).files.length);
}else if(e.target.value){
fileName = e.target.value.split('\\').pop();
}
console.log(fileName);
(fileName) ? $(this).closest('.acf-field-image').find('.file-upload .text').html(fileName) : $(this).closest('.acf-field-image').find('.file-upload .text').html(text);
})
});
$.each($('.acf-field-file'), function (index, acf_field_file) {
var acf_field_file = $(acf_field_file);
var label1 = acf_field_file.find('.acf-label label');
var input = acf_field_file.find('.acf-file-uploader > input');
label1.clone().prependTo(acf_field_file.find('.acf-file-uploader'));
var label2 = acf_field_file.find('.acf-file-uploader > label');
label2.addClass('file-upload');
label2.wrapInner('');
label2.append('Choose File');
input.prependTo( label2 );
var text = label2.find('.text').text();
input = label2.find('> input');
$( acf_field_file.find('.acf-basic-uploader input') ).on('change', function(e){
var fileName = '';
if($(this).files && $(this).files.length > 1){
fileName = ($(this).getAttribute('data-multiple-caption') || '').replace('{count}', $(this).files.length);
}else if(e.target.value){
fileName = e.target.value.split('\\').pop();
}
console.log(fileName);
(fileName) ? $(this).closest('.acf-field-file').find('.file-upload .text').html(fileName) : $(this).closest('.acf-field-file').find('.file-upload .text').html(text);
})
});
$.each($('.acf-field-true-false'), function (index, true_false) {
var true_false = $(true_false);
var label = true_false.find('.acf-input label');
label.addClass('checkbox');
$('').insertAfter( label.find('input[type="checkbox"]') );
});
function throttle (func, interval) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function () {
timeout = false;
};
if (!timeout) {
func.apply(context, args)
timeout = true;
setTimeout(later, interval)
}
}
}
// Animation in ------------
var animation_in = (function () {
var animation = throttle(function() {
if ( $('.animation-in').length > 0) {
$('.animation-in').each(function() {
if ( $(this).isInViewport(1) ) {
$(this).addClass('animation-active');
var _this = $(this);
}
});
}
}, 50);
animation();
$(window).on('resize scroll', animation);
})();
// Core Components - start here
// --------------------------------------------
var hero = (function () {
var wpr = $('.hero');
if ( wpr.length > 0 ) {
// hero-slide
$('.hero .slides.slide').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
dots: true,
});
var change_word_length = wpr.find('.change-word span').length - 1;
$('.hero .WYSIWYG-styles h1').css('opacity', '1');
setInterval(function() {
var change_word_active = wpr.find('.change-word > span.is-visible');
if ( change_word_active.index() != change_word_length ) {
var next_change_word = change_word_active.next('span');
wpr.find('.change-word > span').addClass('is-hidden').removeClass('is-visible');
next_change_word.removeClass('is-hidden').addClass('is-visible');
} else {
wpr.find('.change-word > span').removeClass('is-visible').addClass('is-hidden');
wpr.find('.change-word > span:first-of-type').removeClass('is-hidden').addClass('is-visible');
}
}, 2000);
}
})();
// Nav ------------
var nav = (function () {
// var
var mouse_is_inside = false;
// cash
var $header = $('header');
var $nav = $('nav');
var $nav_mobile = $('nav.mobile');
var $close = $header.find('.toggle-nav');
var $header_search = $('.header-search-form');
// setup
// events
$close.on('click', toggleDropdown);
$header.find('.right li.search').on('click', function () {
$header_search.addClass('active');
});
$header_search.find('.close').on('click', function () {
$header_search.removeClass('active');
});
$('header nav, header .toggle-nav').hover( function(){
mouse_is_inside = true;
}, function(){
mouse_is_inside = false;
});
$("body").mouseup(function(){
if(!mouse_is_inside && $nav.hasClass('active') ) { toggleDropdown(); }
});
$nav.find('.search form > div > span').on('click', function () {
$nav.find('.search form > div .submit').trigger('click');
});
// function
function toggleDropdown(e) {
if ( $nav_mobile.hasClass('active') ) {
$nav_mobile.removeClass('active');
$close.removeClass('active');
$('body').css('height', "");
$('body').css('overflow', "");
} else {
$nav_mobile.addClass('active');
$close.addClass('active');
$('body').css('height', '100%');
$('body').css('overflow', 'hidden');
}
}
fixed_header();
$(window).scroll(function () { fixed_header(); });
// if ( $('.hero, .blog-single-page').length > 0 ) {
// $header.removeClass('darken');
// } else {
// $header.addClass('darken');
// }
function fixed_header() {
var scrollTop = $(window).scrollTop();
if (scrollTop > 0) {
$header.addClass('fixed darken');
} else {
$header.removeClass('fixed');
if ( $('.hero, .blog-single-page, .video_loop, #star_sales_page_hero').length > 0 ) {
$header.removeClass('darken');
} else {
$header.addClass('darken');
}
}
}
})();
var social_links_wpr = (function () {
var wpr = $('.blog-single-page');
if (wpr.length > 0) {
var content = wpr.find('.content');
var social = wpr.find('.social_links_wpr');
fix_scroll();
$(window).scroll(fix_scroll);
function fix_scroll() {
var scrollTop = $(window).scrollTop();
var content_top = content.offset().top;
var content_bottom = content_top + content.outerHeight() - social.outerHeight();
if ( scrollTop < content_top - 60) {
social.removeClass('fixed fixed-bottom');
} else if ( scrollTop >= content_top - 60 && scrollTop <= content_bottom - 60 ) {
social.addClass('fixed').removeClass('fixed-bottom');
} else {
social.removeClass('fixed').addClass('fixed-bottom');
}
}
}
})();
// breadcrumbs ------------
var breadcrumbs = (function () {
var wpr = $('.breadcrumbs');
if (wpr.length > 0) {
for (var i = 0; i < wpr.find('span').length; i++) {
wpr.html(function () {
return $(this).html().replace("ยป", "/");
})
}
}
})();
// tiles_image_text ------------
// var tiles_image_and_text = (function () {
// var wpr = $('.tiles_image_and_text');
//
// if ( wpr.length > 0 ) {
// var is_mobile = false;
// var rows = wpr.find('.row');
//
// fixed_image();
//
// $(window).scroll(function () {
// fixed_image();
// });
//
// function fixed_image() {
// is_mobile = wpr.find('.image').css('position') == 'static';
// if ( is_mobile ) {
// wpr.find('.image').removeClass('fixed').removeClass('fixed_bottom');
// } else {
// var scrollTop = $(window).scrollTop();
// var scrollBottom = $(window).scrollTop() + $(window).outerHeight();
//
// $.each(rows, function (key, value) {
// var _this_row = $(value);
// if ($(value).isInViewport(1)) {
// var value_top = _this_row.offset().top;
// var value_bottom = value_top + _this_row.outerHeight();
// var value_image = _this_row.find('.image');
//
// if (scrollTop <= value_top) {
// value_image.removeClass('fixed');
// value_image.removeClass('fixed_bottom');
// } else if ( scrollTop > value_top && scrollBottom <= value_bottom ) {
// value_image.addClass('fixed');
// value_image.removeClass('fixed_bottom');
// } else {
// value_image.removeClass('fixed');
// value_image.addClass('fixed_bottom');
// }
// }
// });
// }
// }
// }
// })();
// FAQ ------------
var faq = (function () {
var wpr = $('.FAQ');
if (wpr.length > 0) {
wpr.find('.question-title').on('click', function (e) {
var question = $(e.target).closest('.question');
question.find('.answer').slideToggle();
question.find('.plus-minus-toggle').toggleClass('collapsed');
});
}
})();
// link_boxes ------------
var link_boxes = (function () {
var wpr = $('.link_boxes');
if (wpr.length > 0) {
wpr.find('.box').hover(function (e) {
if ( ! $(this).hasClass('active')) {
var target = $(this);
$(this).addClass('active');
setTimeout(function () {
target.removeClass('active');
}, 3000);
}
});
}
})();
// modal ------------
var modal = (function () {
var modalLink = $('.modal-click');
var modal = $('.modal-wpr');
var close = modal.find('.close');
var mouse_is_inside = false;
var popups = $('.modal-wpr.popup');
$.each(popups, function (key, value) {
var target = $(value);
if ( target.hasClass('popup-page-exit') ) {
$(document).mouseleave(function () {
if ( ! target.hasClass('done') ) {
trigger(target, 'open');
target.addClass('done');
}
});
} else if ( target.hasClass('popup-timer') ) {
var time = target.data("time");
setTimeout(function () {
trigger(target, 'open');
}, time * 1000);
}
});
$('a[href^="#"]').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {
var target = $(this.hash);
if ( target.hasClass('modal-wpr') ) {
trigger(target);
}
}
});
modalLink.on('click', function(ev) {
console.log('modalLink');
var target = $($(this).data('target'));
trigger(target, null , ev);
});
close.on('click', function() {
console.log('close');
var target = $(this).closest('.modal-wpr');
trigger(target);
});
$('.modal-wpr .modal, .modal-wpr .close').hover( function(){ mouse_is_inside = true;
}, function(){ mouse_is_inside = false; });
modal.mouseup(function(){
if( ! mouse_is_inside && $(this).closest('.modal-wpr').hasClass('active') ) {
console.log('mouseup');
var target = $(this).closest('.modal-wpr');
trigger(target);
}
});
function trigger(target, toggle, ev) {
if ( ! toggle ) {
target.toggleClass('active');
} else if ( toggle == 'open' ) {
target.addClass('active');
} else if ( toggle == 'close' ) {
target.removeClass('active');
}
if ( target.hasClass('video-modal') ) {
if ( target.hasClass('active') ) {
if ( $(target).hasClass('video-Vimeo') ) {
var iframe = $(target).find('iframe')[0];
var player = new Vimeo.Player(iframe);
player.play();
} else if ( $(target).hasClass('video-Youtube') ) {
var iframe = $(target).find('iframe')[0];
iframe.src += "&autoplay=1";
ev.preventDefault();
}
} else {
if ( target.hasClass('video-Vimeo') ) {
var iframe = target.find('iframe')[0];
var player = new Vimeo.Player(iframe);
player.pause();
} else if ( target.hasClass('video-Youtube') ) {
var iframe = target.find('iframe');
var video = iframe.attr("src");
video = video.replace('&autoplay=1', '');
iframe.attr("src", "");
iframe.attr("src", video);
}
}
}
}
})();
var simple_image_banner = (function () {
var wpr = $('.simple_image_banner');
if ( wpr.length > 0 ) {
$.each(wpr, function (key, value) {
var image = $(value).find('.image');
if ( $(value).isInViewport(1) ) {
fix_scroll(value, image);
} else {
image.removeClass('fixed fixed-bottom');
}
$(window).scroll(function () {
if ( $(value).isInViewport(1) ) {
fix_scroll(value, image);
} else {
image.removeClass('fixed fixed-bottom');
}
});
})
function fix_scroll(value, image) {
var wpr = $(value);
var win_height = $(window).height();
var wpr_height = wpr.outerHeight();
if ( win_height < wpr_height ) {
var scrollTop = $(window).scrollTop();
var scrollMid = scrollTop + ($(window).height() / 2);
var wpr_top = wpr.offset().top;
var wpr_bottom = wpr_top + wpr_height - win_height;
if ( scrollTop < wpr_top ) {
image.removeClass('fixed fixed-bottom');
} else if ( scrollTop >= wpr_top && scrollTop <= wpr_bottom ) {
image.addClass('fixed');
image.removeClass('fixed-bottom');
} else {
image.removeClass('fixed');
image.addClass('fixed-bottom');
}
}
}
}
})();
// Core Components - end here ----------
// Custom Components ----------
function simpleParallax(elements) {
console.log(elements.length);
var ismobile = $('.simple_text .col-lg-6').css('max-width') == 'none';
$(window).resize(function() { ismobile = $('.simple_text .col-lg-6').css('max-width') == 'none'; });
function inViewport(node) {
var rect = node.getBoundingClientRect()
return ((rect.height > 0 || rect.width > 0) && rect.bottom >= 0 && rect.right >= 0 && rect.top <= (window.innerHeight || document.documentElement.clientHeight) && rect.left <= (window.innerWidth || document.documentElement.clientWidth))
}
$(window).scroll(function() {
var scrolled = $(window).scrollTop()
$(elements).each(function(index, element) {
var initY = $(this).offset().top
var height = $(this).outerHeight()
var endY = initY + $(this).outerHeight()
var intensity = $(this).data("intensity") ? $(this).data("intensity") : 0.2;
// Check if the element is in the viewport.
var visible = inViewport(this);
if ( visible ) {
if ( !ismobile ) {
var diff = (scrolled + $(window).height() / 2) - (initY + height/2);
var ratio = Math.round((diff / height) * 50);
$(this).css('transform', 'translateY(' + parseInt(-(ratio * intensity)) + 'px)');
} else {
$(this).css('transform', '');
}
}
});
});
}
if ( $('.parallax').length < 50 ) {
simpleParallax( $('.parallax') );
}
var contact_form = (function () {
var wpr = $('.form_contact form .acf-fields');
if (wpr.length > 0) {
var inputs = wpr.find('input, textarea');
$.each(inputs, function (key, input) {
var input_wpr = $(input).closest('.acf-field');
if (
input_wpr.hasClass('acf-field-true-false') ||
input_wpr.hasClass('acf-field-checkbox') ||
input_wpr.hasClass('acf-field-relationship') ||
input_wpr.hasClass('acf-field-select')
) {
} else {
var el = $(input).detach();
input_wpr.find('.acf-label').prepend(el);
}
if ( input_wpr.hasClass('acf-field-relationship') ) {
setTimeout(function () {
input_wpr.find('.acf-rel-item:contains("(draft)")').closest('li').remove();
}, 500);
}
});
function checkForInput(element) {
if ($(element).val().length > 0) {
$(element).addClass('active');
} else {
$(element).removeClass('active');
}
}
// The lines below (inside) are executed on change & keyup
$(inputs).on('change keyup', function() {
var input_wpr = $(this).closest('.acf-field');
if ( input_wpr.hasClass('acf-field-true-false') || input_wpr.hasClass('acf-field-checkbox') ) {
} else {
checkForInput(this);
}
});
}
})();
var testimonials_scroll = (function () {
var wpr = $('.testimonials_scroll');
if (wpr.length > 0) {
var testimonial = wpr.find('.wpr-img');
var testimonial_text = wpr.find('.wpr-text');
var scroll = throttle(function() {
if ( wpr.isInViewport(1) ) {
var scroll_top = $(window).scrollTop();
var scroll_mid = scroll_top + ($(window).height() / 2);
var scroll_bot = scroll_top + $(window).height();
$.each(testimonial, function (key, value) {
var value = $(value);
var testimonial_top = value.offset().top;
var testimonial_bot = testimonial_top + value.outerHeight();
if (scroll_mid >= testimonial_top && scroll_mid <= testimonial_bot) {
value.addClass('active');
testimonial_text.eq(key).addClass('active');
} else {
value.removeClass('active');
testimonial_text.eq(key).removeClass('active');
}
});
}
}, 50);
scroll();
$(window).on('resize scroll', scroll);
// $.each(wpr, function (key, value) {
// var image = $(value).find('.testimonial-background');
//
// if ( $(value).isInViewport(1) ) {
// fix_scroll(value, image);
// } else {
// image.removeClass('fixed fixed_bottom');
// }
//
// $(window).scroll(function () {
// if ( $(value).isInViewport(1) ) {
// fix_scroll(value, image);
// } else {
// image.removeClass('fixed fixed_bottom');
// }
// });
// })
function fix_scroll(value, image, textarea) {
var wpr = $(value);
var win_height = $(window).height();
var wpr_height = wpr.outerHeight();
if ( win_height < wpr_height ) {
var scrollTop = $(window).scrollTop();
var scrollMid = scrollTop + ($(window).height() / 2);
var wpr_top = wpr.offset().top;
var wpr_bottom = wpr_top + wpr_height - win_height;
if ( scrollTop < wpr_top ) {
image.removeClass('fixed fixed_bottom');
} else if ( scrollTop >= wpr_top && scrollTop <= wpr_bottom ) {
image.addClass('fixed').removeClass('fixed_bottom');
} else {
image.removeClass('fixed').addClass('fixed_bottom');
}
}
}
}
})();
var text_in = (function () {
// setup
function wrapWords(str, tmpl) {
console.log(str);
if ( str.indexOf("href=") <= 0 ) {
return str.replace(/\S+/g, tmpl || "$&");
}
}
function changeText(s){
var div = document.createElement('div');
div.innerHTML = s;
recurseDomChildren(div, true);
var str = div.innerHTML.replace(/spfrnt/g, "").replace(/spback/g, "");
return str;
}
function recurseDomChildren(start, output){
var nodes;
if(start.childNodes){
nodes = start.childNodes;
loopNodeChildren(nodes, output);
}
}
function loopNodeChildren(nodes, output){
var node;
for(var i=0;i 0 ) {
} else {
$(val).wrapInner( "" );
var text = $(val).html();
$(val).html( changeText(text) );
}
});
var animation = throttle(function() {
if ( $('.WYSIWYG-styles:not(.hero-text) h1').length > 0) {
$.each($('.WYSIWYG-styles:not(.hero-text) h1'), function(key, val) {
var val = $(val);
if ( val.isInViewport(1) && ! val.hasClass('done') ) {
$(this).addClass('done');
var height = val.outerHeight();
val.addClass('in-'+ key)
anime.timeline({loop: false}).add({
targets: 'h1.in-'+ key +' .word',
translateY: 0,
translateX: [50,0],
translateZ: 0,
opacity: [0, 1],
duration: 1200,
easing: "easeOutElastic(1, .8)",
delay: anime.stagger(120, {start: 200}),
});
}
});
}
}, 50);
animation();
$(window).on('resize scroll', animation);
})();
var quick_download = (function () {
var wpr = $('.quick_download');
if (wpr.length > 0) {
if ( wpr.find('.download-btn').hasClass('Automatic') ) {
wpr.find('.download-btn')[0].click();
console.log('download 2');
}
}
})();
var simple_video = (function () {
var wpr = $('.simple_video');
if (wpr.length > 0) {
wpr.find('.video_image_wpr').on('click', function () {
$(this).find('.video').addClass('active');
if ( $(this).find('.video').hasClass('video-Vimeo') ) {
var iframe = $(this).find('iframe')[0];
var player = new Vimeo.Player(iframe);
player.play();
} else if ( $(this).find('.video').hasClass('video-Youtube') ) {
var iframe = $(this).find('iframe')[0];
iframe.src += "&autoplay=1";
ev.preventDefault();
}
});
}
})();
// slider ------------
var testimonials_slider = (function () {
var wpr = $('.testimonials_slider');
if (wpr.length > 0) {
wpr.find('.slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
dots: false,
autoplay: true,
autoplaySpeed: 5000
});
wpr.find('.arrow.next').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickNext');
});
wpr.find('.arrow.back').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickPrev');
});
}
})();
// video slider ------------
var video_slider = (function () {
var wpr = $('.video_slider');
if (wpr.length > 0) {
wpr.find('.slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
dots: true,
autoplay: false
});
wpr.find('.arrow.next').on('click', function () {
var iframe = wpr.find('.slider-wpr .slide-item.slick-active iframe')[0];
$(this).closest('.slider-wpr').find('.slider').slick('slickNext')
var player = new Vimeo.Player(iframe);
player.pause();
});
wpr.find('.arrow.back').on('click', function () {
var iframe = wpr.find('.slider-wpr .slide-item.slick-active iframe')[0];
$(this).closest('.slider-wpr').find('.slider').slick('slickPrev');
var player = new Vimeo.Player(iframe);
player.pause();
});
}
})();
// Team Bio slider ------------
var testimonials_slider = (function () {
var wpr = $('.team_bio');
if (wpr.length > 0) {
wpr.find('.slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
dots: false,
autoplay: true,
autoplaySpeed: 5000
});
wpr.find('.arrow.next').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickNext');
});
wpr.find('.arrow.back').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickPrev');
});
}
})();
var section_instagram_feed = (function () {
var wpr = $('#instagram_feed');
if (wpr.length > 0) {
function insta_cache(error) {
console.log( error );
console.log('insta_cache');
var count = localStorage.getItem('imgDataCount');
if ( count != null && count > 0 ) {
var insta_images = [];
for (var i = 0; i < count; i++) {
insta_images[i] = localStorage.getItem('imgData-'+i);
}
for (var i = 0; i < insta_images.length; i++) {
wpr.append('');
}
}
}
function insta_done() {
setTimeout(function () {
console.log('insta_done');
var imgs = wpr.find("img");
localStorage.setItem("imgDataCount", imgs.length );
$.each(imgs, function (key, value) {
var src = $(value).attr('src');
localStorage.setItem("imgData-"+key, src);
});
}, 1000);
}
$.instagramFeed({
'username': 'sarahjenks',
'container': document.getElementById("instagram_feed"),
'display_profile': false,
'display_biography': false,
'display_gallery': true,
'styling': true,
'items': 4,
'items_per_row': 2,
'margin': 0,
'host': 'https://images' + ~~(Math.random() * 3333) + '-focus-opensocial.googleusercontent.com/gadgets/proxy?container=none&url=https://www.instagram.com/',
'callback': insta_done,
'on_error': insta_cache,
});
}
})();
// Countdown Timer ----------
var timer = (function() {
var wpr = $('.nav-timer');
if (wpr.length > 0) {
$.each(wpr, function (key, value) {
var time = $(value).data("time");
var newYork = moment(time).tz('America/New_York');
initializeClock(newYork.format(), $(value));
});
}
function getTimeRemaining(endtime) {
var currentTime = moment().tz("America/Los_Angeles").format('YYYY-MM-DD HH:mm:ss');
var bits = currentTime.split(/\D/);
var currentTime = new Date(bits[0], --bits[1], bits[2], bits[3], bits[4], bits[5]);
var t = Date.parse(endtime) - Date.parse(currentTime);
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
return {'total': t, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds};
}
function convertUTCDateToLocalDate(date) {
var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
var offset = date.getTimezoneOffset() / 60;
var hours = date.getHours();
newDate.setHours(hours - offset);
return newDate;
}
function initializeClock(endtime, this_wpr) {
var clock = this_wpr.find('.numbers');
var daysSpan = clock.find('.days');
var hoursSpan = clock.find('.hours');
var minutesSpan = clock.find('.minutes');
var secondsSpan = clock.find('.seconds');
function updateClock() {
var t = getTimeRemaining(endtime);
if ( t.days >= 100 ) {
console.log('not time');
clearInterval(timeinterval);
clock.css('opacity', 0);
} else if (t.total <= 0) {
clearInterval(timeinterval);
console.log('time done');
// wpr.remove();
} else {
if (t.days > 0) {
daysSpan.html(t.days);
} else {
daysSpan.closest('p').remove();
}
if (t.hours > 0) {
hoursSpan.html(t.hours);
} else if ( t.days == 0 && t.hours == 0 ) {
hoursSpan.closest('p').remove();
}
if (t.minutes > 0) {
minutesSpan.html(t.minutes);
}
if (t.seconds > 0) {
secondsSpan.html(t.seconds);
}
}
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}
})();
var fixed_timer = (function() {
var wpr = $('.countdown_timer')
if (wpr.length > 0) {
var countdown = wpr.find('.countdown');
var is_header_fixed = true;
var header_offset = 0;
if ( is_header_fixed ) {
var header = $('header.main');
var header_offset = header.outerHeight();
}
if ( wpr.offset().top - header_offset <= $(window).scrollTop() ) {
countdown.addClass('fixed').css('top', header_offset+'px');
}
$(window).scroll(function () {
var header_offset = 0;
if ( is_header_fixed ) {
var header = $('header.main');
var header_offset = header.outerHeight();
}
if ( wpr.offset().top - header_offset <= $(window).scrollTop() ) {
countdown.addClass('fixed').css('top', header_offset+'px');
} else {
countdown.removeClass('fixed').css('top', '');
}
});
}
})();
// Star testimonials ------------
var star_testimonials_slider = (function () {
var wpr = $('#star_sales_page_testimonials');
if (wpr.length > 0) {
wpr.find('.slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: false,
dots: false,
autoplay: true,
autoplaySpeed: 5000,
responsive: [
{ breakpoint: 1080,
settings: {
autoplay: false,
adaptiveHeight: true,
}
}
]
});
wpr.find('.arrow.next').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickNext');
});
wpr.find('.arrow.back').on('click', function () {
$(this).closest('.slider-wpr').find('.slider').slick('slickPrev');
});
}
})();
// Animations
var star_animations = (function () {
let burst_large = '.accent-radial-burst-large',
small_burst = '.accent-small-burst',
card_image = '.star-card-image',
background_disc = '.background-disc',
hand_left = '.accent-hand-left';
var window_width = $(window).width() - $(hand_left).width();
var window_height = $(window).height();
var document_height = $(document).height() - $(window).height();
// Map function ------------
function map(value, in_min, in_max, out_min, out_max) {
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
let hand_left_scroll_start = 0;
let hand_left_scroll_end = 0;
let card_fade_start = 0;
let card_fade_end = 0;
$(window).on("load resize scroll", function() {
let scrolled = $(window).scrollTop();
let scrolled_mid = scrolled + (window_height / 2);
// team - sun burst
if ( $(burst_large).length > 0 ) {
if( isInViewport(burst_large) ) {
$(burst_large).find('.inner').css({transform: 'rotate('+ (180*window.pageYOffset/(document.body.clientHeight - window.innerHeight)) +'deg)'});
}
}
// transformed - left hand
if ( $(hand_left).length > 0 ) {
if( isInViewport(hand_left) ) {
if ( hand_left_scroll_start == 0 ) {
hand_left_scroll_start = scrolled_mid;
hand_left_scroll_end = hand_left_scroll_start + window_height;
}
let position_left = map(scrolled_mid, hand_left_scroll_start, hand_left_scroll_end, -131, -31);
if ( Math.round(position_left) > -131 && Math.round(position_left) <= -31 ) {
$(hand_left).css("transform", "translateX("+ Math.round(position_left) +"%) translateY(-47%)");
}
}
}
// transformed - 'the star' card
if ( $(card_image).length > 0 ) {
if( isInViewport(card_image) ) {
if ( card_fade_start == 0 ) {
card_fade_start = scrolled_mid;
card_fade_end = card_fade_start + window_height;
}
let fade_in = map(scrolled_mid, card_fade_start, card_fade_end, 0, 40);
let test = fade_in - Math.floor(fade_in)
if ( Math.round(fade_in) >= 0 && Math.round(fade_in) <= 40 ) {
$(card_image).css("opacity", (Math.round(fade_in)/100).toFixed(2) );
}
}
}
// products - background disc
if ( $(background_disc).length > 0 ) {
if( isInViewport(background_disc) ) {
let offset = $(background_disc).offset().top,
height = offset + $(background_disc).height(),
diff = (scrolled + $(window).height()/2) - offset,
ratio = Math.round((diff / height) * 50);
$(background_disc).find('.inner').css('transform', 'translateY(' + parseInt(-(ratio * 15)) + 'px)');
}
}
// products - small burst
if ( $(small_burst).length > 0 ) {
if( isInViewport(small_burst) ) {
$(small_burst).find('.inner').css({transform: 'rotate('+ (180 * window.pageYOffset/(document.body.clientHeight - window.innerHeight)) +'deg)'});
}
}
});
function isInViewport(el) {
var elementTop = $(el).offset().top;
var elementBottom = elementTop + $(el).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
})();
})( jQuery );