rack-no_animations 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack/no_animations.rb +54 -56
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832687d48795c59f7569ca4520d8e64dafd799cf
|
4
|
+
data.tar.gz: 8d90bb6322ae7d3b82f616ca1afa499145e0a89c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee751ee83337170891f54ef23fa1ab546bc18b67bfef806806649521dff4f544df99d0ac1b8ce2303186bcfd900bc4c5d7f29ce9cea48155fab436bb1e2bdf5
|
7
|
+
data.tar.gz: b8bacb1c941e817316cd624a3adcb47d7bdc99a4f879bb43a33adca92cfe7c280519623e0bc59f5b5241d0c847e9ab097a31f23931bc7791d620522d8e2a4dd8
|
data/lib/rack/no_animations.rb
CHANGED
@@ -1,80 +1,78 @@
|
|
1
1
|
module Rack
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
CONTENT_LENGTH = 'Content-Length'.freeze
|
2
|
+
class NoAnimations
|
3
|
+
TEXT_HTML = %r{text/html}.freeze
|
4
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
6
5
|
|
7
|
-
|
6
|
+
DISABLE_ANIMATIONS_SNIPPET = <<-EOF
|
8
7
|
<scrip>if (typeof jQuery !== 'undefined') { jQuery.fx.off = true }</script>
|
9
8
|
<style>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
* {
|
10
|
+
-o-transition: none !important;
|
11
|
+
-moz-transition: none !important;
|
12
|
+
-ms-transition: none !important;
|
13
|
+
-webkit-transition: none !important;
|
14
|
+
transition: none !important;
|
15
|
+
-o-transform: none !important;
|
16
|
+
-moz-transform: none !important;
|
17
|
+
-ms-transform: none !important;
|
18
|
+
-webkit-transform: none !important;
|
19
|
+
transform: none !important;
|
20
|
+
-webkit-animation: none !important;
|
21
|
+
-moz-animation: none !important;
|
22
|
+
-o-animation: none !important;
|
23
|
+
-ms-animation: none !important;
|
24
|
+
animation: none !important;
|
25
|
+
}
|
27
26
|
</style>
|
28
|
-
|
29
|
-
|
27
|
+
EOF
|
28
|
+
SNIPPET_LENGTH = DISABLE_ANIMATIONS_SNIPPET.length
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def initialize(app)
|
31
|
+
@app = app
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
def call(env)
|
35
|
+
status, headers, body = env = @app.call(env)
|
37
36
|
|
38
|
-
|
37
|
+
return env unless is_html?(headers)
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
response(status, headers, body)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
42
|
+
protected
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
def response(status, headers, body)
|
45
|
+
changed, body = disable_animations(body)
|
47
46
|
|
48
|
-
|
47
|
+
update_length(headers) if changed
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
[status, headers, body]
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def is_html?(headers)
|
53
|
+
headers['Content-Type'.freeze] =~ TEXT_HTML
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def update_length(headers)
|
57
|
+
content_length = headers[CONTENT_LENGTH]
|
58
|
+
length = content_length.to_i
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
end
|
60
|
+
if length.to_s == content_length
|
61
|
+
headers[CONTENT_LENGTH] = (length + SNIPPET_LENGTH).to_s
|
64
62
|
end
|
63
|
+
end
|
65
64
|
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
if (body_index = body.rindex('</body>'.freeze))
|
73
|
-
body.insert(body_index - 7, DISABLE_ANIMATIONS_SNIPPET)
|
74
|
-
end
|
66
|
+
def disable_animations(response, body = '')
|
67
|
+
response.each do |s|
|
68
|
+
body << s.to_s# read the whole body
|
69
|
+
end
|
75
70
|
|
76
|
-
|
71
|
+
if (body_index = body.rindex('</body>'.freeze))
|
72
|
+
body.insert(body_index - 7, DISABLE_ANIMATIONS_SNIPPET)
|
77
73
|
end
|
74
|
+
|
75
|
+
[ body_index, [ body ] ]
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|