-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
191 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Capybara | ||
class Server | ||
class AnimationDisabler | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
@status, @headers, @body = @app.call(env) | ||
return [@status, @headers, @body] unless html_content? | ||
response = Rack::Response.new([], @status, @headers) | ||
|
||
@body.each { |html| response.write insert_disable(html) } | ||
@body.close if @body.respond_to?(:close) | ||
|
||
response.finish | ||
end | ||
|
||
private | ||
|
||
def html_content? | ||
!!(@headers["Content-Type"] =~ /html/) | ||
end | ||
|
||
def insert_disable(html) | ||
html.sub(%r{(</head>)}, DISABLE_MARKUP + '\\1') | ||
end | ||
|
||
DISABLE_MARKUP = <<~HTML | ||
<script defer>(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);</script> | ||
<style> | ||
* { | ||
transition: none !important; | ||
animation-duration: 0s !important; | ||
animation-delay: 0s !important; | ||
} | ||
</style> | ||
HTML | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Capybara | ||
class Server | ||
class Middleware | ||
class Counter | ||
attr_reader :value | ||
|
||
def initialize | ||
@value = 0 | ||
@mutex = Mutex.new | ||
end | ||
|
||
def increment | ||
@mutex.synchronize { @value += 1 } | ||
end | ||
|
||
def decrement | ||
@mutex.synchronize { @value -= 1 } | ||
end | ||
end | ||
|
||
attr_accessor :error | ||
|
||
def initialize(app, server_errors, extra_middleware = []) | ||
@app = app | ||
@extended_app = extra_middleware.inject(@app) do |ex_app, klass| | ||
klass.new(ex_app) | ||
end | ||
@counter = Counter.new | ||
@server_errors = server_errors | ||
end | ||
|
||
def pending_requests? | ||
@counter.value.positive? | ||
end | ||
|
||
def call(env) | ||
if env["PATH_INFO"] == "/__identify__" | ||
[200, {}, [@app.object_id.to_s]] | ||
else | ||
@counter.increment | ||
begin | ||
@extended_app.call(env) | ||
rescue *@server_errors => e | ||
@error ||= e | ||
raise e | ||
ensure | ||
@counter.decrement | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | ||
<title>with_animation</title> | ||
<script src="/jquery.js" type="text/javascript" charset="utf-8"></script> | ||
<script src="/jquery-ui.js" type="text/javascript" charset="utf-8"></script> | ||
<script src="/test.js" type="text/javascript" charset="utf-8"></script> | ||
<style> | ||
.transition.away { | ||
width: 0%; | ||
} | ||
|
||
a { | ||
display: inline-block; | ||
width: 100%; | ||
overflow: hidden; | ||
} | ||
|
||
a:not(.away) { | ||
height: 20px; | ||
} | ||
|
||
a.transition { | ||
transition: all 3s ease-in-out; | ||
} | ||
|
||
@keyframes animation { | ||
0% {height: 20px; width: 100%;} | ||
100% {height: 0px; width: 0%;} | ||
} | ||
|
||
a.animation.away { | ||
animation-name: animation; | ||
animation-duration: 3s; | ||
animation-fill-mode: forwards; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body id="with_animation"> | ||
<a href='#' class='transition' onclick='this.classList.add("away")'>transition me away</a> | ||
<a href='#' class='animation' onclick='this.classList.add("away")'>animate me away</a> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters