Skip to content
This repository was archived by the owner on Jan 31, 2018. It is now read-only.

Commit 4e539e4

Browse files
committed
Updated syntax. added connection.type for bandwidth detection
1 parent 61bd790 commit 4e539e4

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

js/app.helpers.js

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
1-
window.APP = (function(module, $) {
1+
window.APP = (function(module) {
22
"use strict";
33

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() {
3437
var deviceOrientation = window.orientation;
3538
if (typeof deviceOrientation === "undefined")
3639
deviceOrientation = 'orientation not supported';
3740

3841
return deviceOrientation;
39-
4042
}
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+
4844
}
4945

50-
51-
5246
return module;
5347

54-
})(window.APP || {}, window.jQuery);
48+
})(window.APP || {});

0 commit comments

Comments
 (0)