/
lib.js
103 lines (78 loc) · 2.17 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var debug = true;
var height, width, device;
var scrollPosition;
// Debugging Message Control
var debug_stage_msg = function(message) {
if(debug) {
console.log(message);
}
}
var dsm = debug_stage_msg; // Alias
// Event Tracking Wrapper
var shoutOut = function(category, action, opt_label, opt_value) {
opt_label = opt_label || false;
opt_value = opt_value || false;
// Google Analytics Shit
_gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
dsm("An event was logged");
}
/* ---------- HELPER FUNCTIONS --------- */
// CSS Wrappers
var setCSS = function(target, property, value) {
$(target).css(property, value);
return target;
}
var setWidth = function(target, value) {
setCSS(target, 'min-width', Math.round(value));
}
var setHeight = function(target, value) {
setCSS(target, 'min-height', Math.round(value));
}
// Mathematical Wrappers
var percentage = function(number, percentage, decimalPlaces) {
decimalPlaces = decimalPlaces || false;
var result = (percentage/100) * number;
if (decimalPlaces) {
return Math.floor(result * (10 * decimalPlaces)) / (10 * decimalPlaces);
} else {
return result;
}
}
/* ---------- RESPONSIVE ---------- */
// Get Device Type
var getDeviceType = function(width, height) {
if (width > 1600 && height > 1100) {
device = 'desk-wide';
}
else if (width > 1000) {
device = 'desk';
}
else if (width < 1000 && width > 481) {
device = 'portable';
}
else if (width < 481) {
device = 'palm';
}
else {
device = 'unknown';
}
return device;
}
var deviceDimensions = function() {
// Get to know the viewport
// https://stackoverflow.com/questions/1248081/get-the-browser-viewport-dimensions-with-javascript
window.width = Math.max(window.innerWidth)
window.height = Math.max(window.innerHeight)
return width, height;
}
// Classes that need viewport data to Initialize
var viewportDependentClasses = function(device) {
if(device != 'desk-wide') {
$('.full-height').css('min-height', height);
$('.half-height').css('min-height', height / 2);
} else {
setHeight('.full-height', 900);
setHeight('.half-height', 1500);
}
return false;
}