Sha256: 37cb7ff64501578d4444c12ba3eb144a824087c8c7bcce240efffb90c8ccb77b

Contents?: true

Size: 1.55 KB

Versions: 21

Compression:

Stored size: 1.55 KB

Contents

#
# disable CSS3 and jQuery animations in test mode for speed, consistency and avoiding timing issues.
# HT: https://gist.github.com/keithtom/8763169
class DisableAnimationsInTestEnvironment
  def initialize(app, _options = {})
    @app = app
  end

  def call(env)
    @status, @headers, @body = @app.call(env)
    return [@status, @headers, @body] unless html?
    response = Rack::Response.new([], @status, @headers)

    @body.each { |fragment| response.write inject(fragment) }
    @body.close if @body.respond_to?(:close)

    response.finish
  end

  private

    def html?
      @headers["Content-Type"] =~ /html/
    end

    # rubocop:disable Metrics/MethodLength Layout/IndentHeredoc
    def inject(fragment)
      disable_animations = <<-EOF
<script type="text/javascript">(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);</script>
<style>
  * {
     -o-transition: none !important;
     -moz-transition: none !important;
     -ms-transition: none !important;
     -webkit-transition: none !important;
     transition: none !important;
     -o-transform: none !important;
     -moz-transform: none !important;
     -ms-transform: none !important;
     -webkit-transform: none !important;
     transform: none !important;
     -webkit-animation: none !important;
     -moz-animation: none !important;
     -o-animation: none !important;
     -ms-animation: none !important;
     animation: none !important;
  }
</style>
      EOF
      fragment.gsub(%r{</head>}, disable_animations + "</head>")
    end
  # rubocop:enable Metrics/MethodLength Layout/IndentHeredoc
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-5.0.0.rc1 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.6.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0.rc3 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0.rc2 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0.rc1 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.5.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0.beta2 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.4.2 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-4.0.0.beta1 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.4.1 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.4.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.3.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.2.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.1.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.0.2 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.0.1 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.0.0 lib/hyrax/specs/disable_animations_in_test_environment.rb
hyrax-3.0.0.pre.rc4 lib/hyrax/specs/disable_animations_in_test_environment.rb