// social share function
;(function($){
/**
* jQuery function to prevent default anchor event and take the href * and the title to make a share pupup
*
* @param {[object]} e [Mouse event]
* @param {[integer]} intWidth [Popup width defalut 500]
* @param {[integer]} intHeight [Popup height defalut 400]
* @param {[boolean]} blnResize [Is popup resizeabel default true]
*/
$.fn.customerPopup = function (e, intWidth, intHeight, blnResize) {
// Prevent default anchor event
e.preventDefault();
// Set values for window
intWidth = intWidth || '500';
intHeight = intHeight || '400';
strResize = (blnResize ? 'yes' : 'no');
// Set title and open popup with focus on it
var strTitle = ((typeof this.attr('title') !== 'undefined') ? this.attr('title') : 'Social Share'),
strParam = 'width=' + intWidth + ',height=' + intHeight + ',resizable=' + strResize,
objWindow = window.open(this.attr('href'), strTitle, strParam).focus();
}
/* ================================================== */
$(document).ready(function ($) {
$('.customer.share').on("click", function(e) {
$(this).customerPopup(e);
});
});
}(jQuery));
/*** Functions ***/
var setupAttributeBox = function(config){
if (config.hasOwnProperty('attributes')) {
var attributes = config.attributes;
for (var key in attributes) {
var item = attributes[key];
if (jQuery('#attribute-box' + item.id).length > 0) {
for(var i = 0; i < item.options.length; i++){
var in_stock = (item.options[i].stock) ? 'in-stock' : 'out-of-stock';
jQuery('#attribute-box' + item.id).append('
'+ item.options[i].label +'');
}
}
}
}
}
jQuery(document).ready(function($){
/*** Event Callbacks ***/
var deviceWidth = window.innerWidth;
var isTablet = deviceWidth <= 1279;
var isMobile = deviceWidth <= 1024;
var isXSMobile = deviceWidth <= 480;
if(isMobile) {
// mobile menu
$('.megamenu li.parent').on('click', function(e) {
e.preventDefault();
if(!$(this).hasClass('active')) {
$('.megamenu li').removeClass('active');
$(this).addClass('active');
} else {
$(this).removeClass('active');
}
});
$('.megamenu .sub-wrapper a').on('click', function(e) {
e.stopPropagation();
});
}
if(isTablet) {
$('.header-top-link-ul li').on('click', function() {
if(!$(this).hasClass('active')) {
$('.header-top-link-ul li').removeClass('active');
$(this).addClass('active');
} else {
$(this).removeClass('active');
}
});
}
$('#dish').on('click', function() {
$('.nav-container.hidden-xs').toggleClass('visible');
});
// add class to clerk live search module
setTimeout(function() {
$('.livesearch-popup').next().addClass('live-search-wrapper');
}, 1000);
$(window).scroll(function(){
var searchPopup = $('.live-search-wrapper');
if($(searchPopup).is(':visible')) {
searchPopup.hide();
$('.arw-toggle-content.not_cat_search').removeClass('visible');
}
});
$('.read-more-button').on('click', function(){
var descHeight = ($(this).hasClass('read-less')) ? 100 : $('.shorten-description').prop('scrollHeight');
var readMsg = ($(this).hasClass('read-less')) ? Translator.translate('read more') : Translator.translate('read less');
//change height
$('.shorten-description').animate({
height: descHeight+'px'
}, 1000 );
//change button information
$(this).toggleClass('read-less');
$(this).html(readMsg);
});
// customer service tabs
$('body.cms-customer-service .tab-navigation li a').on('click', function(e) {
$('body.cms-customer-service .tab-navigation li').removeClass('active');
$(this).parent().addClass('active');
var tabID = $(this).attr('data-tab');
$('body.cms-customer-service .tab-content').removeClass('active');
$('#' + tabID).addClass('active');
if(history.pushState) {
history.pushState(null, null, '#' + tabID);
} else {
window.location.hash = '#' + tabID;
}
return false;
});
// activate the necessary tab for the customer service location
if(window.location.href.indexOf('/customer-service') > -1 && window.location.hash){
$('body.cms-customer-service .tab-navigation li a[href="'+ window.location.hash +'"]').click();
}
// product tabs
$('.tabs .tab-navigation li').on('click', function(e) {
e.preventDefault();
$('.tabs .tab-navigation li').removeClass('active');
$(this).addClass('active');
var tabID = $(this).find('span').attr('tab-data');
$('.tabs .tab-content').removeClass('active');
$('#' + tabID).addClass('active');
});
// custom newsletter popup
setTimeout(function(){
if (getCookie('dont_show_newsletter') == null && getCookie('newsletter_closed') == null) {
$('.custom-popup').fadeIn(400);
}
}, 60000); //60000 ms == 1 min
$('.home-custom-newsletter-popup .popup-close, .popup-overlay').on('click', function(e) {
var expire = new Date();
expire.setFullYear(expire.getFullYear() + 1);
if ($('#arw_dont_show_popup').prop('checked')) {
document.cookie = 'dont_show_newsletter=true; path=/; expires=' + expire.toGMTString();
}
//setup the closing cookie for the current session
document.cookie = 'newsletter_closed=true; path=/';
$('.custom-popup').fadeOut(400);
});
// quick access functions
$('.header-quick-access .header-mini-cart .arw-toggle-control, .total-badge, .fa-shopping-cart').on('click', function(e) {
e.stopPropagation();
if(!$('#arw_mini_cart_header').hasClass('visible')) {
$('#arw_mini_cart_header').addClass('visible');
} else {
$('#arw_mini_cart_header').removeClass('visible');
}
});
$('.header-quick-access .arw-toggle-container .arw-toggle-control.search').on('click', function(e) {
e.stopPropagation();
if(!$('.not_cat_search').hasClass('visible')) {
$('.not_cat_search').addClass('visible');
$('input[name="q"]').focus();
} else {
$('.not_cat_search').removeClass('visible');
$('.live-search-wrapper').hide();
}
});
// close quick access div
$('body').on('click', function() {
$('#arw_mini_cart_header').removeClass('visible');
$('.not_cat_search').removeClass('visible');
});
$(document).on('click', '.attribute-box li:not(.out-of-stock)', function(e){
e.stopPropagation();
var selectId = $(this).parents('.attribute-box').attr('id').replace('-box', '');
var value = $(this).attr('data-value');
if (!$(this).hasClass('selected')) {
$('.attribute-box li').removeClass('selected');
$(this).addClass('selected');
$('#' + selectId).val(value)
} else{
$(this).removeClass('selected');
$('#' + selectId).val('');
}
});
// product page show size guide popup
if ( $('body').hasClass('catalog-product-view') && $('.pschart-showsizes').length > 0 ) {
$('.table_size tr').removeClass('row');
}
$(document).on('click', '#size-guide', function(){
showSizeChart();
});
/*** Functions ***/
var getCookie = function(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
return unescape(dc.substring(begin + prefix.length, end));
}
});