Skip to content

Instantly share code, notes, and snippets.

@objectfoo
objectfoo / lazyLoad.js
Last active October 13, 2015 05:08
Lazy loading function patterns
// Lazy Loading Functions
// Nicholas Zakas, Professional JavaScript for Web Developers p.736
(function() {
// Load on function call
var featureTestA = false;
var featureTestB = true;
var loadOnCall = function () {
console.log('load On Call');
if ( featureTestA ) {
@objectfoo
objectfoo / jsUtil.js
Last active October 13, 2015 11:57
JS Utils, ie7+ and good browsers
(function(window) {
window.jsUtil = {
normalizeEvent: function (e) {
e = e || window.event; // ie7&8
if(!e.preventDefault) {
e.preventDefault = function() {
e.returnValue = false; // ie7&8
};
}
if(!e.stopPropagation) {
@objectfoo
objectfoo / shiv_frag.html
Last active December 12, 2015 08:29
HTML5 elements can not be created in a document fragment on IE7 & IE8, if you want to create an HTML5 element inside a document fragment you need to apply the shiv just like the normal document object.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docFrag Shim Test</title>
</head>
<body>
<!--
HTML5 elements can not be created in a document fragment on IE7 & IE8,
if you want to create an HTML5 element inside a document fragment
/**
* closure
* *************************/
(function() {
var array = [];
for ( var i = 0; i < 10; i++ ) {
(function(i) {
array[i] = function () {
console.log('iteration: %s', i);
}
@objectfoo
objectfoo / guard.js
Last active December 17, 2015 05:48
Chainable guard object. Effective Javascript; David Herman. pg 165
// Chainable guard object. Effective Javascript; David Herman. pg 165
(function() {
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
@objectfoo
objectfoo / cssLinterSettings.json
Last active December 20, 2015 07:49
Sublime css linter mods needs to be in file: SublimeLinter.sublime-settings, other files currently don't work
{
"csslint_options":
{
"adjoining-classes": "warning",
"box-model": true,
"box-sizing": "warning",
"compatible-vendor-prefixes": false, // Tuned
"display-property-grouping": true,
"duplicate-background-images": "warning",
"duplicate-properties": true,

Block Element Modifier

BEM as described at http://bem.info.

Block

An independent interface piece that preserves a design point or some functionality. Anything that can be taken as a solid piece and can be put into a page is an interface block. Blocks are identified by a css class e.g. .tabbed-pane, .search.

Element

function debounce(fn, delay) {
var timer;
delay = delay || 250;
return function () {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
function pad(n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10);
}
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'];
// 26 Feb 16:19:34
function timestamp() {
@objectfoo
objectfoo / isDebugQueryString
Last active October 5, 2016 01:44
set window.isDebug to query string's debug=xxx
'use strict';
// if querystring contains isDebug then put query string value on window.isDebug
var isDebug = getParameterByName('debug');
function getParameterByName(name) {
var re_escaped_name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + re_escaped_name + '=([^&#]*)');
var results = regex.exec(location.search);
return results !== null