rack-no_animations 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/lib/rack/no_animations.rb +80 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2af60553d7c7d347d2d4d66aa3eddacb1b12da8d
|
4
|
+
data.tar.gz: 5309ef6a55cd81bf30bf29c161deb48d83fb86fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 148b23b3e89465485a925315bb2de3a663863caae6f3370bcd86bb2c572eaf700967fd9e0e89b82b61698837515eb18b6e0d7d8dbf89e3317e6fa1ae900e84c0
|
7
|
+
data.tar.gz: 43812713a328df524c3c72e66691940849dc00f81c45ea33f50fcd08b41f2c40445dee63fbfa56632e48c1df7e5482c7f68bf978cfa09939c21c761fd93c2e15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Michal Cichra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Rack
|
2
|
+
module NoAnimations
|
3
|
+
class NoAnimations
|
4
|
+
TEXT_HTML = %r{text/html}.freeze
|
5
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
6
|
+
|
7
|
+
DISABLE_ANIMATIONS_SNIPPET = <<-EOF
|
8
|
+
<scrip>if (typeof jQuery !== 'undefined') { jQuery.fx.off = true }</script>
|
9
|
+
<style>
|
10
|
+
* {
|
11
|
+
-o-transition: none !important;
|
12
|
+
-moz-transition: none !important;
|
13
|
+
-ms-transition: none !important;
|
14
|
+
-webkit-transition: none !important;
|
15
|
+
transition: none !important;
|
16
|
+
-o-transform: none !important;
|
17
|
+
-moz-transform: none !important;
|
18
|
+
-ms-transform: none !important;
|
19
|
+
-webkit-transform: none !important;
|
20
|
+
transform: none !important;
|
21
|
+
-webkit-animation: none !important;
|
22
|
+
-moz-animation: none !important;
|
23
|
+
-o-animation: none !important;
|
24
|
+
-ms-animation: none !important;
|
25
|
+
animation: none !important;
|
26
|
+
}
|
27
|
+
</style>
|
28
|
+
EOF
|
29
|
+
SNIPPET_LENGTH = DISABLE_ANIMATIONS_SNIPPET.length
|
30
|
+
|
31
|
+
def initialize(app)
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
status, headers, body = env = @app.call(env)
|
37
|
+
|
38
|
+
return env unless is_html?(headers)
|
39
|
+
|
40
|
+
response(status, headers, body)
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def response(status, headers, body)
|
46
|
+
changed, body = disable_animations(body)
|
47
|
+
|
48
|
+
update_length(headers) if changed
|
49
|
+
|
50
|
+
[status, headers, body]
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_html?(headers)
|
54
|
+
headers['Content-Type'.freeze] =~ TEXT_HTML
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_length(headers)
|
58
|
+
content_length = headers[CONTENT_LENGTH]
|
59
|
+
length = content_length.to_i
|
60
|
+
|
61
|
+
if length.to_s == content_length
|
62
|
+
headers[CONTENT_LENGTH] = (length + SNIPPET_LENGTH).to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def disable_animations(response, body = '')
|
68
|
+
response.each do |s|
|
69
|
+
body << s.to_s# read the whole body
|
70
|
+
end
|
71
|
+
|
72
|
+
if (body_index = body.rindex('</body>'.freeze))
|
73
|
+
body.insert(body_index - 7, DISABLE_ANIMATIONS_SNIPPET)
|
74
|
+
end
|
75
|
+
|
76
|
+
[ body_index, [ body ] ]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-no_animations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michal Cichra
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rack middleware to stop CSS/jQuery animations.
|
56
|
+
email:
|
57
|
+
- michal@o2h.cz
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- lib/rack/no_animations.rb
|
64
|
+
homepage: https://github.com/mikz/rack-no_animations
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.6
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Injects CSS and JavaScript snippet to stop CSS and jQuery animations.
|
88
|
+
test_files: []
|