-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest5.js
178 lines (123 loc) · 4.01 KB
/
test5.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*-----------------------------------------------------
*******************************************************
*****************************************************
LIGHTRANGE
Simple date range selection
2016-01-28
Tommie Hansen
*****************************************************
*******************************************************
-----------------------------------------------------*/
// INIT
;(function($, window, document, undefined) {
'use strict';
/* Start performance measurement */
var perfStart = performance.now();
/* Helpers */
function _id(e) { return document.getElementById(e); }
//function _e(e) { return document.querySelector(e); }
//function _ee(e) { return document.querySelectorAll(e); }
//function _for(e,f) { var i, len=e.length; for(i=0;i<len;i++){ f(e[i]); }}
//function _for(e,f) { var i, len=e.length; for(i=0;i<len;i++){ if(f(e[i]) === false) break; }}
//function _data(e,attr) { return e.getAttribute('data-' + attr); }
/* GLOBAL SCOPE / SETUP */
var main = _id('cal'),
r_dp = main.querySelector('#r_dp'),
r_dpi = _id('r_dpi'), // calendar input field
firstRun = true,
dayLong = r_dpi.getAttribute('data-days').split(','),
monthLong = r_dpi.getAttribute('data-months').split(','),
dayShort = [],
monthShort = [],
monthConf = r_dpi.getAttribute('data-monthsNum').split(','),
monthNum = monthConf[0],
monthStart = monthConf[1],
sel1 = false, // selection 1 + 2
sel2 = false;
// generate short days + months
for(var i=0;i<7;i++){ dayShort[i] = dayLong[i].substr(0,3); }
for(var i=0;i<12;i++){ monthShort[i] = monthLong[i].substr(0,3); }
/*-----------------------------------------------------
Begin rangeCal ns
-----------------------------------------------------*/
var rangeCal = {
/* Show */
show: function(){
// add classes
main.className = 'show';
r_ovr.className = 'on';
// use isInit to check if the calendar has already been triggered
// else just show the calendar without re-processing month and binds
if(!isInit){
var now = new Date(),
month = now.getMonth(), // note: getMonth = zero-based index
year = now.getFullYear();
// apply offset
month = month + parseInt(offset);
// set curdate
curDate = month + ',' + year;
this.getMonth(curDate); // get month
this.binds(); // initiliaze all binds once
isInit = 1;
}
},
/* Hide */
hide: function(){
main.className = '';
},
/* Error */
err: function(){},
/* Hover Range */
hoverRange: function(){},
/* Navigation */
nav: function(){},
/* Binds */
binds: function(){
// initialize datepicker
$(r_dpi).on('click', this.showCal);
// click day
$(main).on('click', 'tbody td', this.select);
// month navigation
//$(r_nav).on('click', '.nav', function(){ rangeCal.nav(this, monthsNum); } )
// OK/Cancel buttons
$(r_actions).on('click', 'button', function(){
var ok = true;
// Cancel
if( this.className.indexOf('red') > -1 ){
// reset form and close (or just close)
}
// OK button
else {
// validate selections
}
// close if OK
if(ok) rangeCal.hide();
})
},
/* Navigation */
nav: function(e){
var curX,
curId = e.id;
},
/*-----------------------------------------------------
LARGE FUNCTIONS
-----------------------------------------------------*/
/* User select action */
select: function(){},
/* Set dates */
set: function(){},
/* Output month */
getMonth: function(curDate){
var perfStart = performance.now(); // Begin perf measure
// PERF: Output to log
var perfEnd = performance.now();
console.log('getMonth perf @ 50 months: ' + (perfEnd-perfStart) + 'ms');
} // end getMonth
};
/* INIT ON RUN */
rangeCal.binds();
/* LOG PERFORMANCE */
var perfEnd = performance.now();
var str = 'init perf: ' + (perfEnd-perfStart) + 'ms';
console.log(str);
})(jQuery,window,document);