Commit 837fe40f authored by Nikolay Gromov's avatar Nikolay Gromov

Добавил блок для определения мобильных

parent 4f3b84c5
......@@ -15,7 +15,8 @@
"sprite-svg": [],
"sprite-png": [
"__demo"
]
],
"is-mobile": []
},
"addCssBefore": [
"./src/scss/variables.scss"
......@@ -26,7 +27,8 @@
"addJsBefore": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/jquery-migrate/dist/jquery-migrate.min.js",
"./node_modules/svg4everybody/dist/svg4everybody.js"
"./node_modules/svg4everybody/dist/svg4everybody.js",
"./node_modules/ismobilejs/isMobile.min.js"
],
"addJsAfter": [
"./src/js/global-script.js"
......@@ -79,6 +81,7 @@
"gulp-uglify": "^2.1.0",
"gulp.spritesmith": "^6.3.0",
"imagemin-pngquant": "^5.0.0",
"ismobilejs": "^0.4.0",
"jquery": "^3.1.1",
"jquery-migrate": "^3.0.0",
"merge-stream": "^1.0.1",
......
......@@ -8,6 +8,7 @@
<script>
// Маркер работающего javascript
document.documentElement.className = document.documentElement.className.replace('no-js', 'js');
@@include('../blocks/is-mobile/is-mobile--to-head.js')
</script>
<!--DEV Такой комментарий не попадет в собранный HTML
......@@ -25,16 +26,3 @@
<meta name="msapplication-TileColor" content="#2b2f38">
<meta name="msapplication-TileImage" content="img/favicons/mstile-144x144.png">
-->
<!--DEV Детектор мобильных устройств — https://github.com/kaimallea/isMobile
<script>
// Minified version of isMobile included in the HTML since it's small
!function(a){var b=/iPhone/i,c=/iPod/i,d=/iPad/i,e=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,f=/Android/i,g=/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,h=/(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,i=/IEMobile/i,j=/(?=.*\bWindows\b)(?=.*\bARM\b)/i,k=/BlackBerry/i,l=/BB10/i,m=/Opera Mini/i,n=/(CriOS|Chrome)(?=.*\bMobile\b)/i,o=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,p=new RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),q=function(a,b){return a.test(b)},r=function(a){var r=a||navigator.userAgent,s=r.split("[FBAN");return"undefined"!=typeof s[1]&&(r=s[0]),s=r.split("Twitter"),"undefined"!=typeof s[1]&&(r=s[0]),this.apple={phone:q(b,r),ipod:q(c,r),tablet:!q(b,r)&&q(d,r),device:q(b,r)||q(c,r)||q(d,r)},this.amazon={phone:q(g,r),tablet:!q(g,r)&&q(h,r),device:q(g,r)||q(h,r)},this.android={phone:q(g,r)||q(e,r),tablet:!q(g,r)&&!q(e,r)&&(q(h,r)||q(f,r)),device:q(g,r)||q(h,r)||q(e,r)||q(f,r)},this.windows={phone:q(i,r),tablet:q(j,r),device:q(i,r)||q(j,r)},this.other={blackberry:q(k,r),blackberry10:q(l,r),opera:q(m,r),firefox:q(o,r),chrome:q(n,r),device:q(k,r)||q(l,r)||q(m,r)||q(o,r)||q(n,r)},this.seven_inch=q(p,r),this.any=this.apple.device||this.android.device||this.windows.device||this.other.device||this.seven_inch,this.phone=this.apple.phone||this.android.phone||this.windows.phone,this.tablet=this.apple.tablet||this.android.tablet||this.windows.tablet,"undefined"==typeof window?this:void 0},s=function(){var a=new r;return a.Class=r,a};"undefined"!=typeof module&&module.exports&&"undefined"==typeof window?module.exports=r:"undefined"!=typeof module&&module.exports&&"undefined"!=typeof window?module.exports=s():"function"==typeof define&&define.amd?define("isMobile",[],a.isMobile=s()):a.isMobile=s()}(this);
(function () {
if (isMobile) {
console.log(isMobile);
}
})();
</script>
-->
document.addEventListener('DOMContentLoaded', function(){
if (window.isMobile !== undefined) {
console.log(isMobile);
if(isMobile.any) {
var rootClasses = ' is-mobile';
for (key in isMobile) {
if(typeof isMobile[key] === 'boolean' && isMobile[key] && key !== 'any') rootClasses += ' is-mobile--'+key;
if(typeof isMobile[key] === 'object' && key !== 'other') {
for (type in isMobile[key]) {
if(isMobile[key][type]) rootClasses += ' is-mobile--'+key+'-'+type;
}
}
}
document.documentElement.className += rootClasses;
}
}
else {
console.log('Классы для мобильных не добавлены: в сборке отсутствует isMobile.js');
}
});
// В этом файле должны быть стили только для БЭМ-блока is-mobile, его элементов,
// модификаторов, псевдоселекторов, псевдоэлементов, @media-условий...
// Не пишите здесь другие селекторы.
.is-mobile {
&--android-device {}
&--apple-device {}
&--amazon-device {}
&--windows-device {}
&--phone {}
&--tablet {}
&--seven_inch {}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment