loadcss-rails 1.3.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/loadcss/rails/version.rb +2 -2
- data/vendor/assets/javascripts/cssrelpreload.js +75 -15
- data/vendor/assets/javascripts/loadCSS.js +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 890354a3f2b5255309167fb1af8d6cf9464a3960
|
4
|
+
data.tar.gz: 9f0a70e4338132012b5739592a03293fa1ab0c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df83184ba0faa40dc2e2ed8fe17a8c7f2ebe9036131b14d8a735af223e9e158e13a38cba9f1d741c1631f92cf5094c848932cbd9d64fd18ebc50bd35574380d
|
7
|
+
data.tar.gz: 2b531bcfd39bbe53ff4bf4530629c27e0aa3a3ab3fcef052ae20ecccca5fdd2e5e0cd41b745193281c05bc343af719d3dfd7fcac88d8e0dcad72ff756397ac78
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ These pieces of javascript were implemented by [Filament Group](https://github.c
|
|
11
11
|
## Installation
|
12
12
|
|
13
13
|
```
|
14
|
-
gem 'loadcss-rails', '~>
|
14
|
+
gem 'loadcss-rails', '~> 2.0.1'
|
15
15
|
```
|
16
16
|
|
17
17
|
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`).
|
@@ -1,44 +1,104 @@
|
|
1
|
-
/*! loadCSS
|
1
|
+
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
|
2
|
+
/* This file is meant as a standalone workflow for
|
3
|
+
- testing support for link[rel=preload]
|
4
|
+
- enabling async CSS loading in browsers that do not support rel=preload
|
5
|
+
- applying rel preload css once loaded, whether supported or not.
|
6
|
+
*/
|
2
7
|
(function( w ){
|
8
|
+
"use strict";
|
3
9
|
// rel=preload support test
|
4
10
|
if( !w.loadCSS ){
|
5
|
-
|
11
|
+
w.loadCSS = function(){};
|
6
12
|
}
|
13
|
+
// define on the loadCSS obj
|
7
14
|
var rp = loadCSS.relpreload = {};
|
8
|
-
|
15
|
+
// rel=preload feature support test
|
16
|
+
// runs once and returns a function for compat purposes
|
17
|
+
rp.support = (function(){
|
18
|
+
var ret;
|
9
19
|
try {
|
10
|
-
|
20
|
+
ret = w.document.createElement( "link" ).relList.supports( "preload" );
|
11
21
|
} catch (e) {
|
12
|
-
|
22
|
+
ret = false;
|
13
23
|
}
|
24
|
+
return function(){
|
25
|
+
return ret;
|
26
|
+
};
|
27
|
+
})();
|
28
|
+
|
29
|
+
// if preload isn't supported, get an asynchronous load by using a non-matching media attribute
|
30
|
+
// then change that media back to its intended value on load
|
31
|
+
rp.bindMediaToggle = function( link ){
|
32
|
+
// remember existing media attr for ultimate state, or default to 'all'
|
33
|
+
var finalMedia = link.media || "all";
|
34
|
+
|
35
|
+
function enableStylesheet(){
|
36
|
+
link.media = finalMedia;
|
37
|
+
}
|
38
|
+
|
39
|
+
// bind load handlers to enable media
|
40
|
+
if( link.addEventListener ){
|
41
|
+
link.addEventListener( "load", enableStylesheet );
|
42
|
+
} else if( link.attachEvent ){
|
43
|
+
link.attachEvent( "onload", enableStylesheet );
|
44
|
+
}
|
45
|
+
|
46
|
+
// Set rel and non-applicable media type to start an async request
|
47
|
+
// note: timeout allows this to happen async to let rendering continue in IE
|
48
|
+
setTimeout(function(){
|
49
|
+
link.rel = "stylesheet";
|
50
|
+
link.media = "only x";
|
51
|
+
});
|
52
|
+
// also enable media after 3 seconds,
|
53
|
+
// which will catch very old browsers (android 2.x, old firefox) that don't support onload on link
|
54
|
+
setTimeout( enableStylesheet, 3000 );
|
14
55
|
};
|
15
56
|
|
16
|
-
// loop
|
57
|
+
// loop through link elements in DOM
|
17
58
|
rp.poly = function(){
|
59
|
+
// double check this to prevent external calls from running
|
60
|
+
if( rp.support() ){
|
61
|
+
return;
|
62
|
+
}
|
18
63
|
var links = w.document.getElementsByTagName( "link" );
|
19
64
|
for( var i = 0; i < links.length; i++ ){
|
20
65
|
var link = links[ i ];
|
21
|
-
|
22
|
-
|
23
|
-
|
66
|
+
// qualify links to those with rel=preload and as=style attrs
|
67
|
+
if( link.rel === "preload" && link.getAttribute( "as" ) === "style" && !link.getAttribute( "data-loadcss" ) ){
|
68
|
+
// prevent rerunning on link
|
69
|
+
link.setAttribute( "data-loadcss", true );
|
70
|
+
// bind listeners to toggle media back
|
71
|
+
rp.bindMediaToggle( link );
|
24
72
|
}
|
25
73
|
}
|
26
74
|
};
|
27
75
|
|
28
|
-
// if
|
76
|
+
// if unsupported, run the polyfill
|
29
77
|
if( !rp.support() ){
|
78
|
+
// run once at least
|
30
79
|
rp.poly();
|
31
|
-
|
80
|
+
|
81
|
+
// rerun poly on an interval until onload
|
82
|
+
var run = w.setInterval( rp.poly, 500 );
|
32
83
|
if( w.addEventListener ){
|
33
84
|
w.addEventListener( "load", function(){
|
34
85
|
rp.poly();
|
35
86
|
w.clearInterval( run );
|
36
87
|
} );
|
37
|
-
}
|
38
|
-
if( w.attachEvent ){
|
88
|
+
} else if( w.attachEvent ){
|
39
89
|
w.attachEvent( "onload", function(){
|
90
|
+
rp.poly();
|
40
91
|
w.clearInterval( run );
|
41
|
-
} )
|
92
|
+
} );
|
42
93
|
}
|
43
94
|
}
|
44
|
-
|
95
|
+
|
96
|
+
|
97
|
+
// commonjs
|
98
|
+
if( typeof exports !== "undefined" ){
|
99
|
+
exports.loadCSS = loadCSS;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
w.loadCSS = loadCSS;
|
103
|
+
}
|
104
|
+
}( typeof global !== "undefined" ? global : this ) );
|
@@ -6,7 +6,7 @@
|
|
6
6
|
// Arguments explained:
|
7
7
|
// `href` [REQUIRED] is the URL for your CSS file.
|
8
8
|
// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
|
9
|
-
|
9
|
+
// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
|
10
10
|
// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
|
11
11
|
var doc = w.document;
|
12
12
|
var ss = doc.createElement( "link" );
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loadcss-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Misshore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem provides LoadCSS and OnloadCSS for your Rails application.
|
14
14
|
email:
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.6.12
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Use LoadCSS and OnloadCSS with Rails
|