Skip to content

Instantly share code, notes, and snippets.

@nilocortex
Last active Apr 2, 2020
Embed
What would you like to do?
Announcement Bar Fix 1.4.9 - 1.4.10.1
function docSpacing() {
// Init header height script
var hHeight = $("#header").height(),
hPosition = $("#header").data('position'),
mobileSticky = $(".mobile-cart-buttons").data('sticky'),
mobileLocation = $(".sticky-footer").data("mobile"),
mobileNavDiv = $('.sticky-footer'),
mobilehHeight = $(".sticky-footer").height(),
mobileProdBtns = $('.product-top-buttons'),
mobilePromoDiv = $('.promo-bar'),
mobilePromo = $('.promo-bar').outerHeight(),
deskPromo = $('.promo-bar').height(),
mobileCartBtns = $(".cart-top-buttons");
// Set main menu dropdown to always append below header
$('.main-menu-dropdown, .js-search-dropdown').css("top", hHeight);
if (window.innerWidth > 768) {
// If desktop
if (hPosition) {
// If sticky header
$('#header').css('top', $('.promo-bar').outerHeight())
if($('.promo-bar').length > -1){
hHeight = $("#header").outerHeight() + $('.promo-bar').outerHeight();
}
$('main.main-content').css('margin-top', $("#header").outerHeight() + $('.promo-bar').outerHeight());
} else {
$('main.main-content').css('margin-top', 'initial');
}
$('body').css('margin-bottom', 0);
} else if ($('body').hasClass('template-product') || $('body').hasClass('template-cart')) {
// If product or cart page
if ($('body').hasClass('template-product') && !(mobileSticky) && window.innerWidth < 769) {
// If product page without sticky add to cart buttons (mobile)
if (mobileLocation == 'top') {
// If mobile nav is on top
$('main.main-content').css('margin-top', mobilehHeight + mobilePromo);
$('main.main-content').css('margin-bottom', 0);
$('main.main-content').css('padding-top', 0);
$('body').css('margin-bottom', 0);
mobileNavDiv.css('bottom', 'initial');
if($('.promo-bar').length > -1){
mobileNavDiv.css('top', $('.promo-bar').outerHeight())
}
} else {
if (mobilePromo) {
// if product promo bar is turned on
$('main.main-content').css('margin-top', mobilePromo);
$('main.main-content').css('padding-top', '4%');
} else {
$('main.main-content').css('margin-top', '4%');
$('main.main-content').css('padding-top', 0);
}
$('body').css('margin-bottom', mobilehHeight);
mobileNavDiv.css('top', 'initial');
}
} else if ($('body').hasClass('template-product') && mobileSticky && window.innerWidth < 769) {
// If product page with sticky add to cart buttons (mobile)
if (mobileLocation == 'top') {
var newHeight = mobilehHeight + mobileProdBtns.outerHeight() + mobilePromo;
$('main.main-content').css('margin-top', newHeight);
$('main.main-content').css('margin-bottom', 0);
$('main.main-content').css('padding-top', 0);
mobileProdBtns.css("top", mobilehHeight + mobilePromo);
$('body').css('margin-bottom', 0);
mobileNavDiv.css('bottom', 'initial');
if(mobilePromo){
mobileNavDiv.css('top', $('.promo-bar').outerHeight())
}
} else {
if (mobileProdBtns.outerHeight() != 0) {
mobileProdBtns.css("padding-top", '15px');
}
}
mobileProdBtns.css("top", 0 + mobilePromo);
$('body').css('margin-bottom', mobilehHeight);
mobileNavDiv.css('top', 'initial');
}
}
if ($('body').hasClass('template-cart') && window.innerWidth < 769) {
// If cart page
if (mobileLocation == 'top') {
$('main.main-content').css('margin-bottom', 0);
$('body').css('margin-bottom', 0);
mobileCartBtns.css("top", mobilehHeight + $('.promo-bar.slick-slider').outerHeight());
setTimeout(function(){
if(mobilePromo){
var newCartHeight = mobilehHeight + mobileCartBtns.outerHeight() + $('.promo-bar.slick-slider').outerHeight();
mobileNavDiv.css('top', $('.promo-bar.slick-slider').outerHeight());
mobileCartBtns.css("top", mobilehHeight + $('.promo-bar.slick-slider').outerHeight());
$('main.main-content').css('margin-top', newCartHeight);
}
}, 600)
mobileNavDiv.css('bottom', 'initial');
} else {
var newTopHeight = mobileCartBtns.outerHeight() + $('.promo-bar.slick-slider').outerHeight();
$('main.main-content').css('margin-top', newTopHeight);
mobileCartBtns.css("top", $('.promo-bar.slick-slider').outerHeight());
setTimeout(function(){
newTopHeight = mobileCartBtns.outerHeight() + $('.promo-bar.slick-slider').outerHeight();
$('body').css('margin-bottom', mobilehHeight);
if (mobilePromo) {
$('main.main-content').css('margin-top', newTopHeight);
mobileCartBtns.css("top", $('.promo-bar.slick-slider').outerHeight());
}else{
$('main.main-content').css('margin-top', mobileCartBtns.outerHeight());
}
}, 600)
}
if (mobilePromo) {
mobilePromoDiv.css('top', 0);
} else {
$('main.main-content').css('margin-top', '4%');
$('#PageContainer').css({
'margin-top': 0,
'padding-top': 0
});
}
} else {
// If any other page
if (window.innerWidth < 769) {
if (mobileLocation == 'top') {
var newHeight = $('.promo-bar.slick-slider').outerHeight() + mobilehHeight;
$('main.main-content').css('margin-top', newHeight);
$('main.main-content').css('margin-bottom', '4%');
$('body').css('margin-bottom', 0);
mobileNavDiv.css({
'bottom':'initial'
});
if (mobilePromo) {
mobileNavDiv.css('top', mobilePromo);
$('.sticky-header').css('margin-top', mobileNavDiv.outerHeight() + mobilePromo)
$('main.main-content').css('padding-top', '0');
}
} else {
if (mobilePromo) {
// if product promo bar is turned on
$('main.main-content').css('margin-top', mobilePromo);
$('main.main-content').css('padding-top', '4%');
$('.sticky-header').css('margin-top', $('.promo-bar').outerHeight())
} else {
$('main.main-content').css('margin-top', '4%');
$('main.main-content').css('padding-top', 0);
}
$('body').css('margin-bottom', mobilehHeight);
mobileNavDiv.css('top', 'initial');
}
}else{
if (mobilePromo) {
$('main.main-content').css('padding-top', '0');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment