$(function(){ /* ============================================================================= general ========================================================================== */ /* js enabled user -------------------------------------------------------------------------- */ $('html').removeclass('no-js').addclass('has-js'); /* touch or mouse ? -------------------------------------------------------------------------- */ var ua = navigator.useragent; function is_touch_device() { try { document.createevent("touchevent"); return true; } catch (e) { return false; } } if ((is_touch_device()) || ua.match(/(iphone|ipod|ipad)/) || ua.match(/blackberry/) || ua.match(/android/)) { $('body').addclass('touch'); } else { $('body').addclass('mouse'); } /* resize dispatcher -------------------------------------------------------------------------- */ $(window).on('resize', function() { checkdevicetype(); containerresize(); navresize(false); footresize(); }); /* check device type -------------------------------------------------------------------------- */ var ishandheld = null; var issmartphone = null; var istablet = null; var isdesktop = null; function checkdevicetype () { var body = $('body'); body.css({overflow:'hidden'}); if ($(window).width() > 1000) { ishandheld = issmartphone = istablet = false; isdesktop = true; } else if ($(window).width() > 760) { ishandheld = istablet = true; isdesktop = issmartphone = false; } else { ishandheld = issmartphone = true; isdesktop = istablet = false; } body.css({overflow:''}); } checkdevicetype(); /* image replacement on hover -------------------------------------------------------------------------- */ $('body').on('mouseenter mouseleave', '.hover-img', function(e) { if ( !$(this).hasclass('current') ) { var img = $(this).find('img'); if (img.length == 0) img = $(this); var src = img.attr('src'); if (src) { var newsrc = src.replace('_hover',''); if ( e.type == 'mouseenter' ) { newsrc = src.replace(new regexp("(\.png|\.jpg)", "i"), "_hover$1"); } img.attr('src',newsrc); } } }); /* prevent image dragging -------------------------------------------------------------------------- */ $('body').on('mousedown', 'img', function() { return false; }); /* placeholder -------------------------------------------------------------------------- */ $('input, textarea').placeholder(); /* ============================================================================= global ========================================================================== */ function containerresize() { var container = $('.global-container'); // reset size container.css({height:''}); if (container.outerheight() < $(window).height()) { container.css({height:$(window).height()}); } } /* ============================================================================= nav ========================================================================== */ /* sub menu -------------------------------------------------------------------------- */ $('.nav-main .menu > .menu-item').on('mouseenter mouseleave', function(e) { var item = $(this); var otheritems = item.siblings('.menu-item'); if (e.type == 'mouseenter') { otheritems.stop(true).fadeto(300, 0.2); item.addclass('is-open'); } else { otheritems.stop(true).fadeto(300, 1); item.removeclass('is-open'); } }); $('.nav-main .sub-menu > .menu-item').on('mouseenter mouseleave', function(e) { var item = $(this); var otheritems = item.siblings('.menu-item'); if (e.type == 'mouseenter') { otheritems.stop(true).fadeto(300, 0.2); } else { otheritems.stop(true).fadeto(300, 1); } }); $('.nav-main .menu > .menu-item a').on('click', function(e) { var item = $(this).closest('.menu-item'); var otheritems = item.siblings('.menu-item'); var submenu = item.find('.sub-menu-container'); if (submenu.length == 1 && $('body').hasclass('touch')) { if (item.hasclass('is-open')) { otheritems.stop(true).fadeto(300, 1); item.removeclass('is-open'); } else { otheritems.removeclass('is-open').stop(true).fadeto(300, 0.2); item.stop(true).fadeto(300, 1); item.addclass('is-open'); } e.preventdefault(); } }); /* mask toggle -------------------------------------------------------------------------- */ $('.nav-main').on('mouseenter mouseleave', function(e) { if (!isdesktop) return; var mask = $('.nav-mask'); if (e.type == 'mouseenter') { mask.stop(true).fadeto(300, 1, function() { mask.css({display:'', opacity:''}).addclass('is-visible'); }); } else { mask.stop(true).fadeto(300, 0, function() { mask.css({display:'', opacity:''}).removeclass('is-visible'); }) } }); /* nav toggle -------------------------------------------------------------------------- */ $('.nav-toggle, .nav-handheld .mask').on('click', function() { if (!ishandheld) return; var nav = $('.nav-handheld'); var button = nav.find('.nav-toggle'); var menu = nav.find('.menu-container'); var mask = nav.find('.mask'); if (nav.hasclass('is-open')) { tweenmax.to( button, 0.5, { left:0, ease:power3.easeinout } ); tweenmax.to( nav, 0.5, { width:0, ease:power3.easeinout, oncomplete: function() { nav.attr('style', '').removeclass('is-open'); menu.attr('style', ''); button.attr('style', ''); mask.css({display:'', opacity:''}); } } ); mask.stop(true).fadeto(500, 0); } else { tweenmax.to( window, 0.5, { scrollto: {y:0}, ease: power3.easeinout } ); navresize(true); nav.css({zindex:21}); tweenmax.to( button, 0.5, { left:menu.outerwidth(), ease:power3.easeinout } ); tweenmax.to( nav, 0.5, { width:menu.outerwidth(), ease:power3.easeinout, oncomplete: function() { nav.attr('style', '').addclass('is-open') button.attr('style', ''); mask.css({display:'', opacity:''}); navresize(true); } } ); mask.stop(true).fadeto(500, 1); } }) /* resize -------------------------------------------------------------------------- */ function navresize(forced) { var nav = $('.nav-handheld'); var menu = nav.find('.menu-container'); var mask = $('.nav-mask, .nav-handheld .mask'); // reset size menu.attr('style', ''); if (ishandheld && (forced || nav.hasclass('is-open'))) { if (menu.outerheight() < $(document).height()) { menu.css({overflow: 'visible'}); menu.height($(document).height()); } } // resize mask mask.css({width:$(window).width(), height:$(document).height()}); } /* top bar -------------------------------------------------------------------------- */ function stickynav() { var head = $('.site-head'); var bar = $('.top-bar'); var navtoggle = $('.nav-handheld .nav-toggle'); var scrolltop = $(window).scrolltop(); var breakpoint = head.height()-bar.height()-8; if (scrolltop > breakpoint && !bar.hasclass('is-fixed')) { bar.addclass('is-fixed'); navtoggle.addclass('is-fixed'); } else if (scrolltop <= breakpoint && bar.hasclass('is-fixed')) { bar.removeclass('is-fixed'); navtoggle.removeclass('is-fixed'); } } $(window).on('scroll', stickynav); /* top bar sub menu -------------------------------------------------------------------------- */ $('.nav-secondary .has-submenu').on('mouseenter mouseleave', function(e) { var container = $(this); var submenu = container.find('.submenu'); if (container.hasclass('is-open')) { container.removeclass('is-open'); tweenmax.to( container, 0.3, { paddingtop: 0, ease: power3.easeinout } ) } else { container.addclass('is-open'); tweenmax.to( container, 0.3, { paddingtop: submenu.height(), ease: power3.easeinout } ) } }); $('.nav-secondary .has-submenu .link').on('click', function(e) { if (!$('body').hasclass('touch')) return; var container = $(this).closest('.menu-item'); var submenu = container.find('.submenu'); if (container.hasclass('is-open')) { container.removeclass('is-open'); tweenmax.to( container, 0.3, { paddingtop: 0, ease: power3.easeinout } ) } else { container.addclass('is-open'); tweenmax.to( container, 0.3, { paddingtop: submenu.height(), ease: power3.easeinout } ) } }); /* ============================================================================= head slideshow ========================================================================== */ var headslideshowwait = false; var headslideshowduration = 4000; var headslideshowtimeout = null; /* switch -------------------------------------------------------------------------- */ function headslideshowswitch(index, auto) { if (headslideshowwait) return; var slideshow = $('.head-slideshow'); var slides = slideshow.find('.slide'); var activeslide = slides.filter('.is-active'); var activeindex = activeslide.index(); var newslide = slides.eq(index); if (newslide.is(activeslide)) return; cleartimeout(headslideshowtimeout); headslideshowwait = true; if (index > activeindex) { var from = activeslide.width(); var to = -activeslide.width()/2; } else { var from = 0; var to = activeslide.width()/2; } // transition newslide.css({left:from, width:0, zindex:2}); tweenmax.to( activeslide, 1.5, { left: to, ease:power3.easeinout } ); tweenmax.to( newslide, 1.5, { left: 0, width: activeslide.width(), ease:power3.easeinout, oncomplete:function() { newslide.attr('style', '').addclass('is-active'); activeslide.attr('style', '').removeclass('is-active'); // check page $('.head-slideshow .page').trigger('check'); headslideshowwait = false; if (auto) { headslideshowtimeout = settimeout(function () { headslideshownext(false, true); }, headslideshowduration); } } } ) } /* next slide -------------------------------------------------------------------------- */ function headslideshownext(previous, auto) { var slideshow = $('.head-slideshow'); if (slideshow.length == 0) return; var slides = slideshow.find('.slide'); var activeslide = slides.filter('.is-active'); var newslide = null; if (previous) { newslide = activeslide.prev('.slide'); if (newslide.length == 0) newslide = slides.last(); } else { newslide = activeslide.next('.slide'); if (newslide.length == 0) newslide = slides.first(); } headslideshowswitch(newslide.index(), auto); } /* pages -------------------------------------------------------------------------- */ $('body').on('click', '.head-slideshow .page', function() { var index = $(this).index(); headslideshowswitch(index, false); }); $('body').on('check', '.head-slideshow .page', function() { var index = $('.head-slideshow .slide.is-active').index(); if (index != $(this).index()) $(this).removeclass('is-active'); else $(this).addclass('is-active') }) /* init -------------------------------------------------------------------------- */ function headslideshowinit() { var slideshow = $('.head-slideshow'); // cycle headslideshowtimeout = settimeout(function () { headslideshownext(false, true); }, headslideshowduration); // swipe slideshow.hammer().on('dragleft swipeleft', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragleft') { return; } headslideshownext(false, false); }); slideshow.hammer().on('dragright swiperight', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragright') { return; } headslideshownext(true, false); }); } headslideshowinit(); /* ============================================================================= horizontal slideshow ========================================================================== */ var horizontalslideshowwait = false; /* switch -------------------------------------------------------------------------- */ function horizontalslideshowswitch(next) { if (horizontalslideshowwait) return; var slideshow = $('.horizontal-slideshow'); var container = slideshow.find('.slides'); var slides = slideshow.find('.slide'); var activeslide = slides.filter('.is-active'); var nextslide = slides.filter('.is-next'); var prevslide = slides.filter('.is-prev'); if (next) var newactiveslide = slides.filter('.is-next'); else var newactiveslide = slides.filter('.is-prev'); if (newactiveslide.is(activeslide)) return; horizontalslideshowwait = true; var newnextslide = newactiveslide.next('.slide'); if (newnextslide.length == 0) newnextslide = slides.first(); var newprevslide = newactiveslide.prev('.slide'); if (newprevslide.length == 0) newprevslide = slides.last(); // create temp slides var tempactiveslide = newactiveslide.clone(); tempactiveslide.attr('class', 'slide').css({display:'block', zindex:3}).appendto(container); tempactiveslide.find('.image').css({opacity:0.2}); if (next) tempactiveslide.css({left: nextslide.outerwidth(true)}); else tempactiveslide.css({left: -prevslide.outerwidth(true)}); var tempnextslide = newnextslide.clone(); tempnextslide.attr('class', 'slide').css({display:'block', zindex:3}).appendto(container); if (next) { tempnextslide.css({left: nextslide.outerwidth(true)*2}); tempnextslide.find('.image').css({opacity:0.2}); } else { tempnextslide.css({left: 0}); tempnextslide.find('.image').css({opacity:1}); } var tempprevslide = newprevslide.clone(); tempprevslide.attr('class', 'slide').css({display:'block', zindex:3}).appendto(container); if (next) { tempprevslide.css({left: 0}); tempprevslide.find('.image').css({opacity:1}); } else { tempprevslide.css({left: -prevslide.outerwidth(true)*2}); tempprevslide.find('.image').css({opacity:0.2}); } var tempslides = tempactiveslide.add(tempnextslide).add(tempprevslide); // transition var timeline = new timelinelite(); timeline.to( tempactiveslide, 1, { left:0, ease:power3.easeinout }, 0 ); timeline.to( tempactiveslide.find('.image'), 1, { alpha:1, ease:power3.easeinout }, 0 ); timeline.to( tempnextslide, 1, { left:nextslide.outerwidth(true), ease:power3.easeinout }, 0 ); timeline.to( tempnextslide.find('.image'), 1, { alpha:0.2, ease:power3.easeinout }, 0 ); timeline.to( tempprevslide, 1, { left:-prevslide.outerwidth(true), ease:power3.easeinout }, 0 ); timeline.to( tempprevslide.find('.image'), 1, { alpha:0.2, ease:power3.easeinout }, 0 ); if (next) { timeline.to( prevslide, 1, { left:-prevslide.outerwidth(true)*2, ease:power3.easeinout }, 0 ); } else { timeline.to( nextslide, 1, { left:nextslide.outerwidth(true)*2, ease:power3.easeinout }, 0 ); } timeline.add(function() { tempslides.remove(); prevslide.attr('style', '').removeclass('is-prev'); nextslide.attr('style', '').removeclass('is-next'); newactiveslide.attr('style', '').attr('class', 'slide is-active'); newnextslide.attr('style', '').attr('class', 'slide is-next'); newprevslide.attr('style', '').attr('class', 'slide is-prev'); horizontalslideshowwait = false }); slides.removeclass('is-active'); if (next) nextslide.removeclass('is-next'); else prevslide.removeclass('is-prev'); timeline.play(); } /* navigation -------------------------------------------------------------------------- */ $('body').on('click', '.horizontal-slideshow .arrow', function() { if ($(this).hasclass('next')) horizontalslideshowswitch(true); else horizontalslideshowswitch(false); }); /* init -------------------------------------------------------------------------- */ function horizontalslideshowinit() { var slideshow = $('.horizontal-slideshow'); // swipe slideshow.hammer().on('dragleft swipeleft', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragleft') { return; } horizontalslideshowswitch(true); }); slideshow.hammer().on('dragright swiperight', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragright') { return; } horizontalslideshowswitch(false); }); } horizontalslideshowinit(); /* ============================================================================= product ========================================================================== */ var productthumbswait = false; /* thumbs slide -------------------------------------------------------------------------- */ function productthumbsslide(down) { if (productthumbswait) return; productthumbswait = true; var container = $('.thumbs-container'); var block = container.find('.thumbs'); var thumbs = container.find('.thumb'); var position = block.position(); var mintop = -((thumbs.length*90)+((thumbs.length-1)*10)-container.height()); if (down) var newtop = position.top-400; else var newtop = position.top+400; if (newtop > 0) newtop = 0 if (newtop < mintop) newtop = mintop tweenmax.to( block, 0.8, { top: newtop, ease:power3.easeinout, oncomplete: function() { productthumbswait = false; } } ) } /* thumbs nav -------------------------------------------------------------------------- */ $('.thumbs-navigation .arrow').on('click', function() { if ($(this).hasclass('bottom')) productthumbsslide(true); else productthumbsslide(false); }); /* next image -------------------------------------------------------------------------- */ function productnextimage(previous) { var pages = $('.gallery-pagination .page'); var activeimage = pages.filter('.is-active'); if (previous) var nextimage = activeimage.prev('.page'); else var nextimage = activeimage.next('.page'); nextimage.click(); } /* gallery init -------------------------------------------------------------------------- */ function productgalleryinit() { var gallery = $('.product-gallery'); var thumbs = gallery.find('.other-images'); // swipe horizontal gallery.hammer().on('dragleft swipeleft', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragleft') { return; } productnextimage(false); }); gallery.hammer().on('dragright swiperight', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragright') { return; } productnextimage(true); }); // swipe vertical thumbs.hammer().on('dragup swipeup', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragup') { return; } productthumbsslide(true); }); thumbs.hammer().on('dragdown swipedown', function(ev) { ev.gesture.preventdefault(); if(ev.type == 'dragdown') { return; } productthumbsslide(false); }); } productgalleryinit(); /* ============================================================================= category ========================================================================== */ /* block toggle -------------------------------------------------------------------------- */ $('.page-toolbar .button-toggle, .page-column .button-toggle, #product_list').on('click', function() { if (!issmartphone) return; var container = $(this).parent(); var product = $('#product_list'); $('.page-toolbar, .page-column').not(container).removeclass('is-opened'); if (container.hasclass('is-opened') || $(this).is('#product_list')) { container.removeclass('is-opened'); product.removeclass('is-masked'); } else { container.addclass('is-opened'); product.addclass('is-masked'); } }); /* select category -------------------------------------------------------------------------- */ $('body').on('change', '.layered_select.category', function(e) { if (!issmartphone) return; var selected = $(this).find(':selected'); var href = selected.attr('data-href'); window.location = href; }) /* ============================================================================= products ========================================================================== */ /* lazy load -------------------------------------------------------------------------- */ $('.lazy-button').on('click', function(e) { var list = $(this).prev('.product-list'); var products = list.find('.product'); var toload = products.not('.is-loaded').slice(0, 24); toload.each(function(index) { var product = $(this); var container = product.find('.image-container'); var img = $(''+container.attr('data-legend')+''); container.prepend(img); product.addclass('is-loaded').hide().delay(50*index).fadein(300); }); if (products.not('.is-loaded').length <= 24) $(this).fadeout(); e.preventdefault(); }); /* ============================================================================= newsletter popin ========================================================================== */ /* close -------------------------------------------------------------------------- */ $('.newsletter-popin').on('click', '.close, .hit', function(e) { var container = $('.newsletter-popin'); var popin = container.find('.popin'); tweenmax.to( container, 0.75, { alpha:0, ease:power2.easeinout } ) tweenmax.to( popin, 0.75, { top:-200, ease:power1.easeinout, oncomplete:function() { container.remove(); } } ) }); /* ============================================================================= foot ========================================================================== */ /* foot resize -------------------------------------------------------------------------- */ function footresize() { var foot = $('.site-foot'); // reset position foot.attr('style', ''); var offset = foot.offset(); // foot min position var mintop = $(window).height()-foot.height(); if (offset.top < mintop && !ishandheld) { foot.css({position:'fixed'}); } } /* newsletter scroll -------------------------------------------------------------------------- */ if ($('.site-foot .form-newsletter .message').length == 1) { var scrollmax = $(document).height()-$(window).height(); $(window).scrolltop(scrollmax); } /* ============================================================================= custom form ========================================================================== */ /* selects -------------------------------------------------------------------------- */ function initcustomselect() { $('select.custom').each(function() { // hide original select var replacedselect = $(this); replacedselect.hide(); // remove existing customized select replacedselect.next('.replaced-select').remove(); // selectors var label = $('label[for="'+$(this).attr('id')+'"]'); var options = $(this).find('option'); // create new elements var newscroller = $('
'); var newoptions = $(''); var newselect = $('
') var newselectinner = $('
') var newlabel = $('
'+options.filter(':selected').html()+'
'); // add label newselectinner.prepend(newlabel); // open handler newlabel.on('click', function(e) { if (!$(this).closest('.replaced-select').hasclass('is-single')) { $(this).closest('.replaced-select').toggleclass('is-opened'); } }); // add options options.each(function() { newoptions.append($('
  • '+$(this).html()+'
  • ')); }); newscroller.find('.scroller').append(newoptions); newselectinner.append(newscroller); if (options.length == 1) newselect.addclass('is-single'); // selection handler newoptions.on('click', '.option', function(e) { if (!$(this).hasclass('is-disabled')) { replacedselect.val($(this).attr('data-value')).change(); newlabel.find('.inner').html($(this).html()); newselect.removeclass('is-opened'); } }); replacedselect.on('change', function(e) { var selected = $(this).find(':selected'); newlabel.find('.inner').html(selected.html()); newoptions.find('.is-selected').removeclass('is-selected'); newoptions.find('[data-value="'+selected.val()+'"]').addclass('is-selected'); }); replacedselect.on('update', function() { $(this).find('option').each(function() { var option = newoptions.find('[data-value="'+$(this).val()+'"]'); if ($(this).is('.is-disabled')) option.addclass('is-disabled'); else option.removeclass('is-disabled'); }); var selected = $(this).find(':selected'); newlabel.find('.inner').html(selected.html()); newoptions.find('.is-selected').removeclass('is-selected'); newoptions.find('[data-value="'+selected.val()+'"]').addclass('is-selected'); }); // add customized select newselect.append(newselectinner); newselect.insertafter($(this)); // iscroll if (!$('html').hasclass('lt-ie9')) { newscroller.css({position:'relative', left:0}); new iscroll( newscroller.get(0), { scrollbars: true, scrollx: false, mousewheel: true, click: true, interactivescrollbars: true } ); newscroller.css({position:'', left:''}); } }); $('body').on('click', '.replaced-select', function(e) { $('.replaced-select').not($(this)).removeclass('is-opened'); }); $('body').on('click', function(e) { if ($('.replaced-select').length == 0) return; if ($(e.target).closest('.replaced-select').length == 1) { } else { $('.replaced-select').removeclass('is-opened'); } }); } /* checkbox -------------------------------------------------------------------------- */ function initcustomcheckbox() { $('input[type="checkbox"].custom').each(function() { var replacedcheckbox = $(this); replacedcheckbox.hide(); var newcheckbox = $('
    '); if (replacedcheckbox.is(':checked')) newcheckbox.addclass('is-checked'); else newcheckbox.removeclass('is-checked'); newcheckbox.on('click', function(e) { if (replacedcheckbox.is(':checked')) { $(this).removeclass('is-checked'); replacedcheckbox.attr('checked',false).change(); } else { $(this).addclass('is-checked'); replacedcheckbox.attr('checked',true).change(); } e.preventdefault(); }); replacedcheckbox.on('change', function() { if (replacedcheckbox.is(':checked')) newcheckbox.addclass('is-checked'); else newcheckbox.removeclass('is-checked'); }); newcheckbox.insertafter($(this)); }); } /* radio -------------------------------------------------------------------------- */ function initcustomradio() { $('input[type="radio"].custom').each(function() { var replacedradio = $(this); replacedradio.hide(); var label = $('label[for="'+$(this).attr('id')+'"]'); var linkedradios = $('input[type="radio"][name="'+replacedradio.attr('name')+'"]'); var newradio = $('
    '); if (replacedradio.is(':checked')) newradio.addclass('is-checked'); else newradio.removeclass('is-checked'); newradio.on('click', function(e) { $(this).addclass('is-checked'); $(this).prev('.custom').attr('checked',true).trigger('change'); e.preventdefault(); }); replacedradio.on('change', function() { $('.replaced-radio[data-name="'+$(this).attr('name')+'"]').removeclass('is-checked'); if ($(this).is(':checked')) $(this).next('.replaced-radio').addclass('is-checked'); else $(this).next('.replaced-radio').removeclass('is-checked'); }); newradio.insertafter($(this)); }); } /* init -------------------------------------------------------------------------- */ $('body').on('customform', function() { initcustomselect(); initcustomcheckbox(); initcustomradio(); }).trigger('customform'); /* ============================================================================= ending stuff ========================================================================== */ /* remove hover events if user is on touch screen -------------------------------------------------------------------------- */ if ($('body').hasclass('touch')) { $('*').off('mouseenter mouseleave'); } /* trigger resize event to position everything after window load -------------------------------------------------------------------------- */ $(window).on('load', function() { $(window).trigger('resize'); }); });