Skip to content

Instantly share code, notes, and snippets.

@DanWebb
DanWebb / excerpt_image.liquid
Created August 26, 2015 07:50
Extract an image src from an article excerpt
{% comment %}
This include requires you to pass in the an article excerpt
which contains a single image.
Example: {% include 'excerpt_image' with article.excerpt %}
{% endcomment %}
{% assign src = excerpt_image | split: 'src="' %}
@DanWebb
DanWebb / form_obj.js
Created August 28, 2015 11:22
Make key/value pairs from form elements based on name and value attributes
var obj = {};
$('form').find('input, select, textarea').each(function() {
obj[this.name] = this.value;
});
// Or create an object based on a specific group of form elements
var address = {};
$('form').find('[name^="address"]').each(function() {
address[this.name.replace('address[','').replace(']','')] = this.value;
});
@DanWebb
DanWebb / notification.js
Created May 1, 2014 17:56
Simple notification object
var notification = {
element: $('#notification'),
timeout: null,
show: function(type, message) {
'use strict';
// reset the current timer
clearTimeout(this.timeout);
this.element
@DanWebb
DanWebb / setIntervalTimeout.js
Last active August 29, 2015 14:03
setIntervalTimeout method created to solve issues with elements loading after page load where promises can't be applied.
// call a callback function every *interval* until *stopTime* or until (bool)true is
// returned from the callback function
function setIntervalTimeout(callback, interval, stopTime) {
var i;
i = setInterval(function() {
if(callback()) clearInterval(i);
}, interval);
setTimeout(function() {
@DanWebb
DanWebb / jquery.ba-tinypubsub.js
Last active August 29, 2015 14:05 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@DanWebb
DanWebb / wait.js
Last active August 29, 2015 14:15
Set a waiting period on any number of different actions definable by name and time parameters, returns true if the action can be executed or false if it is being called again within the waiting period.
var wait = (function() {
var timers = {};
return function(name, time) {
// if the current timer has not been set yet or it has previously
// been set but finished it's waiting period
if(typeof(timers[name])==='undefined' || timers[name]) {
timers[name] = false;
setTimeout(function() { timers[name] = true; }, time);
return true;
@DanWebb
DanWebb / related_articles.liquid
Last active August 29, 2015 14:15
Retrieve related articles based on tag Edit: changed it from only checking the first tag in the article to going through every tag. It's more resource intensive but only checking the first tag isn't good enough in most cases
@DanWebb
DanWebb / shopify_select.css
Last active August 29, 2015 14:19
Shopify admin like custom select box with bootstrap and jquery
.custom-select {
position: relative;
width: 100%;
}
.custom-select > span {
border-radius: 3px;
border: 1px solid #d3dbe2;
padding: 5px 15px;
color: #479ccf;
cursor: pointer;
@DanWebb
DanWebb / some_stock.liquid
Created May 2, 2015 08:20
Get whether some (but not all) of the variants products are out of stock
{% assign some_stock = false %}
{% assign out_of_stock = 0 %}
{% for variant in product.variants %}
{% if variant.available == false %}
{% assign out_of_stock = out_of_stock | plus: 1 %}
{% endif %}
{% endfor %}
{% if product.variants.size != out_of_stock and out_of_stock > 0 %}
{% assign some_stock = true %}
{% endif %}
@DanWebb
DanWebb / latest_posts.liquid
Last active August 29, 2015 14:20
Get any amount of latest blog posts among any amount of different blogs
{% comment %}
blog_handles should contain the handles of each blog you want to pull posts from
seperated by commas.
{% endcomment %}
{% assign blog_handles = 'blog-1,blog-2,blog-3,blog-4,blog-5' | split: ',' %}
{% comment %}initialise the previous_article_timestamp as the current time{% endcomment %}
{% assign previous_article_timestamp = 'now' | date: '%s' %}
{% comment %}i represents the number of featured articles that will be shown{% endcomment %}