(function( $ ) {
function reCalcBGImg(container) {
if(container.css('background-image') === 'none')
return;
var ratio = parseFloat(container.attr('data-img-ratio'));
var containerWidth = container.width();
var containerHeight = container.height();
var containerRatio = containerWidth/containerHeight;
if(ratio <= containerRatio) {
container
.css('background-position-x', '0px')
.css('background-position-y', (containerHeight - containerWidth / ratio) * 0.5 + 'px');
} else {
container
.css('background-position-x', (containerWidth - containerHeight * ratio) * 0.5 + 'px')
.css('background-position-y', '0px');
}
}
$( window ).resize( function() {
$('.t-reveal-effect').each(function( index, ele){
reCalcBGImg($(ele));
})
});
$( document ).ready(function() {
setTimeout(function(){
$( 'div.slick_testimonial_slider' ).each( function() {
var self = $(this);
var slidesToShow = parseInt((self.attr('data-slidestoshow') != null ) ? self.attr('data-slidestoshow') : 1, 10);
var slidesToScroll = parseInt((self.attr('data-slidestoscroll') != null ) ? self.attr('data-slidestoscroll') : 1, 10);
self.slick({
infinite: true,
useTransform: false,
lazyLoad: 'ondemand',
slidesToShow: slidesToShow,
slidesToScroll: slidesToScroll,
prevArrow: '',
nextArrow: '',
//autoplay: true,
autoplaySpeed: 10000,
responsive: [
{
breakpoint: 878,
settings: {
arrows: false
}
}
]
}).on('lazyLoaded', function (e, slick, image, imageSource) {
$tImg = image.next('.t-image');
var imgHeight = image.innerHeight();
var imgWidth = image.innerWidth();
var ratio = imgWidth / imgHeight;
var containerRatio = $tImg.width() / $tImg.height();
$tImg.attr('data-img-ratio', ratio);
$tImg.attr('data-img-width', imgWidth);
$tImg.attr('data-img-height', imgHeight);
$tImg.attr('data-container-width', $tImg.width());
$tImg.attr('data-container-height', $tImg.height());
$tImg.css('background-image','url("'+imageSource+'")'); //replace with background instead
reCalcBGImg($tImg);
image.attr('src',''); //remove source
image.remove();
});
});
}, 6000);
var registerMouseMove = false;
var prevX = null;
var prevY = null;
var ratio = 1;
$('.t-reveal-effect').hover(function(){
if(window.innerWidth < 992)
return;
ratio = parseFloat($(this).attr('data-img-ratio'));
var newHeight = $(this).parent().parent().parent().height() - 50;
var newWidth = $(this).parent().parent().width();
var containerRatio = newWidth/newHeight;
$(this).siblings('div').slideToggle();
if(ratio <= containerRatio) {
$(this).animate({
height: newHeight,
width: newWidth,
'background-position-x': '0px',
'background-position-y': (newHeight - newWidth / ratio) * 0.5 + 'px',
}, null, null, function(){registerMouseMove = true;});
} else {
$(this).animate({
height: newHeight,
width: newWidth,
'background-position-x': (newWidth - newHeight * ratio) * 0.5 + 'px',
'background-position-y': '0px',
}, null, 'linear', function(){registerMouseMove = true;});
}
prevX = null;
prevY = null;
$(this).find('.t-reveal-icon').fadeOut();
}, function() {
if(window.innerWidth < 992)
return;
registerMouseMove = false;
var oldHeight = parseInt($(this).attr('data-container-height'), 10);
var oldWidth = parseInt($(this).attr('data-container-width'), 10);
var containerRatio = oldWidth / oldHeight;
prevX = null;
prevY = null;
if(ratio <= containerRatio) {
$(this).animate({
height: oldHeight,
width: oldWidth,
'background-position-x': '0px',
'background-position-y': (oldHeight - oldWidth / ratio) * 0.5 + 'px',
});
} else {
$(this).animate({
height: oldHeight,
width: oldWidth,
'background-position-x': (oldWidth - oldHeight * ratio) * 0.5 + 'px',
'background-position-y': '0px',
});
}
$(this).siblings('div').slideToggle();
$(this).find('.t-reveal-icon').fadeIn();
}).on('mousemove', function( event ) {
if(window.innerWidth < 992)
return;
if(!registerMouseMove || prevX == null || prevY == null) {
prevX = event.clientX;
prevY = event.clientY;
return;
}
var scrollSpeed= parseFloat($(this).attr('data-scroll-speed'));
$(this).animate({
'background-position-x': '+=' + ((prevX - event.clientX)*scrollSpeed).toString(),
'background-position-y': '+=' + ((prevY - event.clientY)*scrollSpeed).toString()
}, 0);
prevX = event.clientX;
prevY = event.clientY;
});
$('.currency_switcher_select').each(function() {
var switcher = $(this);
switcher.ddslick({
width: '100%',
background: function() {
if(switcher.data("background") != ""){
return switcher.data("background");
} else {
return '#eee';
}
},
defaultSelectedIndex: function(){
return (switcher.data("currency") === "USD") ? 0 : 1;
},
onSelected: function(d) {
if(d.selectedData.value === switcher.data("currency"))
return;
var uri = window.location.href;
if (uri.search("wmc-currency=" + ((d.selectedData.value === 'USD') ? 'CAD' : 'USD')) !== -1) { // Cart
uri = uri.replace("wmc-currency=" + ((d.selectedData.value === 'USD') ? 'CAD' : 'USD'), "wmc-currency=" + d.selectedData.value);
} else {
uri += ((uri.search("\\?") !== -1) ? "&" : "?") + "wmc-currency=" + d.selectedData.value;
}
window.location.href = uri;
}
});
});
$( '.tc-notice .close-notice' ).on('click', function(){
var noticeID = $(this).parent().data('notice-id');
var dismissalType = $(this).parent().data('dismissal-type');
$(this).parent().remove();
$('.tc-notice').first().css('display', 'block');
if(dismissalType === 'permanent') {
var date = new Date();
date.setTime(date.getTime() + (364 * 24 * 60 * 60 * 1000));
document.cookie = 'notice-' + noticeID + '-dismissed' + "=1; expires=" + date.toUTCString() + "; path=/";
}
localStorage.setItem('notice-' + noticeID + '-dismissed', '1');
});
$( '.tc-notice' ).each(function() {
var $notice = $(this);
var noticeID = $notice.data('notice-id');
if(localStorage.getItem('notice-' + noticeID + '-dismissed') !== null) {
$notice.remove();
}
}).first().css('display', 'block');
});
})( jQuery );
function tc_send_event(obj) {
let event = new CustomEvent(obj['event_name'], { detail: obj['detail']});
window.dispatchEvent(event);
}