This file contains 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
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; | |
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) { | |
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; | |
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; |
This file contains 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
// Example 1 | |
mediator.name = 'Doug'; | |
mediator.subscribe('nameChange', function(arg){ | |
console.log(this.name); | |
this.name = arg; | |
console.log(this.name); | |
}); | |
mediator.publish('nameChange', 'Jorn'); |
This file contains 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 parse = JSON.parse; | |
JSON = { | |
stringify: JSON.stringify, | |
validate: function(str){ | |
This file contains 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
// a simple facade that masks the various browser-specific methods | |
function addEvent( element, event, callback ) { | |
if( window.addEventListener ) { | |
element.addEventListener( event, callback, false ); | |
} else if( document.attachEvent ) { | |
element.attachEvent( 'on' + event, callback ); | |
} else { | |
element[ 'on' + event ] = callback; | |
} |
This file contains 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 MyModule = ( function( window, undefined ) { | |
// revealing module pattern ftw | |
function MyModule() { | |
function someMethod() { | |
alert( 'some method' ); | |
} | |
function someOtherMethod() { |
This file contains 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 excerpt($limit) { | |
$excerpt = explode(' ', get_the_excerpt(), $limit); | |
if (count($excerpt)>=$limit) { | |
array_pop($excerpt); | |
$excerpt = implode(" ",$excerpt).'...'; | |
} else { | |
$excerpt = implode(" ",$excerpt); | |
} | |
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); |
This file contains 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 fitElement = function fitElement(elementSelector, elementAspect) { | |
var element = (typeof elementSelector === 'string' || elementSelector instanceof String) ? document.querySelector(elementSelector) : elementSelector, | |
parW = element.parentNode.clientWidth, | |
parH = element.parentNode.clientHeight, | |
parAsp = parW / parH, | |
aspect = elementAspect || 16 / 9, | |
elW, elH; | |
if (aspect > parAsp) { | |
elW = parW; | |
elH = elW / aspect; |
This file contains 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
//source: http://stackoverflow.com/questions/4508574/remove-hash-from-url | |
//Best is Homero Barbosa's answer below: | |
history.pushState('', document.title, window.location.pathname); | |
//... or, if you want to maintain the search parameters: | |
history.pushState('', document.title, window.location.pathname + window.location.search); | |
//Old, do not use, badwrongfun: | |
// var loc = window.location.href, | |
// index = loc.indexOf('#'); | |
// if (index > 0) { |
This file contains 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
//Setup | |
let el = document.getElementById('thingy'); | |
let elChild = document.createElement('div'); | |
elChild.innerHTML = 'Content'; | |
//Append | |
el.appendChild(elChild); | |
//Prepend | |
el.insertBefore(elChild, el.firstChild); |
This file contains 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 (window) { | |
document.addEventListener("DOMContentLoaded", function (e) { | |
var supports = { | |
srcset: false, | |
currentSrc: false, | |
sizes: false, | |
picture: false | |
}; | |
var img = new Image(); |
OlderNewer