diff --git a/README.md b/README.md index 540d9f5..c147db0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ These pieces of javascript were implemented by [Filament Group](https://github.c ## Installation ``` -gem 'loadcss-rails', '~> 0.2.0' +gem 'loadcss-rails', '~> 1.2.0' ``` The loadCSS and onloadCSS files will be added to the asset pipeline and available for you to use. Add the lines that you need to your application's JS manifest (usually `app/assets/javascripts/application.js`). diff --git a/lib/loadcss/rails/version.rb b/lib/loadcss/rails/version.rb index 1413a8b..74657ef 100644 --- a/lib/loadcss/rails/version.rb +++ b/lib/loadcss/rails/version.rb @@ -1,6 +1,6 @@ module LoadCSS module Rails - VERSION = '0.2.4' - LOADCSS_VERSION = '0.2.4' + VERSION = '1.2.0' + LOADCSS_VERSION = '1.2.0' end end diff --git a/vendor/assets/javascripts/loadCSS.js b/vendor/assets/javascripts/loadCSS.js index 52d4b1f..a601296 100644 --- a/vendor/assets/javascripts/loadCSS.js +++ b/vendor/assets/javascripts/loadCSS.js @@ -1,8 +1,4 @@ -/*! -loadCSS: load a CSS file asynchronously. -[c]2015 @scottjehl, Filament Group, Inc. -Licensed MIT -*/ +/*! loadCSS: load a CSS file asynchronously. [c]2016 @scottjehl, Filament Group, Inc. Licensed MIT */ (function(w){ "use strict"; /* exported loadCSS */ @@ -29,10 +25,21 @@ Licensed MIT // temporarily set media to something inapplicable to ensure it'll fetch without blocking render ss.media = "only x"; + // wait until body is defined before injecting link. This ensures a non-blocking load in IE11. + function ready( cb ){ + if( doc.body ){ + return cb(); + } + setTimeout(function(){ + ready( cb ); + }); + } // Inject link // Note: the ternary preserves the existing behavior of "before" argument, but we could choose to change the argument to "after" in a later release and standardize on ref.nextSibling for all refs // Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/ - ref.parentNode.insertBefore( ss, ( before ? ref : ref.nextSibling ) ); + ready( function(){ + ref.parentNode.insertBefore( ss, ( before ? ref : ref.nextSibling ) ); + }); // A method (exposed on return object for external use) that mimics onload by polling until document.styleSheets until it includes the new sheet. var onloadcssdefined = function( cb ){ var resolvedHref = ss.href; @@ -47,18 +54,26 @@ Licensed MIT }); }; + function loadCB(){ + if( ss.addEventListener ){ + ss.removeEventListener( "load", loadCB ); + } + ss.media = media || "all"; + } + // once loaded, set link's media back to `all` so that the stylesheet applies once it loads + if( ss.addEventListener ){ + ss.addEventListener( "load", loadCB); + } ss.onloadcssdefined = onloadcssdefined; - onloadcssdefined(function() { - ss.media = media || "all"; - }); + onloadcssdefined( loadCB ); return ss; }; // commonjs - if( typeof module !== "undefined" ){ - module.exports = loadCSS; + if( typeof exports !== "undefined" ){ + exports.loadCSS = loadCSS; } else { w.loadCSS = loadCSS; } -}( typeof global !== "undefined" ? global : this )); +}( typeof global !== "undefined" ? global : this )); \ No newline at end of file diff --git a/vendor/assets/javascripts/onloadCSS.js b/vendor/assets/javascripts/onloadCSS.js index c0e2194..15a2905 100644 --- a/vendor/assets/javascripts/onloadCSS.js +++ b/vendor/assets/javascripts/onloadCSS.js @@ -1,28 +1,29 @@ -/*! -onloadCSS: adds onload support for asynchronous stylesheets loaded with loadCSS. -[c]2014 @zachleat, Filament Group, Inc. -Licensed MIT -*/ - +/*! onloadCSS: adds onload support for asynchronous stylesheets loaded with loadCSS. [c]2016 @zachleat, Filament Group, Inc. Licensed MIT */ /* global navigator */ /* exported onloadCSS */ function onloadCSS( ss, callback ) { - ss.onload = function() { - ss.onload = null; - if( callback ) { - callback.call( ss ); - } - }; + var called; + function newcb(){ + if( !called && callback ){ + called = true; + callback.call( ss ); + } + } + if( ss.addEventListener ){ + ss.addEventListener( "load", newcb ); + } + if( ss.attachEvent ){ + ss.attachEvent( "onload", newcb ); + } - // This code is for browsers that don’t support onload, any browser that - // supports onload should use that instead. - // No support for onload: + // This code is for browsers that don’t support onload + // No support for onload (it'll bind but never fire): // * Android 4.3 (Samsung Galaxy S4, Browserstack) // * Android 4.2 Browser (Samsung Galaxy SIII Mini GT-I8200L) // * Android 2.3 (Pantech Burst P9070) // Weak inference targets Android < 4.4 if( "isApplicationInstalled" in navigator && "onloadcssdefined" in ss ) { - ss.onloadcssdefined( callback ); + ss.onloadcssdefined( newcb ); } } \ No newline at end of file