// JQuery
var jQ = jQuery.noConflict();
jQ(document).ready(function() {
///// GENERAL SITEWIDE JS
var Mediabox = '';
//set path's if VSM or live
var loc = window.location;
vsmURL = loc.protocol + '//' + loc.hostname + '/';
if (vsmURL.indexOf('vsmtools') > -1 ) {
vsmURL = vsmURL + 'U/575/';
} else {
vsmURL = '';
}
var vars = [], hash;
var q = document.URL.split('?')[1];
if(q != undefined){
q = q.split('&');
for(var i = 0; i < q.length; i++){
hash = q[i].split('=');
vars.push(hash[1]);
vars[hash[0]] = hash[1];
}
}
// Stick Nav Header
jQ(window).scroll(function() {
if (jQ(this).scrollTop() > 1){
jQ("body").addClass('stuck');
} else {
jQ("body").removeClass('stuck');
}
if (jQ(this).scrollTop() > 500){
jQ("body").addClass('stuck2');
} else {
jQ("body").removeClass('stuck2');
}
});
// add classes to body for specific page
// add name of current selected nav page class to body
jQ("nav a.selected").each (function () {
var currentPage = jQ(this).text().toLowerCase().replace(/(^\s+|[^a-zA-Z0-9 ]+|\s+$)/g,"").replace(/\s+/g, "-");
jQ('body').addClass(currentPage);
});
// add name of current page title class to body
var currentPageTitle = jQ("h1.pagename").text().toLowerCase().replace(/(^\s+|[^a-zA-Z0-9 ]+|\s+$)/g,"").replace(/\s+/g, "-");
// add id of current page as well (sicne this doesn't change)
var currentPageID = jQ('#divNavPath').attr('class');
jQ('body').addClass(currentPageTitle + ' page'+currentPageID);
// Hide 'No Product' Display message if no products
if (!jQ('.product-wrap .product-item').length) {
jQ('.product-wrap').remove();
}
///// HOME JS
if (jQ('body.page-home').length) {
// Home Slider
// Clean out inputs within VSM generated gallery
jQ('.home-slider input').remove();
var homeSlider = jQ(".home-slider");
// set slider imag as background
jQ('.home-slider .gal-image-wrap').each (function (){
var imgSRC = jQ(this).find('img').attr('src');
jQ(this).css('background-image', 'url('+ imgSRC +')');
jQ(this).find('img').remove();
});
//jQ('.galDescription').wrap("
");
homeSlider.owlCarousel({
items:1,
dots:true,
nav:false,
animateIn:'fadeIn',
animateOut:'fadeOut',
lazyLoad:true,
margin:0,
loop:false,
autoplay:true,
autoplayTimeout:8000,
autoplayHoverPause:false,
smartSpeed:450,
responsiveRefreshRate:0
});
// Home Product Slider
jQ('.product-wrap input, .product-wrap script, .ecomPag').remove();
var homeProdSlider = jQ(".product-wrap");
homeProdSlider.owlCarousel({
items:6,
itemElement: 'a',
dots:false,
nav:false,
lazyLoad:true,
margin:10,
loop:true,
checkVisible:false,
autoplay:true,
autoplayTimeout:5000,
autoplayHoverPause:false,
smartSpeed:450,
responsiveRefreshRate:0,
responsive : {
0 : {
items:1
},
400 : {
items:2
},
600 : {
items:3
},
800 : {
items:4
},
1200 : {
items:6
},
1800 : {
items:8
}
}
});
// Set Size of SLider Circle
//var sliderHeight = jQ('.slider-text').outerHeight() + 50;
//jQ('.slider-text').css('height', sliderHeight);
//jQ('.slider-text').css('width', sliderHeight);
}
///// STATIC PAGES JS
if (jQ('body.page-pages').length) {
// Set Hero Image to Background
if (jQ('.hero-base').attr('data-pageicon').contains(".jpg") || jQ('.hero-base').attr('data-pageicon').contains(".JPG")) {
var pageiconImage = jQ('.hero-base').attr('data-pageicon');
console.log(pageiconImage);
jQ('.hero-base').css('background-image', 'url(' + pageiconImage + ')');
}
// Has no sub nav then make full width
if (!jQ('.sub-nav .l2').length) {
jQ('.main').attr('class', 'main');
jQ('.sub-nav').remove();
}
// Product details page
if (jQ('.product-details-wrap').length) {
// Increment & Decrement
jQ('.plus-button').click(function() {
var $input = jQ('.product-qty input');
var value = parseInt($input.val());
value = value + 1;
$input.val(value);
});
jQ('.minus-button').click(function() {
var $input = jQ('.product-qty input');
var value = parseInt($input.val());
if (value > 1) {
value = value - 1;
} else {
value = 1;
}
$input.val(value);
});
// Set product images as backgrounds
if (jQ('.item-image').length) {
jQ('.item-image').each (function (){
var imgSRC = jQ(this).find('img').attr('src');
// if no image
if (imgSRC == null) {
jQ(this).css('background-image', 'url(https://dummyimage.com/600x600/fff/000.png&text=Image+Coming+Soon)');
} else {
jQ(this).css('background-image', 'url('+ encodeURI(imgSRC) +')');
jQ(this).attr('data-path', encodeURI(imgSRC));
jQ(this).find('img:not(.thumb-prodImage)').remove();
}
});
}
// when add to cart button is clicked set sessionStorage vars for added alert
jQ('input[name="btnAddtoCartS"]').click(function() {
sessionStorage.setItem("prodName", jQ('.product-top .product-name').html());
});
if (sessionStorage.getItem('prodName')) {
var prodName = sessionStorage.getItem('prodName');
jQ('.content-wrap').prepend('');
jQ('#overlay').delay(500).slideDown();
sessionStorage.removeItem("prodName");
jQ('#overlay').click(function(){
jQ(this).slideUp();
});
}
// Clean/Update Lightbox & thumbnail area on Details Page
// remove old pop-up links
jQ('.prod-right .details-mainImg-Wrap').remove();
// create new row for thumbs
jQ('.item-image-details').after('');
// if has thumbnails, put in a new container.
if (jQ('.thumb-prodImage').length) {
var prodThumbs = jQ('.item-image-details').html();
jQ('.prod-thumbs-wrap').html(prodThumbs);
jQ('.item-image-details').empty();
jQ('.prod-thumbs-wrap img').each(function() {
var imgSRC = jQ(this).attr('src');
jQ(this).wrap('');
jQ(this).remove();
});
} else {
// only one product image
var imgSRC = jQ('.item-image-details').attr('data-path');
jQ('.prod-thumbs-wrap').html('');
}
// Image Zoom on Hover
function imgZoom() {
if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
jQ('.item-image-details')
.on('mouseover', function(){
jQ(this).children('.photo').css({'transform': 'scale(2.4)'});
})
.on('mouseout', function(){
jQ(this).children('.photo').css({'transform': 'scale(1)'});
})
.on('mousemove', function(e){
jQ(this).children('.photo').css({'transform-origin': ((e.pageX - jQ(this).offset().left) / jQ(this).width()) * 100 + '% ' + ((e.pageY - jQ(this).offset().top) / jQ(this).height()) * 100 +'%'});
});
jQ('.item-image-details').append('').children('.photo').css({'background-image': 'url('+ jQ('.item-image-details').attr('data-path') +')'})
}
}
imgZoom();
// Update Large image with thumbs
jQ('.thumb-image').click(function() {
var thumbImgSRC = jQ(this).attr('data-path');
jQ('.item-image-details').attr('data-path', encodeURI(thumbImgSRC));
jQ('.item-image-details').css('background-image', 'url('+ encodeURI(thumbImgSRC) +')');
jQ('.item-image-details').removeClass('has-video');
jQ('.item-image-details').empty();
jQ('.thumb-image').removeClass('thumb-selected');
jQ(this).toggleClass('thumb-selected');
imgZoom();
});
// show popup on main image click
jQ('.item-image-details').on('click', function() {
function showPopUp () {
jQ('.product-image-area').wrapInner('');
jQ.magnificPopup.open({
items: {
src: '.popup-wrap',
type: 'inline'
},
callbacks: {
// Disable click on main image if in pop-up
open: function() {
jQ('.item-image-details').off('click');
},
afterClose: function() {
jQ('.thumb-image:first').click();
jQ('.popup-wrap').attr('class', '');
jQ('.item-image-details').on('click', function() {
showPopUp();
});
imgZoom();
}
}
});
}
showPopUp();
});
// Hide Related if empty.
if (!jQ('.related-wrap .product-item-image').length) {
jQ('.product-associated').remove();
}
}
// Info Library
if (jQ(".plant-info-list-wrap.main-list").length) {
// Format Categories
jQ('.sorted li').each (function (){
var cats = jQ(this).find('.categories').text().replace(/,/g, '').replace(/ /g,'').length - 1;
// Duplicate item if more than one category
for (var i = 0; i < cats; i++) {
jQ('.cloned').append(jQ(this.clone()));
}
// Remove Last cat from duplicated items for sorting later
var trimLast = jQ(this).find('.categories').text().replace(/,/g, '').replace(/ /g,'').slice(0,1);
jQ(this).find('.categories').text(trimLast);
jQ(this).attr('data-cat', trimLast);
});
// Remove first cat from duplicated items for sorting later
jQ('.cloned li').each (function (){
var trimFirst = jQ(this).find('.categories').text().replace(/,/g, '').replace(/ /g,'').substring(1);
jQ(this).find('.categories').text(trimFirst);
jQ(this).attr('data-cat', trimFirst);
});
// Alspha Sort List
var list = jQ(".plant-info-list li");
list.detach().sort(function(a,b) {
var at = jQ(a).text();
var bt = jQ(b).text();
return (at > bt)?1:((at < bt)?-1:0);
});
list.appendTo(".sorted");
jQ('.sorted').find("[data-cat='A']").first().addClass('first-cat catA');
jQ('.sorted').find("[data-cat='B']").first().addClass('first-cat catB');
jQ('.sorted').find("[data-cat='C']").first().addClass('first-cat catC');
jQ('.sorted').find("[data-cat='D']").first().addClass('first-cat catD');
jQ('.sorted').find("[data-cat='E']").first().addClass('first-cat catE');
jQ('.sorted').find("[data-cat='F']").first().addClass('first-cat catF');
jQ('.sorted').find("[data-cat='G']").first().addClass('first-cat catG');
jQ('.sorted').find("[data-cat='H']").first().addClass('first-cat catH');
jQ('.sorted').find("[data-cat='I']").first().addClass('first-cat catI');
jQ('.sorted').find("[data-cat='J']").first().addClass('first-cat catJ');
jQ('.sorted').find("[data-cat='K']").first().addClass('first-cat catK');
jQ('.sorted').find("[data-cat='L']").first().addClass('first-cat catL');
jQ('.sorted').find("[data-cat='M']").first().addClass('first-cat catM');
jQ('.sorted').find("[data-cat='N']").first().addClass('first-cat catN');
jQ('.sorted').find("[data-cat='O']").first().addClass('first-cat catO');
jQ('.sorted').find("[data-cat='P']").first().addClass('first-cat catP');
jQ('.sorted').find("[data-cat='Q']").first().addClass('first-cat catQ');
jQ('.sorted').find("[data-cat='R']").first().addClass('first-cat catR');
jQ('.sorted').find("[data-cat='S']").first().addClass('first-cat catS');
jQ('.sorted').find("[data-cat='T']").first().addClass('first-cat catT');
jQ('.sorted').find("[data-cat='U']").first().addClass('first-cat catU');
jQ('.sorted').find("[data-cat='V']").first().addClass('first-cat catV');
jQ('.sorted').find("[data-cat='W']").first().addClass('first-cat catW');
jQ('.sorted').find("[data-cat='X']").first().addClass('first-cat catX');
jQ('.sorted').find("[data-cat='Y']").first().addClass('first-cat catY');
jQ('.sorted').find("[data-cat='Z']").first().addClass('first-cat catZ');
}
// Get Selected Page in Nav if from Join Pages, Store as Session var.
if (jQ('body.join-our-team').length) {
jQ('nav .ul3 a.selected').last().each (function () {
var linkText = jQ(this).text().trim();
sessionStorage.setItem("positionName", linkText);
});
} else {
sessionStorage.removeItem("positionName");
}
}
});