Skip to content

Instantly share code, notes, and snippets.

View ihorduchenko's full-sized avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / vanilla-js-tabs.liquid
Last active September 12, 2021 14:21
Vanilla JS tabs
<nav class="drawer-tabs--nav tabsNav" data-control=".mobileMenu">
{%- assign indexNav = 0 -%}
{%- for block in section.blocks -%}
{%- if block.type == 'menu-tab' -%}
{%- assign name = block.settings.name -%}
{%- assign name_handle = name | handleize -%}
<a href="#{{ name_handle }}" class="navv-tab tabsNavLink{% if indexNav == 0 %} is-active{% endif %}">
{{ name }}
</a>
{%- assign indexNav = indexNav | plus: 1 -%}
@ihorduchenko
ihorduchenko / custom-checkbox.liquid
Created September 18, 2021 20:53
Create custom checkbox
<label for="custom-checkbox" class="custom-checkbox">
<input id="custom-checkbox" type="checkbox" name="custom_checkbox">
<span>Custom checkbox</span>
</label>
<style>
.custom-checkbox > input[type=checkbox] {
opacity: 0;
cursor: pointer;
position: absolute;
@ihorduchenko
ihorduchenko / defer-css.html
Created November 26, 2021 13:56
Defer loading CSS file using media attribute trick
<link rel="stylesheet" href="theme.css" media="print" onload="this.media='all'">
@ihorduchenko
ihorduchenko / strict-content-using-license-key.liquid
Created December 1, 2021 16:48
Strict page content based on license key, stored in Google Sheets
<script defer="defer">
// Format of table is here: http://prntscr.com/219q3nl
const myDomain = window.location.hostname;
const myLicenseKey = '{{ settings.license_key | strip }}';
fetch('https://sheets.googleapis.com/v4/spreadsheets/1JO15y71ImOijJ4rcdMV7avZT5Y5lILkZin6emwg35D0/values/Keys!A2:B10000?key=AIzaSyBxbARr6-hAqdtZXXqSqDPmzap7EULYaFg')
.then(response => response.text())
.then(data => {
let resp = JSON.parse(data);
let respKeys = resp.values;
let allKeys = [];
@ihorduchenko
ihorduchenko / firstVisitCookies.js
Created December 13, 2021 22:16
Get and set cookies on first user visit
function setCookie(name, value, days) {
var expires = '';
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + (value || '') + expires + '; path=/';
}
@ihorduchenko
ihorduchenko / woocommerce>checkout>review-order.php
Created December 23, 2021 20:15
Woocommerce estimated shipping date, based on stock and shipping method
<table class="shop_table mb-4">
<tfoot>
<!-- Skipped top part -->
<!-- Stock part -->
<?php $stock_values = array(); ?>
<?php $max_stock_period = 0; ?>
<?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { ?>
<?php $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); ?>
<?php $stock_status = $_product->get_stock_status(); ?>
@ihorduchenko
ihorduchenko / custom-liquid.liquid
Created December 29, 2021 18:42
Shopify sections - "liquid" section type
{%- if section.settings.boxed -%}
<div class="grid-container contained">
{%- endif -%}
{{ section.settings.liquid }}
{%- if section.settings.boxed -%}
</div>
{%- endif -%}
@ihorduchenko
ihorduchenko / free-geolocation-detection-endpoint.js
Last active March 22, 2022 21:02
Geolocation detection endpoint
// https://get.geojs.io/v1/ip/geo.json
// https://ipapi.co/country
// http://ip-api.com/json
// https://ipinfo.io/json
// https://extreme-ip-lookup.com/json/?key=E4sAnOeXGIkbh5BLZOCg
// https://geolocation-db.com/json/0f761a30-fe14-11e9-b59f-e53803842572
// ABOVE LOOKS LIKE WASTED
// BELOW ARE FINE
// + https://ipgeolocation.abstractapi.com/v1/?api_key=b3d18485c87a42d1a7a82c0568732f19
@ihorduchenko
ihorduchenko / dynamic-customizer-image-metafield.liquid
Last active January 29, 2022 23:44
Get dynamic image metafield from customizer (OS2)
{{ img_url | file_url }}
@ihorduchenko
ihorduchenko / lazyload-youtube.liquid
Created January 24, 2022 09:52
Lazy-load YouTube videos on click
<div class="lazyVideoLoader">
<a href="javascript:;" data-video-id="VIDEO_ID" class="feature-row__video-trigger lazyVideoTrigger">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80">
<path d="M40 0a40 40 0 1040 40A40 40 0 0040 0zM26 61.56V18.44L64 40z"></path>
</svg>
</a>
</div>
<script>
var lazyVideoLoader = document.querySelectorAll('.lazyVideoLoader');