Skip to content

Instantly share code, notes, and snippets.

@aurri
aurri / loadFonts.js
Created June 1, 2015 07:37
webfonts + localstorage
function loadFonts(url, defer){
localStorage.fontUrl == url
? inject(localStorage.font)
: defer
? window.addEventListener('DOMContentLoaded', load)
: load()
function load(){
var req = new XMLHttpRequest()
@aurri
aurri / find.js
Created July 24, 2014 07:24
Find items in a collection
// Find items in a collection
var _ = module.exports = {}
_.find = function(c, s){ return search(c, s, {one:true}) }
_.findIndex = function(c, s){ return search(c, s, {one:true, index:true}) }
_.findLast = function(c, s){ return search(c, s, {one:true, last:true}) }
_.findLastIndex = function(c, s){ return search(c, s, {one:true, index:true, last:true}) }
_.filter = function(c, s){ return search(c, s) }
@aurri
aurri / route.js
Last active August 29, 2015 14:03
Minimal routing library
/////////////////////////////////////////////////
//// Minimal routing library (IE10+)
/////////////////////////////////////////////////
// Listen to url changes:
// route(function(param, param...){}) - will get /param/param, split as arguments
// Navigate to path:
// route.to(path) - redirect to new path
// route.to(path, true) - redirect to new path, replacing current url
@aurri
aurri / lazy.js
Last active August 29, 2015 14:03
Lazy object properties
/////////////////////////////////////////////////
//// Lazy object properties
/////////////////////////////////////////////////
// Sets a property that computes its value on first access
// (see a test below for usage example)
function lazy(obj, prop, fn){
if(typeof prop === 'string') set(prop, fn)
else Object.keys(prop).forEach(function(k){ set(k, prop[k]) })
@aurri
aurri / minimal-router.js
Last active August 29, 2015 14:03
Simple minimal router
/////////////////////////////////////////////////
//// Simple minimal router (works in IE9+)
/////////////////////////////////////////////////
/*** Usage **************************************
//// Navigate to url
route('/path')
@aurri
aurri / riot-routing.js
Last active August 29, 2015 14:03
Routing with Riot.js
/////////////////////////////////////////////////
//// The app core
// A simple app that inherits from Riot
var app = Object.create(riot)
// Map urls to app.routes[method](args..)
@aurri
aurri / getTransitionDuration.js
Created January 11, 2014 22:24
Get transition duration in pure JavaScript, without jQuery
// Based on https://gist.github.com/snorpey/7230329
function getTransitionDuration(el){
var res = 0
prefix('transition-duration', function(v, pfx){
duration = el.style[v]
if(!duration) return
duration = parseTime(duration) + parseTime(el.style[pfx('transition-delay')] || 0)
function parseTime(s){ return parseFloat(s) * (s.indexOf('ms') >- 1 ? 1 : 1000) }
})