Created
November 25, 2015 13:00
-
-
Save radist2s/89dc649c9f41f69874cc to your computer and use it in GitHub Desktop.
CSS loading for mobile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function () { | |
function addHtmlClass(klass) { | |
document.documentElement.setAttribute('class', document.documentElement.getAttribute('class') || '' + ' ' + klass + ' ') | |
} | |
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera\s+Mini/i.test(navigator.userAgent)) { | |
window.fullVersionCookieTest = /nomobile\s*=\s*1(;\s*)?/ig | |
window.isFullVersion = fullVersionCookieTest.test(document.cookie) | |
if (!isFullVersion) { | |
window.isMobile = true | |
document.write("<link rel='stylesheet' " + | |
"href='static/css/style-mobile.css?ver=1' " + | |
"type='text/css' media='all' />") | |
addHtmlClass('mobile') | |
} | |
else { | |
var metaViewportEl = document.getElementById('viewportMeta') | |
metaViewportEl && metaViewportEl.parentElement.removeChild(metaViewportEl) | |
addHtmlClass('desktop') | |
} | |
} | |
else | |
{ | |
addHtmlClass('desktop') | |
} | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment