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
// +++ https://blog.garstasio.com/you-dont-need-jquery/selectors/ | |
// http://youmightnotneedjquery.com/ | |
/// various access | |
self // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope | |
self.origin | |
self.isSecureContext | |
window | |
window.document |
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
/////// GET | |
fetch('/user/search?activeFilter=pending&max-results=11') | |
.then(response => { | |
const {ok, status} = response; | |
if (!ok || status !== 200) | |
throw new Error(); | |
return response.json(); | |
}) | |
.catch((e => { | |
console.log('parsing failed or whatever', e) |
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
// https://github.com/Offirmo/blog/blob/gh-pages/tosort/javascript-daily/mod-floating.md | |
const floating = require('floating.js) | |
floating({ | |
content: '<span style="color: snow">❄</span>', | |
number: 25, | |
direction: 'reverse', | |
size: [0.5, 2.5], | |
}) |
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://youmightnotneedjquery.com/ | |
// navigating | |
// This works in all browsers: | |
location.assign('...') | |
location.href = '...' | |
location = '...' | |
location.reload() | |
// If you wanted to change the page without it reflecting in the browser back history, you can do | |
location.replace('...') |
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
// new | |
return (...args) => { | |
try { | |
return handler.call(this, ...args); | |
} catch(e) { | |
return this.onError(e); | |
} | |
}; | |
// old school |
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
/////// fetch /////// | |
const originalFetch = window.fetch; | |
window.fetch = async (...args) => { | |
const fetchee = await originalFetch(...args); | |
return new Proxy(fetchee, {}); | |
}; | |
new Proxy(target, { |
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
// imports | |
import { Random, Engine } from '@offirmo/random' | |
import { | |
State as MetaState, | |
factory as meta_state_factory, | |
} from '@oh-my-rpg/state-meta' | |
// http://www.benmvp.com/learning-es6-enhanced-object-literals/ | |
return { |
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 global_module_instance; | |
Object.defineProperty(window, 'global_ng_module', { | |
enumerable: true, // why not ? | |
set: function() { | |
throw new Error('You can’t assign window.global_module !'); | |
}, | |
get: function() { | |
if(global_module_instance) return global_module_instance; // already OK | |
global_module_instance = angular.module('global_ng_module', [ | |
'ui.bootstrap' |
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
// debg | |
let DEBUG = false | |
try { // defensive! | |
DEBUG = DEBUG || !!window.localStorage.getItem(`${APP}.debug`) | |
} catch (e) { /* swallow */ } | |
if (DEBUG) console.info(`Hello from ${APP}`) | |
// prepare an url | |
// https://devdocs.io/javascript/global_objects/encodeuri |