Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
4 changes: 2 additions & 2 deletions lib/loadcss/rails/version.rb
Original file line number Diff line number Diff line change
@@ -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
39 changes: 27 additions & 12 deletions vendor/assets/javascripts/loadCSS.js
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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;
Expand All @@ -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 ));
33 changes: 17 additions & 16 deletions vendor/assets/javascripts/onloadCSS.js
Original file line number Diff line number Diff line change
@@ -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 );
}
}