Skip to content

Instantly share code, notes, and snippets.

View willbroderick's full-sized avatar

Will Broderick willbroderick

  • Clean Canvas Ltd
  • Nottingham, UK
View GitHub Profile
@willbroderick
willbroderick / split_images_from_content.liquid
Last active December 31, 2015 22:29
Liquid code to separate X number of images from html content - for displaying these in separate areas.
{% comment %}
Use:
{% include 'split_images_from_content' with collection.description %}
<div class="header">{{ split_images }}</div>
<div class="description">{{ split_content }}</div>
{% endcomment %}
{% assign num_to_split = 1 %}
{% assign split_content = split_images_from_content %}
{% assign split_images = '' %}
@willbroderick
willbroderick / jquery.shopifyproductfill.js
Last active December 7, 2016 17:29
Fill an HTML template with an arbitrary Shopify product, with AJAX
/*
Fill an HTML template with a Shopify product
MIT license.
Example use:
<span class="prev" data-fill-with-product="{{ collection.previous_product | split: '/' | last }}">
<script type="text/template">
<a href="{{ collection.previous_product }}" title="[encode:title]">
<span class="title">[title]</span>
<img src="[img:600x]" />
@willbroderick
willbroderick / willFillParent.js
Last active January 10, 2017 10:30
Set an image or iframe to fill its parent (like a desktop wallpaper)
/* Take an image, or any other element with height/width attrs (e.g. iframe) and stretch it to fill parent
* MIT license
*
* Dependencies:
* imagesLoaded: https://github.com/desandro/imagesloaded
*
* Usage examples:
* $('.fillcontainer img.main').willFillParent({ closest: '.fillcontainer', windowEvent: 'debouncedresize load' });
* $('.video-bg > .video').willFillParent({ windowEvent: 'resize' });
*
@willbroderick
willbroderick / twitter-card.liquid
Last active March 3, 2017 09:04
Shopify - use checkout logo as home page Twitter card image
If you use a checkout logo, and want to use that as your Twitter card image on the home page,
add the following code at the very bottom of the twitter-card snippet:
{% if template == 'index' and settings.checkout_logo_image != blank %}
<meta property="twitter:image" content="https:{{ settings.checkout_logo_image | img_url: '600x600' }}">
{% endif %}
@willbroderick
willbroderick / improve-line-breaks.js
Last active September 7, 2017 15:09
Prevent a line-break before the last word in a passage of text, to aid typography
/*
* This will turn "I eat lots of poached eggs" into "I eat lots of poached&nbsp;eggs"
*
* So this:
* | I eat lots of poached |
* | eggs
*
* Becomes:
* | I eat lots of |
* | poached eggs |
@willbroderick
willbroderick / expression-two-per-row.css
Created October 18, 2017 13:41
Expression - Two products per-row on mobile
@media only screen and (max-width: 767px) {
#content .productlist .product { width: 48%; }
#content .productlist .product:nth-child(2n+1) { margin-left: 4%; }
#page-collection #content .productlist .product:nth-child(2n) { margin-left: 4%; }
#page-collection #content .productlist .product:nth-child(2n+1) { margin-left: 0; }
#content .productlist .product .foot .buttoncont, #content .productdetail .buttoncont { max-width: 100%; }
}
@willbroderick
willbroderick / overflowing-tables.js
Created October 19, 2017 15:27
Overflowing tables - wrap in a scrollable container
// copy this to the very bottom of themes.js.liquid (might need to change the '.rte' depending on theme - this one's for Showcase)
$('.rte table').wrap('<div style="overflow: auto; border: 1px solid rgba(0,0,0,0.0.5)">');
@willbroderick
willbroderick / bumpMeDown.js
Last active October 24, 2017 07:58
Emulate position:fixed on a div to keep it locked, vertically, inside the browser viewport. Designed for tiny sidebar-style content.Add class 'bump-me-down' to any floated div & it'll add padding to the top to make it fit.
/// Bump-down a div to fit (position:fixed style) inside a browser
$(function(){
if($('.bump-me-down').length > 0) {
$(window).on('scroll process-bump-me-downs resize', function(){
var scrollTop = $(window).scrollTop();
var defaultPad = 20;
$('.bump-me-down').each(function(){
var thisOffset = $(this).offset().top;
if($(this).data('bumpOffset')) {
thisOffset -= $(this).data('bumpOffset');
@willbroderick
willbroderick / product-json.liquid
Last active November 13, 2017 15:17
Replacement for {{ product | json }} with accurate inventory information removed
{% comment %}## Add this snippet, then replace {{ product | json }} with {% include 'product-json' %} ##{% endcomment %}
{% capture product_json %}{{ product | json }}{% endcapture %}
{% assign product_json_split = product_json | split: '"inventory_quantity":' %}
{%- for str in product_json_split -%}
{%- if forloop.first -%}{{ str }}
{%- else -%}
"inventory_quantity":
{%- assign str_split = str | split: ',' -%}
{%- for str2 in str_split -%}
{%- unless forloop.first -%},{%- endunless -%}
@willbroderick
willbroderick / pick-a-symmetry-sections.js
Last active February 27, 2018 17:38
Show 'Choose...' in a Symmetry theme with Sections
// copy this to the very bottom of Assets/theme.js.liquid, below everything else in there
$(document).on('optionate', 'select[name="id"]', function(){
var $this = $(this);
setTimeout(function(){
if(!$this.closest('.product-detail').find('.option-selectors select option[value=""]').length) {
$this.closest('.product-detail').find('.option-selectors select').prepend('<option value="">Choose...</option>').val('').trigger('change');
$this.closest('.product-detail').find('.price-area').html('&nbsp;');
$this.closest('.product-detail').find('.gallery .thumbnails a:first').trigger('click');
}