Skip to content

Instantly share code, notes, and snippets.

@petermac-
petermac- / 1-debounce.js
Last active September 12, 2015 19:14
debounce.js
var debounce = function(func, wait) {
// we need to save these in the closure
var timeout, args, context, timestamp;
return function() {
// save details of latest call
context = this;
args = [].slice.call(arguments, 0);
timestamp = new Date();
@petermac-
petermac- / 1-isNative.js
Last active September 12, 2015 19:14
isNative.js
;(function() {
// Used to resolve the internal `[[Class]]` of values
var toString = Object.prototype.toString;
// Used to resolve the decompiled source of functions
var fnToString = Function.prototype.toString;
// Used to detect host constructors (Safari > 4; really typed array specific)
var reHostCtor = /^\[object .+?Constructor\]$/;
@petermac-
petermac- / 1-insertRule.js
Last active September 12, 2015 19:14
insertRule.js
var sheet = (function() {
// Create the <style> tag
var style = document.createElement('style');
// Add a media (and/or media query) here if you'd like!
// style.setAttribute('media', 'screen')
// style.setAttribute('media', 'only screen and (max-width : 1024px)')
// WebKit hack :(
style.appendChild(document.createTextNode(''));
@petermac-
petermac- / 1-matchesSelector.js
Last active September 12, 2015 19:14
matchesSelector.js
function matchesSelector(el, selector) {
var p = Element.prototype;
var f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function(s) {
return [].indexOf.call(document.querySelectorAll(s), this) !== -1;
};
return f.call(el, selector);
}
// Usage
matchesSelector(document.getElementById('myDiv'), 'div.someSelector[some-attribute=true]')
@petermac-
petermac- / 1-detect-animation-end-examples.js
Last active September 12, 2015 19:14
detect-animation-end-examples.js
// jQuery example
// http://osvaldas.info/examples/detecting-css-animation-transition-end-with-javascript/oncssanimationend.js
$( '.item' ).addClass( 'disappear' ).onCSSAnimationEnd( function()
{
$( this ).remove();
});
// JavaScript example
// http://osvaldas.info/examples/detecting-css-animation-transition-end-with-javascript/jquery.oncssanimationend.js
var item = document.querySelector( '.item' );
@petermac-
petermac- / 1-isValidEmail.js
Last active September 12, 2015 19:14
isValidEmail.js
function isValidEmail(string){
string = string||'';
var lastseg = (string.split('@')[1]||'').split('.')[1]||'',
input = document.createElement('input');
input.type = "email";
input.required = true;
input.value = string;
return !!(string && (input.validity && input.validity.valid) && lastseg.length);
}
@petermac-
petermac- / SassMeister-input.scss
Last active September 12, 2015 04:11
SASS Typography (SassMeister)
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// Breakpoint (v2.5.0)
// Modular Scale (v2.1.1)
// ----
@import "modular-scale";
@import "breakpoint";
@petermac-
petermac- / SassMeister-input-HTML.html
Last active September 12, 2015 03:21
Simple SASS Button Mixin v0.1 with Compass (SassMeister)
<button class="btn btn--primary">Primary button</button>
<button class="btn btn--secondary">Secondary button</button>
@petermac-
petermac- / SassMeister-input-HTML.html
Last active September 12, 2015 03:21
Simple SASS Button Mixin v0.2 without Compass (SassMeister)
<button class="btn btn--primary">Primary button</button>
<button class="btn btn--secondary">Secondary button</button>
@petermac-
petermac- / SassMeister-input-HTML.html
Last active September 12, 2015 03:14
SASS Button Mixin v0.1 (SassMeister)
<div>
<button class="button button--small button--default">Small button</button>
<button class="button button--small button--success">Small success button</button>
<button class="button button--small button--warning">Small warning button</button>
<button class="button button--small button--danger">Small danger button</button>
<button class="button button--small button--info">Small info button</button>
</div>
<div>
<button class="button button--default">Medium button</button>