diff --git a/app/assets/javascripts/discourse/lib/mobile.js b/app/assets/javascripts/discourse/lib/mobile.js index c1b904970..8a0876bf9 100644 --- a/app/assets/javascripts/discourse/lib/mobile.js +++ b/app/assets/javascripts/discourse/lib/mobile.js @@ -5,30 +5,19 @@ @module Mobile **/ Discourse.Mobile = { - isMobileDevice: false, + mobileView: false, init: function() { var $html = $('html'); - this.isMobileDevice = $html.hasClass('mobile-device'); this.mobileView = $html.hasClass('mobile-view'); - - if (localStorage && localStorage.mobileView) { - var savedValue = (localStorage.mobileView === 'true' ? true : false); - if (savedValue !== this.mobileView) { - this.reloadPage(savedValue); - } - } }, toggleMobileView: function() { if (localStorage) { localStorage.mobileView = !this.mobileView; } - this.reloadPage(!this.mobileView); - }, - - reloadPage: function(mobile) { - window.location.assign(window.location.pathname + '?mobile_view=' + (mobile ? '1' : '0')); + window.location.reload(); } + }; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 10eda59b3..3702835e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -26,7 +26,6 @@ class ApplicationController < ActionController::Base end before_filter :set_locale - before_filter :set_mobile_view before_filter :inject_preview_style before_filter :disable_customization before_filter :block_if_maintenance_mode @@ -120,10 +119,6 @@ class ApplicationController < ActionController::Base end end - def set_mobile_view - session[:mobile_view] = params[:mobile_view] if params.has_key?(:mobile_view) - end - def inject_preview_style style = request['preview-style'] session[:preview_style] = style if style diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3ad0ece5e..b4309482a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,10 +19,6 @@ module ApplicationHelper end end - def html_classes - "#{mobile_view? ? 'mobile-view' : 'desktop-view'} #{mobile_device? ? 'mobile-device' : 'not-mobile-device'}" - end - def escape_unicode(javascript) if javascript javascript = javascript.dup.force_encoding("utf-8") @@ -115,18 +111,8 @@ module ApplicationHelper "#{Discourse::base_uri}/login" end - def mobile_view? - return false unless SiteSetting.enable_mobile_theme - if session[:mobile_view] - session[:mobile_view] == '1' - else - mobile_device? - end - end - - def mobile_device? - # TODO: this is dumb. user agent matching is a doomed approach. a better solution is coming. - request.user_agent =~ /Mobile|webOS|Nexus 7/ and !(request.user_agent =~ /iPad/) + def stylesheet_filenames(target=:desktop) + [asset_path("#{target}.css"), customization_disabled? ? nil : SiteCustomization.custom_stylesheet_path(session[:preview_style], target)].compact end def customization_disabled? diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb index f46ea5e59..6f3ad6eb0 100644 --- a/app/models/site_customization.rb +++ b/app/models/site_customization.rb @@ -83,6 +83,12 @@ 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) + style.stylesheet_relative_path(target) if style + end + def self.custom_header(preview_style, target=:desktop) preview_style ||= enabled_style_key style = lookup_style(preview_style) @@ -175,14 +181,18 @@ class SiteCustomization < ActiveRecord::Base return "" unless stylesheet.present? return @stylesheet_link_tag if @stylesheet_link_tag ensure_stylesheets_on_disk! - @stylesheet_link_tag = "" + @stylesheet_link_tag = "" 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 = "" + @mobile_stylesheet_link_tag = "" + end + + def stylesheet_relative_path(target=:desktop) + "/#{CACHE_PATH}#{stylesheet_filename(target)}?#{stylesheet_hash(target)}" end end diff --git a/app/views/common/_discourse_stylesheet.html.erb b/app/views/common/_discourse_stylesheet.html.erb index 41bff2413..afdab8627 100644 --- a/app/views/common/_discourse_stylesheet.html.erb +++ b/app/views/common/_discourse_stylesheet.html.erb @@ -1,15 +1,42 @@ <%- unless SiteCustomization.override_default_style(session[:preview_style]) %> - <% if mobile_view? %> - <%= stylesheet_link_tag "mobile" %> - <% else %> - <%= stylesheet_link_tag "desktop" %> - <% end %> + + + <%- end %> + + <%- if staff? %> <%= stylesheet_link_tag "admin"%> <%-end%> - -<%- unless customization_disabled? %> - <%= SiteCustomization.custom_stylesheet(session[:preview_style], mobile_view? ? :mobile : :desktop) %> -<%- end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a60e8cb68..a8a0d0354 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,5 +1,5 @@ - + <%= content_for?(:title) ? yield(:title) + ' - ' + SiteSetting.title : SiteSetting.title %> @@ -20,48 +20,55 @@ <%= javascript_include_tag "admin"%> <%- end %> - <%= render :partial => "common/special_font_face" %> <%= render :partial => "common/discourse_stylesheet" %> + <%= render :partial => "common/special_font_face" %> <%= discourse_csrf_tags %> <%= yield :head %> - + - <%- unless customization_disabled? %> - <%= SiteCustomization.custom_header(session[:preview_style], mobile_view? ? :mobile : :desktop) %> - <%- end %> +