Skip to content

Instantly share code, notes, and snippets.

Looking for work

Barney Carroll barneycarroll

Looking for work
Block or report user

Report or block barneycarroll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
barneycarroll /
Last active Dec 23, 2019
Lock and unlock a page's scroll position.


Useful for when a blocking user experience is needed (in my case, didn't want people unwittingly loosing their place by scrolling while a modal required their attention): $.scrollLock() locks the body in place, preventing scroll until it is unlocked.

// Locks the page if it's currently unlocked

// ...or vice versa
barneycarroll / patdj.js
Last active Nov 8, 2019
DOM patching without: provide two DOM elements, the second (and contents) will be modified such that it resembles the first
View patdj.js
function patdj(target, update, preserve = true) {
if (update.nodeType != 1 && update.nodeType == target.nodeType)
target.nodeValue = update.nodeValue
else if (update.nodeType != target.nodeType || update.tagName !== target.tagName || update.type !== target.type){
const { nextSibling, parentNode } = target;
const replacement = preserve ? update.cloneNode(true) : update;
barneycarroll / fileInput.css
Last active Sep 1, 2019
Total input[type=file] style control with pure CSS. File type inputs are notoriously hard to style, due to different semi-serious style restrictions in the name of security (the argument being that a file input presents access to the user's private file system, and should as such always look unambiguously like what it is — redundant if you ask m…
View fileInput.css
.fileContainer {
overflow: hidden;
position: relative;
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
View NowThen.js
export default () => {
const queue = []
let then
return {
onbeforeupdate : () => !blocker,
oncreate : resolve,
onupdate : resolve,
view : ({
barneycarroll / .js
Last active Aug 2, 2019
Functor Mithril!
View .js
import m from './functor-mithril'
function Async(){
let cache
return ({content, setup, teardown}, dom) => {
if(content && !cache && teardown)
dom(node => {
void node.clientHeight
barneycarroll / modulator.js
Last active Aug 2, 2019
Modulator: a light-touch API (with heavy internals) for auto-instantiating Mithril modules. Makes Mithril lifecycle management more user-friendly.
View modulator.js
var mod = ( function initModulator(){
if( !Map ){
// A naive shim for maps functionality
var Map = shim;
var WeakMap = shim;
// Registry of instantiation contexts
var contexts = new WeakMap();
// All automated counts
View rasterizeHTML.allinone.js
/*! rasterizeHTML.js - v1.2.2 - 2016-09-06
* Copyright (c) 2016 Christoph Burgmer; Licensed MIT */
/* Integrated dependencies:
* url (MIT License),
* css-mediaquery (BSD License),
* CSSOM.js (MIT License),
* ayepromise (BSD License & WTFPL),
* xmlserializer (MIT License),
* sane-domparser-error (BSD License),
View Refresher.js
import {m} from './deps.js'
import viewOf from './viewOf.js'
// View component exposing a single function:
// Once invoked, the function causes the subtree to be reinitialised
export default () => {
let timestamp
const refresh = () => {
barneycarroll / jquery.lipo.js
Last active Mar 23, 2019
Get rid of redundant whitespace & empty structural elements, in that order
View jquery.lipo.js
void function semanticContentScope(context, jQuery){
var $ = context.jQuery || jQuery || false;
return false;
// Strips elements of duplicate, leading and trailing whitespace and removes empty non-functional elements recursively
function semanticContent(markup){
// Conversion
barneycarroll / tern.es5.js
Last active Feb 14, 2019
A ternary function for convenient conditional expressions (especially in Mithril views, where ternary operators can look confusing).
View tern.es5.js
// Verbose ternary function to add debugging points and make views more legible.
// If `defer` is true and the pass/fail outcome is a function, it will be invoked:
// This allows you to conditionally return expressions which would break execution depending on `condition`
function tern( condition, pass, fail, defer ){
if( !fail ) fail = ''
if( defer && condition instanceof Function ) condition = condition()
var outcome = condition ? pass : fail;
You can’t perform that action at this time.