Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
@barneycarroll
barneycarroll / $.hasLayout.js
Created September 30, 2011 10:29
Force hasLayout toggle
// Force hasLayout: wait til after page load, toggle zoom moments later
$.fn.hasLayout = function(){
var
$el = $(this),
zoom = function(){
$el.css('zoom','0').css('zoom','1');
},
delay = function(x){
setTimeout(x,100);
};
@barneycarroll
barneycarroll / aspect.htm
Created October 11, 2011 15:49
Keep a given aspect ratio for any content
<style>
.aspectWrapper {
position: relative;
}
.aspectImg {
display: block;
height: auto;
position: relative;
width: 100%;
@barneycarroll
barneycarroll / jquery.scope.js
Created November 21, 2011 11:37
Create a quick reference to a $ context, useful for concise and readable $('thing').find() shortcuts
/*
Return $ function limited to current context.
e.g
if:
var $widget = $('widget').scope()
then:
$widget() == $('widget')
$widget('a') == $('widget').find('a')
@barneycarroll
barneycarroll / jquery.loadAll.js
Created December 15, 2011 14:07
Wait for all elements with external resources (imgs, iframes) in current $ scope to have loaded before firing passed function
/*
Wait for all elements with external resources (imgs, iframes)
in current $ scope to have loaded before firing passed event.
e.g.
$('.plugin img').loadAll(function(){...})
For a version of $().load that forces a reload (if load has already
fired before event binding), use
@barneycarroll
barneycarroll / webkitMobileGPU-CSS.css
Created January 19, 2012 14:42
Force hardware acceleration on dynamically styled elements for Webkit mobile.
@media(-webkit-min-device-pixel-ratio:1.1){
/* Media query restricts to mobile: avoid Chrome purple scroll bars */
[style] {
-webkit-transform: translateZ(0);
}
}
@barneycarroll
barneycarroll / jquery.dataExtend.js
Created March 7, 2012 18:11
Make editing/extending jQuery.data objects slightly less verbose
/*
$(el).data() is fine if you're using it for simple key/value pairs, but if there's any depth (objects), adding to or modifying said objects becomes a verbose pain in the ass.
This extension method uses $.extend() to add or modify any object with the given key:
$(el).data('plugin',$.extend($(el).data('plugin'),{state:1}))
...becomes:
$(el).dataExtend('plugin',{state:1})
@barneycarroll
barneycarroll / fizzleSizzle.js
Last active October 1, 2015 12:48
Get rid of Sizzle's IE custom attributes
/*
In IE, Sizzle has to create custom attributes to be able to travel the DOM intelligently. The custom attributes are lengthy and nasty, and can often screw up your code if you rely on parsing markup. fizzleSizzle wipes all that stuff out.
*/
// Pass in a string of markup and get it back without Sizzle's shizzle
var fizzleShizzle = function(x){
return x.replace(/(nodeIndex|sizcache|sizset)[\w\d]*(="[^"]*")*/gi,'');
};
(function($){
@barneycarroll
barneycarroll / console.log.js
Created April 20, 2012 08:47
Stop breakage on environments without console.log
if(!window.console) console = {log:function(){}};
@barneycarroll
barneycarroll / browse.js
Created August 7, 2012 13:05
Browser feature inference
browser = {
ieVersion: function () {
var undef;
var v = 3;
var div = document.createElement('div');
var all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]);
return v > 4 ? v : undef;
},
@barneycarroll
barneycarroll / grids.reduced.css
Last active October 11, 2015 01:28
OOCSS grids without classitis for IE9 and above
.line,
.line > :nth-child(n+2):last-child{
overflow: hidden;
}
.line > *{
float:left;
}
.line > :nth-child(1):nth-last-child(2){
width:50%;
}