Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
craigmdennis / index.html
Created May 11, 2014 14:21
A SASS mixin to dynamically create intrinsic ratios for responsive embedded content. For more info visit http://alistapart.com/article/creating-intrinsic-ratios-for-video
<!-- The `data-ratio` attribute contains the width and height of the image -->
<div data-ratio="560-300" class="responsive-wrapper">
<img src="http://placehold.it/560x300" class="fill-container"/>
</div>
<div data-ratio="420-315" class="responsive-wrapper">
<iframe width="420" height="315" src="//www.youtube.com/embed/dQw4w9WgXcQ?rel=0" frameborder="0" allowfullscreen class="fill-container"></iframe>
</div>
@craigmdennis
craigmdennis / Gruntfile.js
Last active August 29, 2015 14:02
Use Grunt to write Kirby templates in Jade and compile to .php
// Generated on 2014-03-14 using generator-webapp 0.4.8
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@craigmdennis
craigmdennis / footer.php
Last active August 29, 2015 14:02
List contents of a directory with a specific filetype. Used in developing Wordpress with Grunt.
@craigmdennis
craigmdennis / app.coffee
Created August 7, 2014 20:39
Filtering Isotope with Multiple selects and a Tag input.
'use strict'
# Document Ready
$ ->
# Initialise Isotope
# http://isotope.metafizzy.co
$('.isotope').isotope
itemSelector: '.isotope-item'
@craigmdennis
craigmdennis / function.coffee
Created August 8, 2014 18:09
Object Literal Function Boilerplate
'use strict'
Upload =
init: (options) ->
# Set some default options
defaults =
debug: false
# Merge all the options
@craigmdennis
craigmdennis / validate.coffee
Last active August 29, 2015 14:05
Allow jQuery Validate to mark Chosen select box as valid
# Allow jQuery Validate to run validation on jQuery Chosen
# select boxes by changing the ignore selector from `:hidden`
$.validator.setDefaults
ignore: '.no-validate'
# jQuery Validate doesn't mark fields as valid on hidden elements
# So when using Chosen we need to show the original input,
# give it focus and then hide it again
@craigmdennis
craigmdennis / Gruntfile.js
Last active August 29, 2015 14:05
Rename file extensions with Grunt copy.
// Compile Jade (allowing for php)
jadephp: {
options: {
pretty: true
},
// Compile templates to HTML in .tmp so we can run useminPrepare
dist: {
files: [
{
expand: true,
@craigmdennis
craigmdennis / click.js
Last active August 29, 2015 14:05
Open all external links in a new window with one line of jQuery
$('.content').on('click', 'a[href*="//"]:not([href*="mysite.com"])', function(){
$(this).attr('target','_blank');
});
@craigmdennis
craigmdennis / underlines.scss
Last active August 29, 2015 14:05
Better underlines using background linear gradients
// Underlines
// http://codepen.io/ghepting/pen/tLnHK/
$background-color: #FFF;
$link-color: $grey-2;
$link-color-active: $brand-red;
$link-underline-color: $link-color;
$link-underline-color-active: $link-color-active;
$link-underline-width: 2px;
$link-underline-offset: 2px;
$breaking-underlines: true;
@craigmdennis
craigmdennis / loadjquery.js
Created August 17, 2014 08:47
Load jQuery without using conditional comments.
if('querySelector' in document
&& 'localStorage' in window
&& 'addEventListener' in window) {
// Add jQuery 2.0+
document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"><\/script>')
} else {
// Add jQuery 1.9.0+
document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><\/script>')
}