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
| const url = origin + '/amp_preconnect_polyfill?' + Math.random(); | |
| const xhr = new XMLHttpRequest(); | |
| xhr.open('HEAD', url, true); | |
| xhr.send(); |
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
| const prefetch = document.createElement('link'); | |
| prefetch.setAttribute('rel', 'prefetch'); | |
| prefetch.setAttribute('href', url); | |
| document.head.appendChild(prefetch); |
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 inFullScreen = document.fullscreenEnabled || document.fullscreenElement || | |
| window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled; | |
| if (inFullScreen) { | |
| //do something.. | |
| if (document.exitFullscreen) { | |
| document.exitFullscreen(); | |
| } else if (document.mozCancelFullScreen) { | |
| document.mozCancelFullScreen(); | |
| } else if (document.webkitExitFullscreen) { | |
| document.webkitExitFullscreen(); |
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
| // array utils | |
| // ================================================================================================= | |
| const combine = (...arrays) => [].concat(...arrays); | |
| const compact = arr => arr.filter(Boolean); | |
| const contains = (() => Array.prototype.includes | |
| ? (arr, value) => arr.includes(value) | |
| : (arr, value) => arr.some(el => el === 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
| // 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 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 MyModule = ( function( window, undefined ) { | |
| // revealing module pattern ftw | |
| function MyModule() { | |
| function someMethod() { | |
| alert( 'some method' ); | |
| } | |
| function someOtherMethod() { |
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
| // 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 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
| // 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']; |
NewerOlder