Revert "Got rid of buggy yepnope spaghetti, however mobile detection really should be driven from the server."

This commit is contained in:
Neil Lalonde 2013-12-18 14:47:12 -05:00
parent c0e1ef75f6
commit 58e5d532c5
3 changed files with 31 additions and 26 deletions

View File

@ -115,12 +115,6 @@ module ApplicationHelper
[asset_path("#{target}.css"), customization_disabled? ? nil : SiteCustomization.custom_stylesheet_path(session[:preview_style], target)].compact
end
def stylesheet_links(target=:desktop)
stylesheet_filenames(target).map do |f|
"<link rel=\"stylesheet\" href=\"#{f}\" type=\"text/css\" media=\"screen\">"
end.join("\n")
end
def customization_disabled?
controller.class.name.split("::").first == "Admin" || session[:disable_customization]
end

View File

@ -2,16 +2,32 @@
<script type="text/javascript">
(function() {
var h = document.getElementsByTagName('html')[0];
window.isMobileView = (localStorage && localStorage.mobileView) ? (localStorage.mobileView === 'true') :
Modernizr.mq("only screen and (max-width: 480px), only screen and (max-device-width: 480px)");
var h = document.getElementsByTagName('html')[0],
isMobileView = (localStorage && localStorage.mobileView) ? (localStorage.mobileView === 'true') :
Modernizr.mq("only screen and (max-width: 480px), only screen and (max-device-width: 480px)");
h.className += (isMobileView ? ' mobile-view' : ' desktop-view');
if(isMobileView) {
document.write(<%= stylesheet_links(:mobile).inspect.html_safe %>);
} else {
document.write(<%= stylesheet_links(:desktop).inspect.html_safe %>);
}
Modernizr.load({
test: isMobileView,
yep: <%= stylesheet_filenames(:mobile).inspect.html_safe %>,
nope: <%= stylesheet_filenames(:desktop).inspect.html_safe %>,
complete: function() {
// CSS file(s) have loaded.
$(function() {
setTimeout(function() {
// Use setTimeout to make this happen in the next event loop.
// Trying to avoid a FOUC (flash of unstyled content).
if (isMobileView) {
$('#custom-mobile-header').show();
} else {
$('#custom-desktop-header').show();
}
$('#js-app').attr('style', ''); // Show everything.
$(window).trigger('scroll.discourse-dock'); // Calc header div positions now that they're visible.
}, 1);
});
}
});
})();
</script>

View File

@ -31,19 +31,14 @@
<body class="css-loading">
<!--[if IE 9]><script type="text/javascript">ie = "new";</script><![endif]-->
<div id="js-app">
<div id="js-app" style="display: none;">
<%- unless customization_disabled? %>
<script>
if(window.isMobile){
document.write("<div id='custom-mobile-header'>");
document.write(<%= SiteCustomization.custom_header(session[:preview_style], :mobile).inspect.gsub("<", '\x3c').html_safe %>);
document.write("</div>");
} else {
document.write("<div id='custom-desktop-header'>");
document.write(<%= SiteCustomization.custom_header(session[:preview_style], :desktop).inspect.gsub("<", '\x3c').html_safe %>);
document.write("</div>");
}
</script>
<div id='custom-desktop-header' style='display: none;'>
<%= SiteCustomization.custom_header(session[:preview_style], :desktop) %>
</div>
<div id='custom-mobile-header' style='display: none;'>
<%= SiteCustomization.custom_header(session[:preview_style], :mobile) %>
</div>
<%- end %>
<section id='main'>