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
// https://gist.github.com/edoardocavazza/47246856759f2273e48b | |
(function () { | |
if (typeof Object.setPrototypeOf === 'undefined' && typeof Object.getOwnPropertyNames === 'function') { | |
var _exclude = ['length', 'name', 'arguments', 'caller', 'prototype']; | |
function bindFunction(ctx, fn) { | |
return function() { | |
return fn.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
function TrapScroller(scroller) { | |
function callback(ev) { | |
ev.stopPropagation(); | |
var d = ev.deltaY || 0; | |
if ( | |
(scroller.scrollHeight !== scroller.offsetHeight) && ( | |
(d < 0 && scroller.scrollTop === 0) || | |
(d > 0 && (scroller.scrollTop >= scroller.scrollHeight - scroller.offsetHeight)) || | |
(scroller.scrollHeight === scroller.clientHeight)) | |
) { |
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 MAP = (typeof self.WeakMap !== 'undefined') ? new WeakMap() : false; | |
const PROP = '__private__'; | |
function internal(object) { | |
if (MAP) { | |
if (!MAP.has(object)) { | |
MAP.set(object, {}); | |
} | |
return MAP.get(object); | |
} |
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
<script> | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('sw.js'); | |
} | |
</script> |
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
// intercept network requests | |
this.addEventListener('fetch', (event) => { | |
// check if `event.request` è un file js | |
if (event.request.url.match(/.js$/)) { | |
event.respondWith( | |
// -> handle del file js | |
); | |
} | |
}); |
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
<script src="node_modules/unchained-js/dist/unchained.client.js"></script> | |
<script> | |
// register a Service Worker. | |
UnchainedClient.register('sw.js', { scope: '/' }).then( | |
// The Service Worker is ready, we can now import the main file. | |
UnchainedClient.import('index.js') | |
); | |
</script> |
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
import { h, render } from 'preact'; | |
import TodoList from './todolist.component.js'; | |
render(<TodoList />, document.body); |
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
// import Unchained core and plugins. | |
importScripts( | |
'node_modules/unchained-js/lib/core.js', | |
'node_modules/unchained-js/lib/plugins/babel.js', | |
'node_modules/unchained-js/lib/plugins/resolve.js' | |
); | |
// intercept fetch events. | |
this.addEventListener('fetch', (event) => { | |
// verify if requested resource is an import. |
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
<script type="module" src="path/to/es6/module.js"></script> | |
<!-- OR (only in Chrome 64) --> | |
<script> | |
const module = await import('path/to/es6/module.js'); | |
</script> |
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 draggable(element) { | |
let currentX = 0; | |
let currentY = 0; | |
element.addEventListener('touchstart', (startEvent) => { | |
const firstTouch = startEvent.touches[0]; | |
let deltaX, deltaY; | |
const onMove = (moveEvent) => { | |
// prevent the scrolling |
OlderNewer