2014-01-09 11:08:42 +08:00
|
|
|
module MobileDetection
|
|
|
|
def self.mobile_device?(user_agent)
|
2016-03-26 17:02:23 +08:00
|
|
|
user_agent =~ /Mobile/ && !(user_agent =~ /iPad/)
|
2014-01-09 11:08:42 +08: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-17 10:07:17 +08:00
|
|
|
session[:mobile_view] = params[:mobile_view] if params && params.has_key?(:mobile_view)
|
2019-02-23 02:43:40 +08:00
|
|
|
session[:mobile_view] = nil if params && params.has_key?(:mobile_view) && params[:mobile_view] == 'auto'
|
2014-01-09 11:08:42 +08:00
|
|
|
|
2014-01-17 12:04:38 +08:00
|
|
|
if session && session[:mobile_view]
|
2014-01-09 11:08:42 +08:00
|
|
|
session[:mobile_view] == '1'
|
|
|
|
else
|
|
|
|
mobile_device?(user_agent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|