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 / 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');
}
@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 / 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 / seo-hacks.liquid
Last active March 22, 2021 16:50
Shopify SEO - attempt to avoid duplicate meta descriptions
Two changes to make in theme.liquid
It will add 'Page 2' etc to the meta description for collection/blog pages, to make those different.
It adds a canonical tag for tag-filtered pages, back to the base collection/blog page.
*** This is the standard meta description code: ***
{% if page_description %}
<meta name="description" content="{{ page_description | escape }}" />
{% endif %}
@willbroderick
willbroderick / clickyboxes.scss
Last active May 22, 2018 14:32
Turn a <select> tag into a list of clickable boxes that behave like radio buttons.
.clickyboxes {
margin: 0.4em 0 1em;
padding: 0;
li {
display: inline;
vertical-align: top;
a {
display: inline-block;
@willbroderick
willbroderick / jquery.cropImageToRatio.js
Last active December 21, 2015 16:37
Wraps an image with a fixed-ratio div and scales/translates the image to fill. Uses % CSS so no resize events needed.
/// Crop and scale images to a specific ratio
$.fn.cropImageToRatio = function(params){
//params
var params = $.extend({
ratio: 4/3,
wrapper: '<div/>'
}, params);
//loop all images
return $(this).each(function(){
//only allow init once
@willbroderick
willbroderick / gist:dbb4064ba345790b39f9
Last active August 29, 2015 14:19 — forked from carolineschnapp/currencies.liquid
Keeps the 'You have chosen GBP, but the shop is AUS' message hidden, if you're using the native currency
{% if settings.show_multiple_currencies %}
{{ "//cdn.shopify.com/s/javascripts/currencies.js" | script_tag }}
{{ "jquery.currencies.min.js" | asset_url | script_tag }}
<script>
{% if settings.currency_format %}
Currency.format = '{{ settings.currency_format }}';
{% endif %}
@willbroderick
willbroderick / normheights.js
Last active November 17, 2015 09:29
Help normalise the heights of items laid out in responsive rows - relies on presence of an inner div that will keep natural height of objects inside. Useful for keeping prices aligned under product images.
$(window).on('debouncedresize load', function(){
$('[data-normheights]').each(function(){
var $items = $(this).find($(this).data('normheights')),
childFilter = $(this).data('normheights-inner'),
tallest = 0,
lastYOffset = 0,
row = [];
$items.each(function(index){
var $img = $(this).find(childFilter);
var yOffset = $(this).offset().top;
@willbroderick
willbroderick / jquery.staggeredEvent.js
Created June 17, 2014 10:19
Stagger events across a collection of elements
/*
Stagger an event across a collection of elements. Useful for making the pretties.
Example - for loading in ajax results with a class-based css3 transition, where results are initially hidden with hide():
$('#ajax-results').on('loaded', function(){
$(this).children('.result').addClass('pre-transition').slideDown(250).staggerEvent(function(el){
$(el).removeClass('pre-transition');
}, 150, 250);
});
*/
@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]" />