Skip to content

Instantly share code, notes, and snippets.

@samthor
samthor / dialog-focus-restore.js
Last active December 1, 2023 14:39
Restore focus after a HTML dialog is shown modally
/**
* Updates the passed dialog to retain focus and restore it when the dialog is closed. Won't
* upgrade a dialog more than once. Supports IE11+ and is a no-op otherwise.
* @param {!HTMLDialogElement} dialog to upgrade
*/
var registerFocusRestoreDialog = (function() {
if (!window.WeakMap || !window.MutationObserver) {
return function() {};
}
var registered = new WeakMap();
@phillipgreenii
phillipgreenii / README.md
Last active November 16, 2023 16:04
Running NPM Scripts through maven

I am in the process of introducing single page applications to where I work. For development, using node based build tools is much easier for the single page applications. However, the build process for our organization is based upon maven. Our solution started with the maven plugin frontend-maven-plugin. It worked great at first, but then we ran into a situation that I couldn't make work with it.

As stated before, at our organization, we have the older ecosystem which is maven and the newer ecosystem which is node. Our goal was to keep the hacking to a minimum. We did this by putting all of the hacks into a single super node based build file. This is what maven calls and the reason frontend-maven-plugin wasn't sufficient. The super node based build script calls all of the other build scripts by spawning npm run. Try as I might, I could not figure out how to make the spawn work. front-end-maven-plugin downloads npm

@nbubna
nbubna / textarea.autosize.js
Last active January 20, 2016 07:11
Vanilla JS textarea auto-size
(function(document) {
var flex = {
tagName: 'TEXTAREA',
attribute: 'autosize',
buffer: 20,
events: 'input propertychange change',
adjust: function(el, shrunk) {
var height = el.scrollHeight,
style = el.style;
var f = function() {
var v = speechSynthesis.getVoices().filter(function(v) { return v.name == 'Hysterical'; })[0],
s = ["ahahahaha", "stop it", "don't tickle me"],
t = new SpeechSynthesisUtterance(s[~~(Math.random()*s.length)]);
t.voice = v; speechSynthesis.speak(t);
};
Array.prototype.slice.call(document.querySelectorAll('a')).forEach(function(a) {
a.addEventListener('mouseover', f);
});
@whichlight
whichlight / art-demo-links.md
Last active August 29, 2015 14:02
materials for jsconf talk
@nbubna
nbubna / resolve.js
Last active December 24, 2015 02:49
Safely resolve string-form variable references.
(function(scope) {
var resolve = scope.resolve = function(reference, context) {
if (resolve.RE.test(reference)) {
return resolve.unsafe(reference, context);
}
};
resolve.RE = /^([\w\$]+)?((\.[\w\$]+)|\[(\d+|'(\\'|[^'])+'|"(\\"|[^"])+")\])*$/;
resolve.unsafe = function(reference, context) {
@yckart
yckart / LICENSE.txt
Last active November 21, 2019 16:18 — forked from 140bytes/LICENSE.txt
Domster | Syntactic sugar for DOM-traversing
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 Yannick Albert <http://yckart.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@nbubna
nbubna / diff.js
Last active June 21, 2021 18:50
Simple object diffing, outputs to console log
function diff(a, b) {
var diffs = {};
for (var k in a) {
if (!(k in b)) {
console.log('b is missing '+k, a[k]);
diffs[k] = "missing";
} else if (a[k] != b[k]) {
var av = a[k], bv = b[k];
try {
if (JSON.stringify(av) != JSON.stringify(bv)) {
@nbubna
nbubna / state.js
Created July 11, 2012 14:35
state.js - browser history and bookmarks for ajax apps
/**
* Copyright (c) 2012, ESHA Research
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* @version 0.4
* @requires jQuery
* @name state
* @author Nathan Bubna
@nbubna
nbubna / key.js
Created July 6, 2012 22:17
key.js
/**
* Copyright (c) 2012, ESHA Research
*
* @version 0.1
* @name key
* @requires jQuery
* @author Nathan Bubna
*/
;(function($, window, document) {