Sha256: 7ae5b708a7dea0e8d8828b8106e0779388bc8af32e67a8944e326e3554706966

Contents?: true

Size: 1.43 KB

Versions: 27

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

#
# Disables CSS3 and jQuery animations
#
class NoAnimations
  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

  def inject(fragment)
    disable_animations = <<~JS
      <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>
    JS

    fragment.gsub(%r{</head>}, disable_animations + "</head>")
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
decidim-dev-0.7.4 lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.7.3 lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.7.2 lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.7.1 lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.7.0 lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.8 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.8 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.7 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.7 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.6 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.6 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.5 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.5 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.4 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.4 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.3 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.3 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.2 lib/generators/decidim/templates/no_animations.rb
decidim-0.6.2 decidim-dev/lib/generators/decidim/templates/no_animations.rb
decidim-dev-0.6.1 lib/generators/decidim/templates/no_animations.rb