Last active
August 29, 2015 14:11
-
-
Save ckhatton/d3bf50574f2bcd0d4106 to your computer and use it in GitHub Desktop.
Shopify JS helpers; for adding 'error' class; formatting a string to an URL or from an URL, or to a Shopify URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addError(element) { $(element).addClass('error'); } | |
function removeError(element) { $(element).removeClass('error'); } | |
function formatForUrl(str) { | |
return str | |
.replace(/ /g, '%20') | |
.replace(/:/g, '%20') | |
.replace(/\\/g, '-') | |
.replace(/\//g, '-') | |
.replace(/-{2,}/g, '-'); | |
} | |
function formatFromUrl(str) { | |
return str.replace(/%20/g, ' '); | |
} | |
function formatForShopify(str) { | |
return str.replace(/%20/g, '+'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment