diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 00:14:07 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 00:14:07 +0200 |
| commit | a190d638c608f4352e3f01d72ed419a5ab5129ed (patch) | |
| tree | dd6e7ea24c2ae4b6251f1ae2b609d9017acfd199 /client/vendor/util.js | |
db stuff and initial app scaffold
Diffstat (limited to 'client/vendor/util.js')
| -rw-r--r-- | client/vendor/util.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/client/vendor/util.js b/client/vendor/util.js new file mode 100644 index 0000000..5d51c34 --- /dev/null +++ b/client/vendor/util.js @@ -0,0 +1,23 @@ +const isIphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) +const isIpad = (navigator.userAgent.match(/iPad/i)) +const isAndroid = (navigator.userAgent.match(/Android/i)) +const isMobile = isIphone || isIpad || isAndroid +const isDesktop = ! isMobile + +document.body.classList.add(isMobile ? 'mobile' : 'desktop') + +const browser = { isIphone, isIpad, isAndroid, isMobile, isDesktop } + +function clamp(n,a,b){ return n<a?a:n<b?n:b } +function mod(n,m){ return n-(m * Math.floor(n/m)) } +function choice (a){ return a[ randint(a.length) ] } +function randint(n){ return Math.floor(Math.random() * n) } +function randrange(a,b) { return Math.random() * (b-a) + a } +function firstTouch(f){ return e => { e.preventDefault(); f(e.touches[0]) }} + +export { + browser, + clamp, mod, + choice, randint, randrange, + firstTouch, +} |
