Skip to content

Instantly share code, notes, and snippets.

@npofopr
Created August 20, 2015 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npofopr/130426cf114d630bf05e to your computer and use it in GitHub Desktop.
Save npofopr/130426cf114d630bf05e to your computer and use it in GitHub Desktop.
$(function() {
// Preloader
$(window).on( 'load', function() {
setTimeout(function() {
$('body').addClass('is-load');
}, 100);
});
// Scroll Header
$(window).on( 'load scroll touchmove', function() {
var sticky = $('body'),
scroll = $(window).scrollTop();
if (scroll >= 1) sticky.addClass('is-fixed');
else sticky.removeClass('is-fixed');
});
// St-nav
$( '.no-touch .st-nav-panel, .no-touch .st-checkout, .no-touch .st-checkout-body, .no-touch .st-wishlist, .no-touch .st-wishlist-body, .no-touch .st-auth, .no-touch .st-auth-body').on( 'mousewheel DOMMouseScroll', function ( e ) {
var e0 = e.originalEvent,
delta = e0.wheelDelta || -e0.detail;
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();
});
// $(window).on( 'reasize', function() {
// $('body').removeClass('is-nav-open is-menu-open');
// });
$('.st-nav-btn').on( 'click touchstart', function(event) {
$('body, .st-auth-btn, .st-checkout-btn, .st-wishlist-btn, .nav-menu-dropdown, [class^=nav-menu-toggle]').removeClass('is-active is-auth-open is-menu-open is-checkout-open is-wishlist-open is-lock is-open');
if( $(this).is('.is-active')) {
$(this).removeClass('is-active').closest('body').removeClass('is-nav-open');
$('body').removeClass('is-lock');
}
else {
$(this).addClass('is-active').closest('body').addClass('is-nav-open');
$('body').addClass('is-lock');
}
event.preventDefault();
});
$('.st-checkout-btn.is-full').on( 'click touchstart', function(event) {
if( $(this).is('.is-active')) {
$(this).removeClass('is-active').closest('body').removeClass('is-checkout-open');
$('body').removeClass('is-lock');
}
else {
$(this).addClass('is-active').closest('body').addClass('is-checkout-open');
$('body').addClass('is-lock');
}
event.preventDefault();
});
$('.st-checkout-close').on( 'click touchstart', function(event) {
$('body, .st-checkout-btn').removeClass('is-active is-checkout-open is-lock');
event.preventDefault();
});
$('.st-wishlist-btn.is-full').on( 'click touchstart', function(event) {
$('body, .st-nav-btn').removeClass('is-nav-open is-active');
if( $(this).is('.is-active')) {
$(this).removeClass('is-active').closest('body').removeClass('is-wishlist-open');
$('body').removeClass('is-lock');
}
else {
$(this).addClass('is-active').closest('body').addClass('is-wishlist-open');
$('body').addClass('is-lock');
}
event.preventDefault();
});
$('.st-wishlist').on( 'click touchstart', '.st-wishlist-close', function(event) {
$('body, .st-wishlist-btn').removeClass('is-active is-wishlist-open is-lock');
event.preventDefault();
});
$('.st-auth-btn').on( 'click touchstart', function(event) {
$('body, .st-nav-btn').removeClass('is-nav-open is-active');
if( $(this).is('.is-active')) {
$(this).removeClass('is-active').closest('body').removeClass('is-auth-open');
$('body').removeClass('is-lock');
}
else {
$(this).addClass('is-active').closest('body').addClass('is-auth-open');
$('body').addClass('is-lock');
}
event.preventDefault();
});
$('.st-auth').on( 'click touchstart', '.st-auth-close', function(event) {
$('body, .st-auth-btn').removeClass('is-active is-auth-open is-lock');
event.preventDefault();
});
// Nav
$('.nav').on( 'click', '[class^=nav-menu-toggle]', function(event) {
if( $(this).is('.is-active')) {
$(this).removeClass('is-active').next('.nav-menu-dropdown').removeClass('is-open');
$('body').removeClass('is-menu-open');
}
else {
$('[class^=nav-menu-toggle]').removeClass('is-active').next('.nav-menu-dropdown').removeClass('is-open');
$(this).addClass('is-active').next('.nav-menu-dropdown').addClass('is-open');
$('body').addClass('is-menu-open');
}
event.preventDefault();
});
// Search
$('.search').on( 'click', '.search-open', function(event) {
$('body, .nav-menu-dropdown, [class^=nav-menu-toggle]').removeClass('is-menu-open is-open is-active');
$('body').addClass('is-search-open');
event.preventDefault();
});
$('.search').on( 'click', '.search-close', function(event) {
$('body').removeClass('is-search-open is-search-results');
event.preventDefault();
});
$('.search-text').focus(function(){
$('body').addClass('is-search-results');
}).blur(function(){
$('body').removeClass('is-search-results');
});
// Cover
$('.backgroundsize .slides-item-image, .backgroundsize .banner-image, .backgroundsize .blog-item-image').each(function() {
var el = $(this),
el_img = el.find('img'),
el_src = el_img.attr('src');
el.css({backgroundImage:'url('+el_src+')'}).find('img').css({
'opacity': 0,
'visibility': 'hidden'
})
});
// Equalheight
$(window).on('load resize', function(){
$.fn.matchHeight._maintainScroll = true;
$('.is-equalheight').matchHeight({
property: 'min-height'
});
$('.catalog-grid > li:not(:hidden)').matchHeight({
property: 'height'
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment