2014-01-08 22:08:42 -05:00
|
|
|
module MobileDetection
|
|
|
|
def self.mobile_device?(user_agent)
|
2016-03-15 20:12:05 -04:00
|
|
|
user_agent =~ /Mobile|Android|webOS/ && !(user_agent =~ /iPad|Nexus (9|10)/)
|
2014-01-08 22:08:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# we need this as a reusable chunk that is called from the cache
|
|
|
|
def self.resolve_mobile_view!(user_agent, params, session)
|
|
|
|
return false unless SiteSetting.enable_mobile_theme
|
|
|
|
|
2014-01-16 21:07:17 -05:00
|
|
|
session[:mobile_view] = params[:mobile_view] if params && params.has_key?(:mobile_view)
|
2014-01-08 22:08:42 -05:00
|
|
|
|
2014-01-16 23:04:38 -05:00
|
|
|
if session && session[:mobile_view]
|
2014-01-08 22:08:42 -05:00
|
|
|
session[:mobile_view] == '1'
|
|
|
|
else
|
|
|
|
mobile_device?(user_agent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|