Skip to content

Instantly share code, notes, and snippets.

View boldfacedesign's full-sized avatar

David Parker boldfacedesign

View GitHub Profile
@boldfacedesign
boldfacedesign / PPK cookies
Created April 28, 2014 15:36
PPK cookies
//read, write and erase cookie functions by PPK - quirksmode.org
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
@boldfacedesign
boldfacedesign / Shopify sitemap collection urls
Created April 27, 2014 22:45
Shopify get all collection urls from sitemap
function loadXMLDoc(filename) {
if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest();
}
else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
Property Description
hash Returns anchor portion of the URL, including the leading hash. (“#results”)
host Returns the hostname and port (if available) of a URL. (“www.example.com” or “www.example.com:80″)
hostname Returns the hostname portion of the URL (“www.example.com”)
href Returns the entire URL. (“http://www.example.com:80/example.php?x=1&y=2#results”)
pathname Returns the path name of the URL (“/example.php”)
port Returns the port portion of the URL (“80″ within the host “www.example.com:80″)
protocol Returns the protocol portion of the URL, including the trailing colon (“http:”, “https:”, “ftp”, etc)
search Returns the query portion of the URL, including the question mark (“?x=1&y=2″)
@boldfacedesign
boldfacedesign / fix Array.indexOf()
Created April 8, 2014 11:14
fix Array.indexOf()
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
@boldfacedesign
boldfacedesign / TEST FOR SUPPORT OF MIN-HEIGHT ON DISPLAY TABLE ELEMENTS
Created April 8, 2014 11:02
TEST FOR SUPPORT OF MIN-HEIGHT ON DISPLAY TABLE ELEMENTS
//TEST FOR SUPPORT OF MIN-HEIGHT ON DISPLAY TABLE ELEMENTS
(function() {
//CREATE ELEMENT IN DOM
var elem = document.createElement('div');
//ADD STYLES
elem.style.display = 'table';
elem.style.minHeight = '2px';
//APPEND TO DOM
document.body.appendChild(elem);
//MEASURE HEIGHT
@boldfacedesign
boldfacedesign / Placeholder polyfil
Created April 8, 2014 11:01
Placeholder Polyfil
//POLYFILL PLACEHOLDERS IN IE8/9
if (document.createElement("input").placeholder == undefined) {
//GET ALL TEXT INPUTS
var inp = document.querySelectorAll('input[type=text]');
//LOOP THROUGH AND USE PLACEHOLDER AS VALUE
for (i=0;i<inp.length;i++) {
var plhTxt = inp[i].getAttribute('placeholder');
inp[i].setAttribute('value',plhTxt);
//SET VALUE TO BLANK ON FOCUS IF VALUE = PLACEHOLDER
inp[i].onfocus=function(){
@boldfacedesign
boldfacedesign / touch optimized mega-menus
Created April 8, 2014 10:57
touch optimized mega-menus
//Touch optimization for mega-menus
if ($('html').hasClass('touch')) {
$('#page').on('click', function(e){
if ($('.region-navigation .menu-name-menu-main-navigation > ul > li').hasClass('open')) {
e.stopPropagation();
e.preventDefault();
$('.region-navigation .menu-name-menu-main-navigation > ul > li').removeClass('open');
}
});
@boldfacedesign
boldfacedesign / Gulp KSS
Last active October 16, 2019 21:17
Gulp KSS
var gulp = require('gulp'),
kss = require('gulp-kss'),
rename = require('rename');
gulp.task('kss-css', function() {
return gulp.src(['css/master.css']) //get compiled CSS
.pipe(rename('style.css')) //rename to KSS required nameing convention
.pipe(gulp.dest('guides/complete/public')); //move to KSS compile folder
});
@boldfacedesign
boldfacedesign / Compass sprite cleaner
Created April 8, 2014 10:50
Compass sprite cleaner function (Ruby)
module Compass::SassExtensions::Functions::Sprites
def sprite_url(map)
verify_map(map, "sprite-url")
map.generate
generated_image_url(Sass::Script::String.new(map.name_and_hash))
end
end
module Compass::SassExtensions::Sprites::SpriteMethods
def name_and_hash
@boldfacedesign
boldfacedesign / shopify collection loop
Created March 23, 2014 18:29
shopify collection loop
{% if c.handle contains collection.handle and c.handle != collection.handle %}
<li class="{{ forloop.index }}">
<a href="{{ c.url }}" title="{{ c.title }}">
<span class="product-border"></span>
<div class="img-wrap">
<span class="img-wrap__inner">
<img src="{{ c.image.src | collection_img_url: 'medium' }}">
</span>
</div>