Skip to content

Instantly share code, notes, and snippets.

View estrattonbailey's full-sized avatar

Eric Bailey estrattonbailey

View GitHub Profile
@estrattonbailey
estrattonbailey / list-collections.liquid
Created July 17, 2015 16:51
Shopify Collections Listing Image Fallbacks
{% if collection.image %}
<a href="{{ collection.url }}" class="collection__image" style="background-image: url('{{ collection.image | img_url: 'grande' }}');">
<div class="collection__image__inner"></div>
{% else %}
{% if collection.products_count > 0 %}
{% assign collection_no_images = false %}
{% for product in collection.products %}
{% if product.featured_image %}
{% assign collection_fallback_img = product.featured_image %}
{% break %}
{% unless filter_options %}
{% capture _filter_options %}
{% for tag in collection.all_tags %}{% if tag contains 'filter-' %}{{ tag | remove: 'filter-' | strip }} {%endif%}{%endfor%}
{% endcapture %}
{% assign filter_options = _filter_options | split: ' ' %}
{% endunless %}
{% assign current_option = 'none' %}
{% capture _filters %}
{% for tag in filter_options %}
function delay(callback, ms){
var _timer = null;
return function(){
clearTimeout(_timer);
_timer = setTimeout(callback, ms);
};
};
@estrattonbailey
estrattonbailey / index.js
Last active February 17, 2016 23:26
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var observable = require('lookoutjs');
function on(event, element, observable, property, callback){
element.addEventListener(event, function(e){
observable[property] = e.target.value;
callback(observable[property])
}, false);
}
@estrattonbailey
estrattonbailey / index.js
Created April 29, 2016 21:34
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var observable = require('lookoutjs');
function on(event, element, observable, property, callback){
element.addEventListener(event, function(e){
observable[property] = e.target.value;
callback(observable[property])
}, false);
}
@estrattonbailey
estrattonbailey / counter.js
Last active August 17, 2016 02:11
Reactive Counter
export default function(el){
const input = el.querySelector('.js-counter-input')
const buttons = Array.prototype.slice.call(el.querySelectorAll('button'))
const state = {
min: parseInt(input.getAttribute('min'),10) || 0,
max: parseInt(input.getAttribute('max'),10) || 9999,
store: {
value: parseInt(input.value,10)
},
@estrattonbailey
estrattonbailey / promo-bar.js
Created August 15, 2016 23:17
Rough Draft - Promo Bar Library
import jss from 'jss-browserify'
import stockpile from 'stockpile.js'
const storage = stockpile('GV')
window.STORE = storage
/**
* requestAnimationFrame polyfill
*/
@estrattonbailey
estrattonbailey / dropdown.js
Created August 19, 2016 13:22
Dropdown Snippet
import delegate from 'delegate'
const checkTouch = (root) => {
let select = root.querySelector('.js-select-outer')
let dropdown = root.querySelector('.js-dropdown')
if (!select) return
if (!window.feature.touch){
dropdown.style.display = 'inline-block'
@estrattonbailey
estrattonbailey / address-form.liquid
Created August 29, 2016 18:20
Shopify Address Form
<div id="{{form_outer_id}}" class="address__form relative w1 {{form_classes}}" style="display: none;">
{% form 'customer_address', form_action %}
{% assign form_id = form.id %}
{% capture form_script %}{% if form_id == 'new' %}barrel.toggleNewForm(event){% else %}barrel.toggleForm(event, {{form_id}}){% endif %}{% endcapture %}
{% capture form_suffix %}{% if form_id and form_id != 'new' %}_{{form_id}}{% endif %}{% endcapture %}
{% capture form_city_id %}{% if form_id == 'new' %}AddressCityNew{% else %}AddressCity{% endif %}{% endcapture%}
{% capture form_country_id %}{% if form_id == 'new' %}AddressCountryNew{% else %}AddressCountry{% endif %}{% endcapture%}
@estrattonbailey
estrattonbailey / object-fit-lazyload.js
Last active June 17, 2019 16:29
Object Fit + Layzr Lazy Load
const objectFit = document.documentElement.style.hasOwnProperty('objectFit')
const images = Layzr({ threshold: 90 })
images.on('src:after', img => {
let parent = img.parentNode
// optional, to style loaded state
parent.setAttribute('data-lazy', 'is-loaded')