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 / $.hasLayout.js
Created Sep 30, 2011
Force hasLayout toggle
View $.hasLayout.js
// 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 Oct 11, 2011
Keep a given aspect ratio for any content
View aspect.htm
<style>
.aspectWrapper {
position: relative;
}
.aspectImg {
display: block;
height: auto;
position: relative;
width: 100%;
@barneycarroll
barneycarroll / jquery.scope.js
Created Nov 21, 2011
Create a quick reference to a $ context, useful for concise and readable $('thing').find() shortcuts
View jquery.scope.js
/*
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 Dec 15, 2011
Wait for all elements with external resources (imgs, iframes) in current $ scope to have loaded before firing passed function
View jquery.loadAll.js
/*
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 Jan 19, 2012
Force hardware acceleration on dynamically styled elements for Webkit mobile.
View webkitMobileGPU-CSS.css
@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 Mar 7, 2012
Make editing/extending jQuery.data objects slightly less verbose
View jquery.dataExtend.js
/*
$(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 Oct 1, 2015
Get rid of Sizzle's IE custom attributes
View fizzleSizzle.js
/*
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 Apr 20, 2012
Stop breakage on environments without console.log
View console.log.js
if(!window.console) console = {log:function(){}};
@barneycarroll
barneycarroll / browse.js
Created Aug 7, 2012
Browser feature inference
View browse.js
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 Oct 11, 2015
OOCSS grids without classitis for IE9 and above
View grids.reduced.css
.line,
.line > :nth-child(n+2):last-child{
overflow: hidden;
}
.line > *{
float:left;
}
.line > :nth-child(1):nth-last-child(2){
width:50%;
}
You can’t perform that action at this time.