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
barneycarroll / README.md
Last active Oct 17, 2019
Lock and unlock a page's scroll position.
View README.md

jquery.scrollLock.js

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
$.scrollLock();

// ...or vice versa
@barneycarroll
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 : ({
instance,
@barneycarroll
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
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
* http://www.github.com/cburgmer/rasterizeHTML.js
* 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
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;
if(!$){
return false;
}
// Strips elements of duplicate, leading and trailing whitespace and removes empty non-functional elements recursively
function semanticContent(markup){
// Conversion
@barneycarroll
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;
@barneycarroll
barneycarroll / unfuckReact.js
Last active Feb 7, 2019
React components are so fucking stupid, it's unbelievable. 3 months with this library version 15 and the glaring stupidity of the API just keeps coming in waves. Fixing some of this stuff – just for the sake of internal consistency – would have been so simple. The number of hoops you're required to jump through for trivial shit. Ugh.
View unfuckReact.js
const mounted = new WeakSet()
export default const unfucker = (component, displayName = component.displayName || component.name || 'React.Component') => {
const host = {
[displayName] : class extends React.Component {
constructor(){
this.state = {}
component.apply(this, arguments)
}
You can’t perform that action at this time.