Last active
October 9, 2016 20:28
-
-
Save englishextra/ff8c9dde94abe32a9d7c4a65e0f2ccac to your computer and use it in GitHub Desktop.
modified MediaHack by Pomke Nohkan removed className fallback and additionally returns earlyDeviceOrientation,earlyDeviceSize
This file contains hidden or 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
/*! | |
* modified MediaHack - (c) 2013 Pomke Nohkan MIT LICENCED. | |
* gist.github.com/englishextra/ff8c9dde94abe32a9d7c4a65e0f2ccac | |
* jsfiddle.net/englishextra/xg7ce8kc/ | |
* removed className fallback and additionally | |
* returns earlyDeviceOrientation,earlyDeviceSize | |
* Add media query classes to DOM nodes | |
* github.com/pomke/mediahack/blob/master/mediahack.js | |
*/ | |
var earlyDeviceOrientation = "", earlyDeviceSize = ""; | |
(function (w, e) { | |
function f(a) { | |
var b = a.split(" "); | |
if (e) { | |
for (var c = 0; c < b.length; c++) { | |
(a = b[c]) && e.add(a) | |
}; | |
} | |
}; | |
function g(a) { | |
var b = a.split(" "); | |
if (e) { | |
for (var c = 0; c < b.length; c++) { | |
(a = b[c]) && e.remove(a) | |
}; | |
} | |
}; | |
var h = { | |
landscape : "all and (orientation:landscape)", | |
portrait : "all and (orientation:portrait)" | |
}, | |
k = { | |
small : "all and (max-width:768px)", | |
medium : "all and (min-width:768px) and (max-width:991px)", | |
large : "all and (min-width:992px)" | |
}, | |
d, | |
mM = "matchMedia"; | |
for (d in h) { | |
(function (a, b) { | |
var c = function (a) { | |
a.matches ? (f(b), earlyDeviceOrientation = b) : g(b) | |
}; | |
c(a); | |
a.addListener(c); | |
})(w[mM](h[d]), d); | |
}; | |
for (d in k) { | |
(function (a, b) { | |
var c = function (a) { | |
a.matches ? (f(b), earlyDeviceSize = b) : g(b) | |
}; | |
c(a); | |
a.addListener(c); | |
})(w[mM](k[d]), d); | |
}; | |
})(window, document.documentElement.classList || ""); | |
alert(earlyDeviceOrientation+" "+earlyDeviceSize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment