Module: MobileDetection
- Defined in:
- lib/mobile_detection.rb
Constant Summary collapse
- MODERN_MOBILE_REGEX =
%r{ \(.*iPhone\ OS\ 1[5-9].*\)| \(.*iPad.*OS\ 1[5-9].*\)| Chrome\/8[89]| Chrome\/9[0-9]| Chrome\/1[0-9][0-9]| Firefox\/8[5-9]| Firefox\/9[0-9]| Firefox\/1[0-9][0-9] }x
- USER_AGENT_MAX_LENGTH =
400
Class Method Summary collapse
- .ios_device?(user_agent) ⇒ Boolean
- .mobile_device?(user_agent) ⇒ Boolean
- .modern_mobile_device?(user_agent) ⇒ Boolean
-
.resolve_mobile_view!(user_agent, params, session) ⇒ Object
we need this as a reusable chunk that is called from the cache.
Class Method Details
.ios_device?(user_agent) ⇒ Boolean
23 24 25 |
# File 'lib/mobile_detection.rb', line 23 def self.ios_device?(user_agent) user_agent =~ /iPad|iPhone|iPod/ end |
.mobile_device?(user_agent) ⇒ Boolean
4 5 6 |
# File 'lib/mobile_detection.rb', line 4 def self.mobile_device?(user_agent) user_agent =~ /Mobile/ && !(user_agent =~ /iPad/) end |
.modern_mobile_device?(user_agent) ⇒ Boolean
41 42 43 |
# File 'lib/mobile_detection.rb', line 41 def self.modern_mobile_device?(user_agent) user_agent[0...USER_AGENT_MAX_LENGTH].match?(MODERN_MOBILE_REGEX) end |
.resolve_mobile_view!(user_agent, params, session) ⇒ Object
we need this as a reusable chunk that is called from the cache
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mobile_detection.rb', line 9 def self.resolve_mobile_view!(user_agent, params, session) return false unless SiteSetting.enable_mobile_theme session[:mobile_view] = params[:mobile_view] if params && params.has_key?(:mobile_view) session[:mobile_view] = nil if params && params.has_key?(:mobile_view) && params[:mobile_view] == "auto" if session && session[:mobile_view] session[:mobile_view] == "1" else mobile_device?(user_agent) end end |