mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 20:53:42 +08:00
254f48e568
Previous to this change an optimisation stripped crawler content from all mobile browsers. This had a side effect that meant that when we dropped support for an old mobile platform we would stop rendering topic and topic list pages. The new implementation ensures we only perform the optimisation on modern mobile browsers.
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module MobileDetection
|
|
def self.mobile_device?(user_agent)
|
|
user_agent =~ /Mobile/ && !(user_agent =~ /iPad/)
|
|
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
|
|
|
|
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
|
|
|
|
def self.ios_device?(user_agent)
|
|
user_agent =~ /iPad|iPhone|iPod/
|
|
end
|
|
|
|
MODERN_MOBILE_REGEX = %r{
|
|
\(.*iPhone\ OS\ 1[3-9].*\)|
|
|
\(.*iPad.*OS\ 1[3-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
|
|
|
|
def self.modern_mobile_device?(user_agent)
|
|
user_agent.match?(MODERN_MOBILE_REGEX)
|
|
end
|
|
|
|
end
|