|
1 | | -window.APP = (function(module, $) { |
| 1 | +window.APP = (function(module) { |
2 | 2 | "use strict"; |
3 | 3 |
|
4 | | - module.helpers = { |
5 | | - supportsTouch: isTouchDevice(), |
6 | | - screenView : getScreenView(), |
7 | | - orientation: getOrientation(), |
8 | | - jsPath : '/assets/js/' |
9 | | - } |
10 | | - |
11 | | - |
12 | | - /*--- Check what view we are in - small, medium, large ---*/ |
13 | | - // Use a common element which changes between window sizes |
14 | | - // e.g. main nav - hidden on small screens. try and avoid using device widths if possible |
15 | | - function getScreenView() { |
16 | | - var small = 480, |
17 | | - med = 768, |
18 | | - large, |
19 | | - screen; |
20 | | - if($(window).width() <= small) { |
21 | | - screen = 'small'; |
22 | | - } |
23 | | - else if($(window).width() <= med) { |
24 | | - screen = 'medium'; |
25 | | - } |
26 | | - else { |
27 | | - screen = 'large'; |
28 | | - } |
29 | | - return screen; |
30 | | - } |
31 | | - |
32 | | - /*--- Check the orientation of device ---*/ |
33 | | - function getOrientation() { |
| 4 | + module.device = { |
| 5 | + // Check for touch support usign touch & ms-pointer events |
| 6 | + supportsTouch : (function() { |
| 7 | + var isTouch = !!('ontouchstart' in window) || !!window.navigator.msMaxTouchPoints; |
| 8 | + if (isTouch) { |
| 9 | + document.getElementsByTagName("html")[0].className += " supports-touch"; |
| 10 | + } |
| 11 | + return isTouch; |
| 12 | + })(), |
| 13 | + // Check for retina display. |
| 14 | + isRetina : (function() { |
| 15 | + var isRetina = (window.devicePixelRatio > 1) ? true : false; |
| 16 | + if (isRetina) { |
| 17 | + document.getElementsByTagName("html")[0].className += " retina"; |
| 18 | + } |
| 19 | + return isRetina; |
| 20 | + })(), |
| 21 | + // Is mobile view. |
| 22 | + isSmallScreen : function() { |
| 23 | + var isSmallScreen = (window.innerWidth <= 480) ? true : false; |
| 24 | + return isSmallScreen; |
| 25 | + }, |
| 26 | + // Is IEx or lt-IEx |
| 27 | + /*isIE : (function(version) { |
| 28 | + })(),*/ |
| 29 | + // Connection type e.g. wifi, 3g etc. Currently only supported by Android |
| 30 | + connectionType : (function() { |
| 31 | + var bandwidth = navigator.connection.type; |
| 32 | + if (typeof bandwidth === "undefined") |
| 33 | + bandwidth = 'connection.type not supported'; |
| 34 | + return bandwidth; |
| 35 | + })(), |
| 36 | + orientation : function() { |
34 | 37 | var deviceOrientation = window.orientation; |
35 | 38 | if (typeof deviceOrientation === "undefined") |
36 | 39 | deviceOrientation = 'orientation not supported'; |
37 | 40 |
|
38 | 41 | return deviceOrientation; |
39 | | - |
40 | 42 | } |
41 | | - |
42 | | - /*--- Check if device supports touch event ---*/ |
43 | | - function isTouchDevice() { |
44 | | - return !!('ontouchstart' in window) || !!window.navigator.msMaxTouchPoints; |
45 | | - } |
46 | | - if (module.helpers.supportsTouch) { |
47 | | - document.getElementsByTagName("html")[0].className += " supports-touch"; |
| 43 | + |
48 | 44 | } |
49 | 45 |
|
50 | | - |
51 | | - |
52 | 46 | return module; |
53 | 47 |
|
54 | | -})(window.APP || {}, window.jQuery); |
| 48 | +})(window.APP || {}); |
0 commit comments