Skip to content

Instantly share code, notes, and snippets.

@fredryk
fredryk / gist:6241704
Created August 15, 2013 15:20
Nice phone numbers, ugly code.
{% assign phone = shop.phone | split: '' %}{{ phone[0] }}{{ phone[1] }}{{ phone[2] }}-{{ phone[3] }}{{ phone[4] }}{{ phone[5] }}-{{ phone[6] }}{{ phone[7] }}{{ phone[8] }}{{ phone[9] }}
@fredryk
fredryk / gist:6089294
Created July 26, 2013 14:28
Back in stock notification for product pages.
{% unless product.available %}
<div id="sold-out">
{% form 'contact' %}
{% if form.posted_successfully? %}
<p class="accent-text">Thanks! We will notify you when this product becomes available!</p>
{% else %}
<p>Click <a id="notify-me" href="#">here</a> to be notified by email when {{ product.title }} becomes available.</p>
{% endif %}
{% if form.errors %}
<div class="error feedback accent-text">
@fredryk
fredryk / gist:6082913
Created July 25, 2013 19:24
A fix for Kickstand's mobile menu on Android.
/* jQuery Dropdown */
var timeout=500;var closetimer=0;var ddmenuitem=0;function jsddm_open(){jsddm_canceltimer();jsddm_close();ddmenuitem=$(this).find("ul").eq(0).css("visibility","visible")}function jsddm_close(){if(ddmenuitem){ddmenuitem.css("visibility","hidden")}}function jsddm_timer(){closetimer=window.setTimeout(jsddm_close,timeout)}function jsddm_canceltimer(){if(closetimer){window.clearTimeout(closetimer);closetimer=null}}
$(document).ready(function(){
$("ul.drop > li").bind("mouseover",jsddm_open);
$("ul.drop > li").bind("mouseout",jsddm_timer);
if(!!('ontouchstart' in window)){//check for touch device
$("ul.drop > li").unbind('click mouseover mouseout');
$("ul.drop > li").bind("click", function() {
if ($(this).find("ul").eq(0).css("visibility") == "hidden") {
@fredryk
fredryk / gist:5880012
Created June 27, 2013 20:18
Disallow special characters from input fields.
$('#note').bind('keypress', function (event) {
var regex = new RegExp("^[a-zA-Z0-9]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
@fredryk
fredryk / gist:5587043
Last active December 17, 2015 09:28
Open external links in a new tab.
<script>
jQuery(document).ready(function($) {
jQuery("body a[href^='http://'], a[href^='https://']").attr("target","_blank");
});
</script>
@fredryk
fredryk / gist:5346158
Created April 9, 2013 14:33
Get and display the first image from a Shopify blog article.
{% if article.content contains '<img' %}
{% assign src = article.content | split: 'src="' %}
{% assign src = src[1] | split: '"' | first | replace: '//cdn', 'http://cdn' | replace: 'http:http://', 'http://' %}
<img src="{{ src }}" />
{% endif %}
@fredryk
fredryk / gist:4487260
Created January 8, 2013 19:47
A fix to display both link-list and tag generated navigation in the sidebar of the Clearflex theme. Many thanks to Caro (https://github.com/carolineschnapp) for her outstanding help and direction!
<!-- in collection-nav.liquid, replace this for loop code -->
{% for link in linklists.[settings.linklist_collections].links %}
<li class="collection{% if settings.show_collection_tags and link.object.all_tags.size > 0 %} dropdown{% endif %}">
<a href="{{ link.url }}"{% if link.active %} class="current"{% endif %}>{{ link.title | escape }}</a>
{% capture child_list_handle %}{{ link.title | handleize }}{% endcapture %}
{% if linklists[child_list_handle] and linklists[child_list_handle].links.size > 0 %}
<ul class="collection-tags">
{% for l in linklists[child_list_handle].links %}
<li><a href="{{ l.url }}">{{ l.title | escape }}</a></li>
@fredryk
fredryk / gist:4349218
Last active December 10, 2015 00:09
A little snippet in case you come across a theme where sub-navigation isn't showing in the mobile nav select.
{% for link in linklists.main-menu.links %}
{% assign child_list_handle = link.title | handleize %}
{% if linklists[child_list_handle].links != blank %}
<option value="{{ link.url }}">{{ link.title | escape }}</option>
{% for childlink in linklists[child_list_handle].links %}
<option value="{{ childlink.url }}">&nbsp; - {{ childlink.title | escape }}</option>
{% endfor %}
{% else %}
<option value="{{ link.url }}">{{ link.title | escape }}</option>
{% endif %}
@fredryk
fredryk / index.html
Created October 26, 2012 13:57
A CodePen by fredryk. Responsive Hover Descriptions - A test of different styles that can be applied to scalable product images to show the product's information.
<div class="wrap">
<div class="row">
<h1>Responsive Hover Descriptions</h1>
</div>
<div class="row">
@fredryk
fredryk / index.html
Created October 26, 2012 13:54
A CodePen by fredryk. Responsive Hover Descriptions - A test of different styles that can be applied to scalable product images to show the product's information.
<div class="wrap">
<div class="row">
<h1>Responsive Hover Descriptions</h1>
</div>
<div class="row">