Skip to content

Instantly share code, notes, and snippets.

@andyinabox
Created December 7, 2013 16:36
Show Gist options
  • Save andyinabox/7844975 to your computer and use it in GitHub Desktop.
Save andyinabox/7844975 to your computer and use it in GitHub Desktop.
Grunticon loader AMD module
define(function(){
function grunticon( css, foo ){
// expects a css array with 3 items representing CSS paths to datasvg, datapng, urlpng
if( !css || css.length !== 3 ){
return;
}
// Thanks Modernizr & Erik Dahlstrom
var w = window,
svg = !!w.document.createElementNS && !!w.document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect && !!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1") && !(window.opera && navigator.userAgent.indexOf('Chrome') === -1),
loadCSS = function( data ){
var link = w.document.createElement( "link" ),
ref = w.document.getElementsByTagName( "script" )[ 0 ];
link.rel = "stylesheet";
link.href = css[ data && svg ? 0 : data ? 1 : 2 ];
ref.parentNode.insertBefore( link, ref );
},
// Thanks Modernizr
img = new w.Image();
img.onerror = function(){
loadCSS( false );
};
img.onload = function(){
loadCSS( img.width === 1 && img.height === 1 );
};
img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
};
return grunticon;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment