Skip to content

Instantly share code, notes, and snippets.

View chrisjhoughton's full-sized avatar

Chris Houghton chrisjhoughton

  • Beacon
  • London, UK
View GitHub Profile
@chrisjhoughton
chrisjhoughton / wait-global.js
Created December 10, 2013 13:02
Wait for a global variable to exist on the page.
var waitForGlobal = function(key, callback) {
if (window[key]) {
callback();
} else {
setTimeout(function() {
waitForGlobal(key, callback);
}, 100);
}
};
@chrisjhoughton
chrisjhoughton / enforce-http.liquid.js
Last active February 14, 2024 07:49
How to build an ajax form on Shopify. See http://inside.sauce.ly/how-to-build-an-ajax-login-form-on-shopify/ for the full blog post.
/*
* Ensure the http protocol is always used on the myshopify.com domains.
* Uses liquid to input the correct URL.
*/
if (window.location.href.match(/https:\/\/.*.myshopify.com/) && top === self) {
window.location.href = window.location.href.replace(/https:\/\/.*.myshopify.com/, 'http://{{ shop.domain }}');
}
@chrisjhoughton
chrisjhoughton / wait-el.js
Last active October 6, 2023 09:46
Wait for an element to exist on the page with jQuery
var waitForEl = function(selector, callback) {
if (jQuery(selector).length) {
callback();
} else {
setTimeout(function() {
waitForEl(selector, callback);
}, 100);
}
};
@chrisjhoughton
chrisjhoughton / remove.liquid
Last active September 9, 2023 07:56
Remove a Shopify cart attribute
{% if cart.attributes.yourCartAttribute %}
<script>
$.ajax({
type: 'POST',
url: '/cart/update.js',
data: 'attributes[yourCartAttribute]=',
dataType: 'json'
});
</script>
{% endif %}
@chrisjhoughton
chrisjhoughton / fb-open-graph.liquid
Last active September 9, 2023 07:52
Facebook Open Graph meta tags for Shopify. Add this as a snippet called "fb-open-graph.liquid" in your theme, and then add {% include 'fb-open-graph' %} to your theme.liquid file.
{% if template contains 'product' %}
<meta property="og:type" content="product">
<meta property="og:title" content="{{ product.title | strip_html | escape }}">
<meta property="og:category" content="{{ product.type }}" />
{% for image in product.images limit:3 %}
<meta property="og:image" content="http:{{ image.src | product_img_url: 'master' }}">
<meta property="og:image:secure_url" content="https:{{ image.src | product_img_url: 'master' }}">
{% endfor %}
<meta property="og:price:amount" content="{{ product.price | money_without_currency | stip_html | escape | remove: ',' }}">
<meta property="og:price:currency" content="{{ shop.currency }}">
@chrisjhoughton
chrisjhoughton / proxy.apache.conf
Last active August 9, 2023 10:17
Sample Nginx reverse proxy to Apache set up for Wordpress.
<VirtualHost *:{PORT}>
ServerName www.yourdomain.com
ServerAdmin mail@domain.com
DocumentRoot /var/www/yourdir/
<Directory /var/www/yourdir>
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
@chrisjhoughton
chrisjhoughton / README.md
Last active May 19, 2023 04:36
Notify tray workflows "webhook style" from Salesforce using Apex triggers.

Salesforce Apex trigger notifications for tray.io

Salesforce's Apex triggers allow you to trigger tray workflows in real-time, based on events that occur in Salesforce. Events include things like:

  • New lead creations
  • Opportunity updates, such as the status moving from "open" to "closed"

Salesforce doesn't support webhooks out of the box, so we'll need to add some Apex code to your Salesforce account to notify tray at the right time.

@chrisjhoughton
chrisjhoughton / twitter-cards.liquid
Last active March 2, 2023 07:39
Twitter Card meta tags for Shopify. Add this as a snippet called "twitter-cards.liquid" in your theme, and then add {% include 'twitter-cards' %} to your theme.liquid file.
{% comment %}
This snippet renders meta data needed to create a Twitter card
for products and articles.
IMPORTANT: change @your_twitter_username with your actual twitter username!
Your cards must be approved by Twitter to be activated
- https://dev.twitter.com/docs/cards/validation/validator
@chrisjhoughton
chrisjhoughton / backbone.sync.js
Last active August 14, 2022 02:22
Backbone Sync with jQuery and a REST API
/*
Overview:
- triggers "sync", "sync_success" and "sync_error" messages after sync
- runs this.url() on the model/collection inputted (note - this function is declared by default in models, not collections. See http://backbonejs.org/#Collection-url for more details)
- handles the four main REST api methods: POST, PUT, GET, DELETE
- expects 'create' to return an id, which is auto-set to the newly created model
- automatically sets parameters when 'fetching' models
- automatically adds models to collections when 'fetching' collections
EXAMPLES:
@chrisjhoughton
chrisjhoughton / fb-conversion.liquid
Last active February 19, 2022 04:57
Facebook's conversion pixel code, ready to go for Shopify with liquid variables. Change the `youraccountid` and add this to the "additional content and scripts" section of your checkout settings.
<!-- Facebook Conversion code -->
{% assign fb_pixel_id = 'yourpixelid' %}
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];