Sha256: cb91a645d494584f5abb9d2e2299db10c51a2dd40541ff3d4ce743130540106a

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

class Browser
  module IE
    TRIDENT_VERSION_REGEX = %r[Trident/([0-9.]+)]
    MODERN_IE = %r[Trident/.*?; rv:(.*?)]

    # Detect if browser is Internet Explorer.
    def ie?
      msie? || modern_ie?
    end

    # Detect if browser is Internet Explorer 6.
    def ie6?
      ie? && version == "6"
    end

    # Detect if browser is Internet Explorer 7.
    def ie7?
      ie? && version == "7"
    end

    # Detect if browser is Internet Explorer 8.
    def ie8?
      ie? && version == "8"
    end

    # Detect if browser is Internet Explorer 9.
    def ie9?
      ie? && version == "9"
    end

    # Detect if browser is Internet Explorer 10.
    def ie10?
      ie? && version == "10"
    end

    # Detect if browser is Internet Explorer 11.
    def ie11?
      ie? && version == "11"
    end

    # Detect if IE is running in compatibility mode.
    def compatibility_view?
      match = ua.match(TRIDENT_VERSION_REGEX)
      ie? && match && version.to_i < (match[1].to_i + 4)
    end

    private

    def msie?
      !!(ua =~ /MSIE/ && ua !~ /Opera/)
    end

    def modern_ie?
      !!(ua =~ MODERN_IE)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
browser-0.9.1 lib/browser/methods/ie.rb
browser-0.9.0 lib/browser/methods/ie.rb
browser-0.8.0 lib/browser/methods/ie.rb
browser-0.7.2 lib/browser/methods/ie.rb
browser-0.7.1 lib/browser/methods/ie.rb
browser-0.7.0 lib/browser/methods/ie.rb
browser-0.6.0 lib/browser/methods/ie.rb
browser-0.5.0 lib/browser/methods/ie.rb