Re-apply with fixes: Stop using user agent to detect mobile devices. Use a media query and yepnope to load the appropriate css and customizations.

This commit is contained in:
Neil Lalonde
2013-12-11 11:17:55 -05:00
parent ed3d3ae1e1
commit 5171a23a9c
9 changed files with 118 additions and 148 deletions

View File

@ -83,6 +83,16 @@ class SiteCustomization < ActiveRecord::Base
style.stylesheet_link_tag(target).html_safe if style
end
def self.custom_stylesheet_path(preview_style, target=:desktop)
preview_style ||= enabled_style_key
style = lookup_style(preview_style)
if style && ((target != :mobile && style.stylesheet) || (target == :mobile && style.mobile_stylesheet))
style.stylesheet_relative_path(target)
else
nil
end
end
def self.custom_header(preview_style, target=:desktop)
preview_style ||= enabled_style_key
style = lookup_style(preview_style)
@ -175,14 +185,18 @@ class SiteCustomization < ActiveRecord::Base
return "" unless stylesheet.present?
return @stylesheet_link_tag if @stylesheet_link_tag
ensure_stylesheets_on_disk!
@stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"/#{CACHE_PATH}#{stylesheet_filename}?#{stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
@stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"#{stylesheet_relative_path(:desktop)}\" type=\"text/css\" media=\"screen\">"
end
def mobile_stylesheet_link_tag
return "" unless mobile_stylesheet.present?
return @mobile_stylesheet_link_tag if @mobile_stylesheet_link_tag
ensure_stylesheets_on_disk!
@mobile_stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"/#{CACHE_PATH}#{stylesheet_filename(:mobile)}?#{stylesheet_hash(:mobile)}\" type=\"text/css\" media=\"screen\">"
@mobile_stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"#{stylesheet_relative_path(:mobile)}\" type=\"text/css\" media=\"screen\">"
end
def stylesheet_relative_path(target=:desktop)
"/#{CACHE_PATH}#{stylesheet_filename(target)}?#{stylesheet_hash(target)}"
end
end