This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var start; | |
var isRunning = false; | |
var frames = 0; | |
var intervalId; | |
var entries = []; | |
function onFrame () { | |
if (isRunning) { | |
window.requestAnimationFrame(onFrame); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAverage (arr) { | |
return arr.reduce(function (prev, cur) { | |
return prev + cur; | |
}) / arr.length; | |
} | |
function getNestedLevel (el) { | |
var level = 0; | |
while (el = el.parentNode) { | |
level++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var origLog = window.console.log.bind(window.console); | |
var stash = []; | |
window.console.log = function () { | |
stash.push([].slice.apply(arguments)); | |
origLog.apply(this, arguments); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gotData = function (request) { | |
if (request.params.query === someField.value) { | |
resultList.innerHTML = request.data.map(function (item) { | |
return '<li>' + item.text + '</li>'; | |
}); | |
} | |
} | |
someField.onkeyup = function () { | |
var query = someField.value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var race = new PromiseRace(); | |
var gotData = function (data) { | |
resultList.innerHTML = data.map(function(item){ | |
return '<li>' + item.text + '</li>'; | |
}); | |
} | |
someField.onkeyup = function() { | |
var promise = race.add($.get('/some/url?query=' + someField.value)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.addMatchers({ | |
toBeAbout: function (expected, precision) { | |
if (typeof this.actual !== 'number' || typeof expected !== 'number') { | |
return false; | |
} | |
var delta = Math.abs(expected - this.actual); | |
precision = precision || 20; | |
return delta <= precision; | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var THRESHOLD = 750; | |
var timeoutId; | |
var resizing = false; | |
var win = $(window); | |
win.on('resize', function () { | |
var timeout = function () { | |
clearTimeout(timeoutId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns transform preperty for this browser | |
*/ | |
var getTransformPrefix = function () { | |
if (getTransformPrefix.prefix === undefined) { | |
var prefixes = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform']; | |
var testNode = document.createElement('div'); | |
for (var i = 0; i < prefixes.length; i++) { | |
if (testNode.style[prefixes[i]] !== undefined) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mixin */ | |
.focus(@className: "focused") { | |
behavior: ~"expression(function focus(el) { el.runtimeStyle.behavior = 'none'; var focusClass = ' @{className}'; el.onfocus = function() { el.className += (focusClass); }; el.onblur = function() { el.className = el.className.replace(new RegExp(focusClass, 'g'), ''); }; }(this))"; | |
} | |
/* usage */ | |
.input { | |
.focus("input_focused"); | |
.input:focus, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mixin */ | |
.insert-html(@html: "") { | |
behavior: ~"expression(function html (el) { el.runtimeStyle.behavior = 'none'; if (!el.updated) { el.updated = true; el.insertAdjacentHTML('afterBegin', '@{html}'); } }(this))"; | |
} | |
/* usage */ | |
.some-class { | |
.insert-html('<span class="shadow"></span>'); | |
} |