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
desandro / transition-scroll-to.js
Created Dec 4, 2012
Use CSS transitions to scroll to element
View transition-scroll-to.js
( function( window, undefined ) {
'use strict';
// helper function
function capitalize( str ) {
return str.charAt(0).toUpperCase() + str.slice(1);
// ========================= getStyleProperty by kangax ===============================
barneycarroll /
Last active Dec 19, 2015
NB: This code has all sorts of edge cases, and any code that attempts to leverage it on a holistic framework level is likely to run into bugs fast. Do not use. Creates a custom `target` event, matching the CSS `:target` pseudo-selector, which can be used to determine when an element in the page becomes the current target of the URI's fragment id…
/* Provides a jQuery 'target' event that fires in all conditions that would
* result in an element becoming the target of the URI fragment identifier or
* hash as it is often called. It aims to provide a behavioural hook to emulate
* CSS3's :target selector [1] (more here [2] and here [3]: good demos include
* this proof of concept [4] and Wikipedia's styling of targeted footnotes and
* citations [5]).
* [1]
* [2]
* [3]
gilbert / widget.js
Created Mar 25, 2015
Mithril + JSS
View widget.js
Widget = {
controller: function () {
this.css = Widget.stylesheet().classes
view: function (ctrl) {
return m('.widget', [
m('h3', { class: ctrl.css.head }),
m('div', { class: ctrl.css.body })
barneycarroll / multi.js
Last active Mar 23, 2016
Execute multiple functions where one is expected. Useful for event handling.
View multi.js
function multi(){
var handlers = arguments, function( x ){
return x instanceof Function
} )
return function handle(){
for( var i = 0; i < handlers.length; i++ )
handlers[ i ].apply( this, arguments )
barneycarroll / grid.js
Created Nov 13, 2014
A grid vm for Mithril
View grid.js
'use strict';
function grid( axis ){
var items = [];
var pending;
var container;
function queue(){
if( pending ) ( window.cancelAnimationFrame || window.clearTimeout )( pending );
gilbert / example-use.js
Last active Aug 18, 2016
Back-button & forward-button compatible Redux-like state management for Mithril.js
View example-use.js
var BlogComments = {}
BlogComments.controller = function (options) {
App.state.fetch('blogComments', `/api/blog-post/${ options.blog_id }/comments`)
BlogComments.view = function (ctrl, options) {
var comments = App.state.blogComments
return m('.blog-comments-component', [
View mithril.utils.js
// Mithril utilities
// Multi allows you to execute multiple functions as one.
// Especially useful when you want to bind several event handlers
// or run several config functions, for example binding a DOM plugin
// & assigning routing to a link.
// m( 'a.select2', {
// config : multi( m.route, select2plugin )
// }, [] );
barneycarroll / modulator.js
Last active Dec 14, 2016
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
barneycarroll / animator.js
Last active Mar 9, 2017
A factory for decorating Mithril modules / views / elements with incoming and outgoing animations.
View animator.js
var animating = false;
// Define an animator consisting of optional incoming and outgoing animations.
// alwaysAnimate is false unless specified as true: false means an incoming animation will only trigger if an outgoing animation is also in progress.
// forcing dontClone to true means the outward animation will use the original element rather than a clone. This could improve performance by recycling elements, but can lead to trouble: clones have the advantage of being stripped of all event listeners.
function animator( incoming, outgoing, alwaysAnimate, dontClone ){
// The resulting animator can be applied to any number of components
return function animate( x, y, z ){
var config;
var parent;
cowboy / isprimitive-no-strict.js
Created Sep 18, 2012
JavaScript: isPrimitive
View isprimitive-no-strict.js
var isPrimitive = function(val) {
return val !== function() { return this; }.call(val);
You can’t perform that action at this time.