Skip to content

Commit

Permalink
Fixed issues when header is hidden (Shopify#3545)
Browse files Browse the repository at this point in the history
* Fixed issues when header is hidden

* Fixed predictive search on search page

* Made it so that the drawer still shows up
  • Loading branch information
tyleralsbury authored and NikoBerger committed Aug 8, 2024
1 parent 116ea6a commit 3615660
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 59 deletions.
4 changes: 4 additions & 0 deletions assets/cart-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CartDrawer extends HTMLElement {

setHeaderCartIconAccessibility() {
const cartLink = document.querySelector('#cart-icon-bubble');
if (!cartLink) return;

cartLink.setAttribute('role', 'button');
cartLink.setAttribute('aria-haspopup', 'dialog');
cartLink.addEventListener('click', (event) => {
Expand Down Expand Up @@ -76,6 +78,8 @@ class CartDrawer extends HTMLElement {
const sectionElement = section.selector
? document.querySelector(section.selector)
: document.getElementById(section.id);

if (!sectionElement) return;
sectionElement.innerHTML = this.getSectionInnerHTML(parsedState.sections[section.id], section.selector);
});

Expand Down
2 changes: 1 addition & 1 deletion assets/predictive-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class PredictiveSearch extends SearchForm {

getResultsMaxHeight() {
this.resultsMaxHeight =
window.innerHeight - document.querySelector('.section-header').getBoundingClientRect().bottom;
window.innerHeight - document.querySelector('.section-header')?.getBoundingClientRect().bottom;
return this.resultsMaxHeight;
}

Expand Down
107 changes: 64 additions & 43 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!doctype html>
<html class="js" lang="{{ request.locale.iso_code }}">
<head>
<!-- Added by AVADA SEO Suite -->
{% include 'avada-seo' %}
<!-- /Added by AVADA SEO Suite -->
<!-- Added by AVADA SEO Suite -->
{% include 'avada-seo' %}
<!-- /Added by AVADA SEO Suite -->
{% render 'cookiebot' %}
{% render 'google-tag-manager-head' %}
{% render 'cookiebot-google-consent-mode-script' %}
Expand Down Expand Up @@ -38,6 +38,10 @@
<script src="{{ 'constants.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'pubsub.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'global.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-disclosure.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-modal.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'search-form.js' | asset_url }}" defer="defer"></script>

{%- if settings.animations_reveal_on_scroll -%}
<script src="{{ 'animations.js' | asset_url }}" defer="defer"></script>
{%- endif -%}
Expand Down Expand Up @@ -262,6 +266,15 @@

{{ 'custom.css' | asset_url | stylesheet_tag }}
{{ 'base.css' | asset_url | stylesheet_tag }}
<link rel="stylesheet" href="{{ 'component-cart-items.css' | asset_url }}" media="print" onload="this.media='all'">

{%- if settings.cart_type == 'drawer' -%}
{{ 'component-cart-drawer.css' | asset_url | stylesheet_tag }}
{{ 'component-cart.css' | asset_url | stylesheet_tag }}
{{ 'component-totals.css' | asset_url | stylesheet_tag }}
{{ 'component-price.css' | asset_url | stylesheet_tag }}
{{ 'component-discounts.css' | asset_url | stylesheet_tag }}
{%- endif -%}

{%- unless settings.type_body_font.system? -%}
{% comment %}theme-check-disable AssetPreload{% endcomment %}
Expand Down Expand Up @@ -311,7 +324,7 @@
<main id="MainContent" class="content-for-layout focus-none" role="main" tabindex="-1">
{{ content_for_layout }}
</main>

{% sections 'footer-group' %}

<ul hidden>
Expand Down Expand Up @@ -370,50 +383,58 @@

<script>
function accGetCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
let name = cname + '=';
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
function accSetCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
const d = new Date();
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
let expires = 'expires=' + d.toUTCString();
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
}
let accChatOpened = accGetCookie("acc_chat_opened");
if (accChatOpened=="") {
var index=0;
setTimeout(function accCheckForChatNode() {
if (document.body.contains(document.getElementById('shopify-chat'))) {
setTimeout(accAdjustChatNotification, 300);
} else {
index += 1;
if (index < 20){setTimeout(accCheckForChatNode, 50);}
}
}, 50);
function accAdjustChatNotification() {
const accChatDiv = document.getElementById('shopify-chat');
accChatDiv.addEventListener('click', () => {
accSetCookie("acc_chat_opened","true","365");
});
const accNotification = document.getElementById('shopify-chat').childNodes[0].shadowRoot.childNodes[3].childNodes[0].childNodes[2];
if (accNotification.innerHTML=="1") {
accNotification.outerHTML="";
}
}
let accChatOpened = accGetCookie('acc_chat_opened');
if (accChatOpened == '') {
var index = 0;
setTimeout(function accCheckForChatNode() {
if (document.body.contains(document.getElementById('shopify-chat'))) {
setTimeout(accAdjustChatNotification, 300);
} else {
index += 1;
if (index < 20) {
setTimeout(accCheckForChatNode, 50);
}
}
}, 50);
function accAdjustChatNotification() {
const accChatDiv = document.getElementById('shopify-chat');
accChatDiv.addEventListener('click', () => {
accSetCookie('acc_chat_opened', 'true', '365');
});
const accNotification =
document.getElementById('shopify-chat').childNodes[0].shadowRoot.childNodes[3].childNodes[0].childNodes[2];
if (accNotification.innerHTML == '1') {
accNotification.outerHTML = '';
}
}
}
</script>
<script type="text/plain" src="https://partnertrackshopify.dk/js/register.js" async data-cookieconsent="marketing"></script>
<script
type="text/plain"
src="https://partnertrackshopify.dk/js/register.js"
async
data-cookieconsent="marketing"
></script>
</body>
</html>
16 changes: 2 additions & 14 deletions sections/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
<link rel="stylesheet" href="{{ 'component-search.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-menu-drawer.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-cart-notification.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-cart-items.css' | asset_url }}" media="print" onload="this.media='all'">

{%- if settings.predictive_search_enabled -%}
<link rel="stylesheet" href="{{ 'component-price.css' | asset_url }}" media="print" onload="this.media='all'">
{%- endif -%}

{%- if section.settings.menu_type_desktop == 'mega' -%}
<link rel="stylesheet" href="{{ 'component-mega-menu.css' | asset_url }}" media="print" onload="this.media='all'">
{%- endif -%}

{%- if settings.cart_type == "drawer" -%}
{{ 'component-cart-drawer.css' | asset_url | stylesheet_tag }}
{{ 'component-cart.css' | asset_url | stylesheet_tag }}
{{ 'component-totals.css' | asset_url | stylesheet_tag }}
{{ 'component-price.css' | asset_url | stylesheet_tag }}
{{ 'component-discounts.css' | asset_url | stylesheet_tag }}
{%- endif -%}

<style>
header-drawer {
Expand Down Expand Up @@ -102,13 +96,7 @@
}
{%- endstyle -%}

<script src="{{ 'details-disclosure.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-modal.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'cart-notification.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'search-form.js' | asset_url }}" defer="defer"></script>
{%- if settings.cart_type == "drawer" -%}
<script src="{{ 'cart-drawer.js' | asset_url }}" defer="defer"></script>
{%- endif -%}

<svg xmlns="http://www.w3.org/2000/svg" class="hidden">
<symbol id="icon-search" viewbox="0 0 18 19" fill="none">
Expand Down
2 changes: 1 addition & 1 deletion sections/predictive-search.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<img
class="predictive-search__image"
src="{{ product.featured_media | image_url: width: 150 }}"
alt="{{ product.featured_media.alt }}"
alt="{{ product.featured_media.alt | escape }}"
width="50"
height="{{ 50 | divided_by: product.featured_media.preview_image.aspect_ratio }}"
>
Expand Down

0 comments on commit 3615660

Please sign in to comment.