Skip to content

Instantly share code, notes, and snippets.

@alexbaulch
alexbaulch / Handlebars-JSON.js
Created December 2, 2015 12:59
Return a JSON.stringify of the object you parse in.
/**
* Created by abaulch on 02/12/15.
*/
Handlebars.registerHelper('json', function(obj) {
return JSON.stringify(obj);
});
events.subscribe('button-clicked', function(data) {
alert(data.text);
});
$('button').on('click', function(e) {
e.preventDefault();
events.publish('button-clicked', {
text: $(this).text()
});
@alexbaulch
alexbaulch / bp.scss
Created December 21, 2014 17:53
Custom breakpoint mixin for Sass
@mixin bp($point) {
@media (max-width: ($point)) {
@content;
}
}
@alexbaulch
alexbaulch / pub-sub.js
Created December 11, 2014 16:42
Miniature PubSub library in AMD pattern
define(function() {
'use strict';
var pubSub = function pubSubFn() {
var topics = {};
function subscribe(topic, listener) {
// Create the topic's object if not yet created
if (!topics[topic]) {
topics[topic] = {
@alexbaulch
alexbaulch / google-analytics.js
Created December 2, 2014 17:03
Check form to which fields have been filled in before a user abandons it and send the fields to Google Analytics.
// stuff to do before the page un loads
if ( $('[data-page-name="contact"]').length ) {
var count = 0;
window.onbeforeunload = function(e) {
var contactUsForm = $('[data-page-name="contact"]').find('.contact-us-form');
var requiredFields = contactUsForm.find('[data-val-required]');
var completedFields = [];
var missedFields = [];
@alexbaulch
alexbaulch / _placeholder-mixin.scss
Created December 1, 2014 00:22
Sass (scss) mixin for styling placeholders cross browser
@mixin placeholder {
::-webkit-input-placeholder {@content}
:-moz-placeholder {@content}
::-moz-placeholder {@content}
:-ms-input-placeholder {@content}
}
@alexbaulch
alexbaulch / ie8-safe-svg.html
Last active August 29, 2015 14:10
Wrapper for safe use of SVGs in IE8
<!--[if gte IE 9]><!-->
<svg>Goes here</svg>
<!--<![endif]-->
<!--[if lte IE 8]>
Fallback image goes here for IE8
<img src="http://placehold.it/300x300" alt="Fallback image" />
<![endif]-->
@alexbaulch
alexbaulch / index.html
Last active August 29, 2015 14:10
adding IE specific classes to the html tag to enable styling based on just specific versions of IE
<!--[if lt IE 7]> <html class="lt-ie10 lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie10 lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie10 lt-ie9" lang="en"> <![endif]-->
<!--[if IE 9]> <html class="lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!-->
<html class="" lang="en">
<!--<![endif]-->
@alexbaulch
alexbaulch / get-query-variable.js
Last active August 29, 2015 14:07
A small CommonJS module for fetching the value of a given url param.
module.exports = function(variable) {
//get query params and remove the beginning '?'
var query = window.location.search.substring(1);
//split on ampersand
var vars = query.split('&');
//loop through 'vars' array
for (var i = 0; i < vars.length; i++) {
// split on '=' to give key value pairs
@alexbaulch
alexbaulch / cookie.js
Created September 25, 2014 13:45
CommonJS cookie handler