yodatepicker 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d578013c430014be26958f1669a56acd6f1477a8
4
- data.tar.gz: dfaeef2b3a163459ca4e0e46d35ded3f532cb7dd
3
+ metadata.gz: 1b915dce295de331a10dfcb578dfffb9bce0c156
4
+ data.tar.gz: 3c3a516c0dce6537df309236d1aa4548fe2ea968
5
5
  SHA512:
6
- metadata.gz: a5bab0047c6ac0354732e357618d06c9573cd8b6ad7179ff860f31d0f4fcdfcfecbf3c46ffabb8c976ca04d2154809982dbb32637601b582366c37694e875d9d
7
- data.tar.gz: 755e79127ad4ff5ec92490334b68cd0602c3ca3d6d4d63521ef7bf35027bd3aae71d34846add2cf90a950bf91fb1836dd1f5b2539398704a3d1f3091c37d20db
6
+ metadata.gz: 407c331df4ff477a783192113d60febf9fc1b4a1695cdb9b326dd7e6d953cfe07f5e588eb045c9c329b9b902990e024fc6a00b698d6ad7167a768d324a00563b
7
+ data.tar.gz: 4cacc437cf72e8b09428539417bc0388d59d42e330f8488d0ca2ef99bd19e29f6d37c4cd9c352e4d2b17bca0d4c2326c2e106bfb22a2ee3fb788b97d4a7816ec
metadata CHANGED
@@ -1,25 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yodatepicker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Brettin
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-28 00:00:00.000000000 Z
12
- dependencies: []
13
- description: yodatepicker - a simple javascript datepicker
14
- email: mark@jackrabbitsystems.com
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: No dependencies
42
+ email:
43
+ - mark@jackrabbitsystems.com
15
44
  executables: []
16
45
  extensions: []
17
46
  extra_rdoc_files: []
18
- files:
19
- - app/js/yodatepicker.js
20
- - app/js/yodatepicker.min.js
21
- - app/styles/yodatepicker-multi.css
22
- - app/styles/yodatepicker.css
47
+ files: []
23
48
  homepage: https://github.com/jackrabbit/yodatepicker
24
49
  licenses:
25
50
  - MIT
@@ -43,6 +68,5 @@ rubyforge_project:
43
68
  rubygems_version: 2.4.8
44
69
  signing_key:
45
70
  specification_version: 4
46
- summary: yodatepicker
71
+ summary: A simple configurable javascript datepicker.
47
72
  test_files: []
48
- has_rdoc:
@@ -1,1266 +0,0 @@
1
- 'use strict';
2
-
3
- /* jshint unused: false */
4
- var yodatepicker = function(options) {
5
- /* jshint unused: true */
6
- var YoException = function(value) {
7
- this.value = value;
8
- this.message = 'yoException: something is wrong with ';
9
- this.toString = function() {
10
- return this.message + this.value;
11
- };
12
- };
13
-
14
- var configure = function(opts) {
15
- var cfg = {
16
- // Max months to display on a multi-month yodatepicker.
17
- MAX_CALENDARS: 2,
18
-
19
- // Element id where to display the yodatepicker.
20
- dp_id_name: opts.dp_id_name || '',
21
-
22
- // Element id where to populate a selected date.
23
- id_name: opts.id_name || '',
24
-
25
- // Localization.
26
- locale: opts.locale || 'en',
27
-
28
- // User defined function executed when selecting a date.
29
- ondateselected_callback: (opts.onDateSelected instanceof Function) ?
30
- opts.onDateSelected : null,
31
-
32
- // User defined function to be called when closing yodatepicker.
33
- onclose_callback: (opts.onClose instanceof Function) ?
34
- opts.onClose : null,
35
-
36
- // Number of months to display in multi-month yodatepicker.
37
- months_to_display: opts.months_to_display || 1,
38
-
39
- // Boolean triggers yodatepicker to close when user selects a date.
40
- close_onselect: opts.close_onselect,
41
-
42
- // Max date user can scroll forward to.
43
- max_date: get_max_date((opts.max_date || '1Y')),
44
-
45
- // Min date user can scroll backward to.
46
- min_date: get_min_date((opts.min_date || '*')),
47
-
48
- // An array of objects with dates as the key and the content
49
- // as the value where the value is the content to be included
50
- // for that date.
51
- cell_content: opts.cell_content || null,
52
-
53
- // if set to true will ignore normal price configurations and pass
54
-             // the data through as is
55
-             use_custom_content: opts.use_custom_content || false,
56
-
57
- // Sets the day of week name: single_name, short_name, full_name.
58
- dow_heading: opts.dow_heading || 'single_name',
59
-
60
- // Tells yodatepicker that the user wants to use a date range.
61
- // The first date selected will become the begin date and then
62
- // the second date selected will become the end date.
63
- use_date_range: opts.use_date_range || false,
64
-
65
- // If use_date_range then this is the element id where to
66
- // populate the selected start date.
67
- begin_id_name: opts.begin_id_name || '',
68
-
69
- // If use_date_range then this is the element id where to
70
- // populate the selected end date.
71
- end_id_name: opts.end_id_name || '',
72
-
73
- // The current date.
74
- currdate: new Date(),
75
-
76
- // CSS class used for previous and next navigation (fontawesome).
77
- prev_fa_class: opts.prev_fa_class || '',
78
- next_fa_class: opts.next_fa_class || '',
79
-
80
- // Custom colors for certain items.
81
- prev_month_nav_color: opts.prev_month_nav_color || '',
82
- next_month_nav_color: opts.next_month_nav_color || '',
83
-
84
- // These options go together for hovering.
85
- rate_mouseover_fgcolor: opts.rate_mouseover_fgcolor || '',
86
- day_mouseover_bgcolor: opts.day_mouseover_bgcolor || '',
87
- day_mouseover_fgcolor: opts.day_mouseover_fgcolor || '',
88
- selected_rate_color: opts.selected_rate_color || '',
89
-
90
- rate_mouseleave_fgcolor: opts.rate_mouseleave_fgcolor || '',
91
- day_mouseleave_bgcolor: opts.day_mouseleave_bgcolor || '',
92
- day_mouseleave_fgcolor: opts.day_mouseleave_fgcolor || '',
93
-
94
- current_start_date: opts.current_start_date || '',
95
- current_stop_date: opts.current_stop_date || ''
96
- };
97
-
98
- // TODO: Clean up this below.
99
- cfg.today = new Date(cfg.currdate.getFullYear(),
100
- cfg.currdate.getMonth(),
101
- cfg.currdate.getDate());
102
-
103
- // array of month names
104
- cfg.month_names = get_month_names(cfg.locale);
105
-
106
- // array of day of week names
107
- cfg.day_names = get_dow_names(cfg.locale, cfg.dow_heading);
108
-
109
- // Keeps track of the month the datepicker is on and will
110
- // not go past the min_date month (if set).
111
- var dp_display_date = cfg.current_start_date ?
112
- cfg.current_start_date : cfg.currdate;
113
- cfg.mn = (dp_display_date.getTime() < cfg.min_date.getTime()) ?
114
- cfg.min_date.getMonth() : dp_display_date.getMonth();
115
-
116
- // Keeps track of the year the datepicker is on and will
117
- // not go past the min_date year (if set).
118
- cfg.yy = (dp_display_date.getTime() < cfg.min_date.getTime()) ?
119
- cfg.min_date.getFullYear() : dp_display_date.getFullYear();
120
-
121
- // Set flag, tiggers the datepicker to close on selecting a day.
122
- cfg.close_onselect = (cfg.close_onselect === undefined) ?
123
- true : cfg.close_onselect;
124
-
125
- // Limit the number of months to display for a multi-month datepicker.
126
- cfg.months_to_display = (cfg.months_to_display > cfg.MAX_CALENDARS) ?
127
- cfg.MAX_CALENDARS : cfg.months_to_display;
128
-
129
- // This feature is only applicable when close_onselect is false and
130
- // months_to_display is greater than 1.
131
- //cfg.use_date_range = (cfg.close_onselect === false &&
132
- // cfg.months_to_display > 1) ? cfg.use_date_range : false;
133
-
134
- // Indicator for which date is active / set when use_date_range.
135
- cfg.date_range = cfg.use_date_range ? {start: true, stop: false} : null;
136
-
137
- return cfg;
138
- };
139
-
140
- var toggle_date_range = function() {
141
- if(cfg.use_date_range) {
142
- if(cfg.date_range.start) {
143
- cfg.date_range.start = false;
144
- cfg.date_range.stop = true;
145
- } else {
146
- cfg.date_range.start = true;
147
- cfg.date_range.stop = false;
148
- }
149
- return true;
150
- }
151
- return false;
152
- };
153
-
154
- var citem = {
155
- day: 0,
156
- month: 0,
157
- year: 1900,
158
- first_dow: 0,
159
- total_days: 0,
160
- offset: 0,
161
-
162
- jrs_more_content: function(key) {
163
- // Returns the content for a cell if it is present.
164
- // Otherwise return an alternate string.
165
- //
166
- // NOTE: key is formatted like '0_25_2015' so here we'll
167
- // reformat that to look like '2015-01-25'.
168
-
169
- var build_item = function(value) {
170
- if(!cfg.use_custom_content) {
171
- var rate = parseFloat(value.toString());
172
- if(isNaN(rate) || rate < 1 ) {
173
- return '<div class="yo-rate-item">N/A</div>';
174
- }
175
- return '<div class="yo-rate-item">$' + value + '</div>';
176
- }
177
- else {
178
- return '<div class="yo-rate-item">' + value + '</div>';
179
- }
180
- };
181
-
182
- var items = key.split('_');
183
- if(!items) { return build_item('N/A'); }
184
-
185
- items[0] = parseInt(items[0], 10) + 1;
186
- var key_month = (items[0] < 10) ? ('0' + items[0]) : items[0];
187
- var key_day = (items[1] < 10) ? ('0' + items[1]) : items[1];
188
- var content_date = items[2] + '-' + key_month + '-' + key_day;
189
-
190
- // NOTE: This loop is inefficient, however for our immediate
191
- // purposes, cell_content is only going to have 365 elements
192
- // which is one year of rates.
193
- for(var i = 0; i < cfg.cell_content.length; i++) {
194
- if(cfg.cell_content[i].date === content_date) {
195
- var value = cfg.cell_content[i].data;
196
- return build_item(value);
197
- }
198
- }
199
- if(cfg.use_custom_content) {
200
- return build_item('');
201
- } else {
202
- return build_item('N/A');
203
- }
204
- },
205
-
206
- markup: function(params) {
207
- var tr_node = params.tr_node;
208
- var td_class = 'yo-datepicker-day-empty' + params.multi_cal;
209
-
210
- if(this.offset >= this.first_dow) {
211
- var tmp_date = new Date(this.year, this.month, this.day);
212
- var key = this.month + '_' + this.day + '_' + this.year;
213
- var td_id = params.yo_id + '_' + key;
214
-
215
- if(tmp_date.valueOf() > cfg.max_date.valueOf()) {
216
- td_class = 'yo-datepicker-day-noselect' + params.multi_cal;
217
- _yodatepicker.create_day(tr_node, this.day, td_id, td_class);
218
- }
219
- else if(tmp_date.valueOf() < cfg.min_date.valueOf()) {
220
- td_class = 'yo-datepicker-day-noselect' + params.multi_cal;
221
- _yodatepicker.create_day(tr_node, this.day, td_id, td_class);
222
- }
223
- else if(tmp_date.valueOf() === cfg.today.valueOf()) {
224
- td_class = 'yo-datepicker-day-current' + params.multi_cal;
225
- _yodatepicker.create_day(tr_node, this.day, td_id, td_class);
226
- var tmp_elem = document.getElementById(td_id);
227
- if(tmp_elem && cfg.cell_content) {
228
- tmp_elem.innerHTML += this.jrs_more_content(key);
229
- }
230
- }
231
- else {
232
- td_class = 'yo-datepicker-day' + params.multi_cal;
233
- _yodatepicker.create_day(tr_node, this.day, td_id, td_class);
234
- var tmp_elem = document.getElementById(td_id);
235
- if(tmp_elem && cfg.cell_content) {
236
- tmp_elem.innerHTML += this.jrs_more_content(key);
237
- }
238
- }
239
-
240
- if(this.day >= this.total_days) { this.first_dow = 999; }
241
- }
242
- else {
243
- _yodatepicker.create_day(tr_node, '', '', td_class);
244
- }
245
- this.offset++;
246
- if(this.offset > this.first_dow) { this.day++; }
247
- }
248
- };
249
-
250
- var close_datepicker = function() {
251
- if(!cfg.close_onselect) { return; }
252
-
253
- // Close the datepicker by setting innerHTML to empty string.
254
- var dp_elem = document.getElementById(cfg.dp_id_name);
255
- if(dp_elem && dp_elem.innerHTML) {
256
- dp_elem.innerHTML = '';
257
- }
258
-
259
- if(cfg.onclose_callback) { cfg.onclose_callback(); }
260
- };
261
-
262
- /* jshint loopfunc: true */
263
-
264
- var rate_available = function(elem) {
265
- if(!elem.innerHTML) { return false; }
266
-
267
- var rate_val = elem.innerHTML;
268
- if(!rate_val || rate_val === 'N/A') {
269
- return false;
270
- }
271
- return true;
272
- };
273
-
274
- var yo_rate_item = function(js_date) {
275
- // The current date needs to be in a format that will work
276
- // with this "yo-" + dp_id_name + "_2_18_2015"
277
- var day_id = 'yo-' + cfg.dp_id_name + '_' + js_date;
278
- var day_elem = document.getElementById(day_id);
279
- if(!day_elem) { return false; }
280
-
281
- var rate_class = 'yo-rate-item';
282
- var rate_elem = day_elem.getElementsByClassName(rate_class);
283
- if(!rate_elem) { return false; }
284
-
285
- return rate_elem[0];
286
- };
287
-
288
- var reset_date_inputs = function() {
289
- cfg.date_range = { start: true, stop: false };
290
-
291
- var start_elem = document.getElementById(cfg.begin_id_name);
292
- start_elem.value = '';
293
- var stop_elem = document.getElementById(cfg.end_id_name);
294
- stop_elem.value = '';
295
- };
296
-
297
- var date_input_element = function() {
298
- var elem = '';
299
- if(cfg.use_date_range) {
300
- if(cfg.date_range.start) {
301
- elem = cfg.begin_id_name;
302
- document.getElementById(cfg.end_id_name).value = '';
303
- } else {
304
- elem = cfg.end_id_name;
305
- }
306
- } else {
307
- elem = cfg.id_name;
308
- }
309
- return elem;
310
- };
311
-
312
- var raw2date = function(raw_date) {
313
- // Take a raw_formatted date like 3_12_2015 and
314
- // returns a javascript Date object.
315
- var pieces = raw_date.split('_');
316
- return new Date(pieces[2], pieces[0], pieces[1]);
317
- };
318
-
319
- var highlight_date = function(js_date, toggle) {
320
- toggle = (toggle) ? toggle : false;
321
- var id_name = 'yo-' + cfg.dp_id_name + '_' + js_date;
322
- var day_elem = document.getElementById(id_name);
323
- if(toggle === true) {
324
- // toggle true: highlight the start date with the mouseover colors
325
- // day_elem.style.color = cfg.day_mouseover_fgcolor;
326
- day_elem.style.color = cfg.selected_rate_color;
327
- day_elem.style.backgroundColor = cfg.day_mouseover_bgcolor;
328
- var rate_elem = yo_rate_item(js_date);
329
- rate_elem.style.color = cfg.selected_rate_color;
330
-
331
- day_elem.onmouseleave = function() {
332
- this.style.color = cfg.selected_rate_color;
333
- this.style.backgroundColor = cfg.day_mouseover_bgcolor;
334
- var rate_elem = yo_rate_item(js_date);
335
- rate_elem.style.color = cfg.selected_rate_color;
336
- };
337
- } else {
338
- // toggle false: start date back to original colors
339
- day_elem.style.color = cfg.selected_rate_color;
340
- day_elem.style.backgroundColor = cfg.day_mouseleave_bgcolor;
341
- var rate_elem = yo_rate_item(js_date);
342
- rate_elem.style.color = cfg.selected_rate_color;
343
-
344
- day_elem.onmouseleave = function() {
345
- this.style.color = cfg.day_mouseleave_fgcolor;
346
- this.style.backgroundColor = cfg.day_mouseleave_bgcolor;
347
- var rate_elem = yo_rate_item(js_date);
348
- rate_elem.style.color = cfg.selected_rate_color;
349
- };
350
- }
351
- };
352
-
353
- /* jshint unused: false */
354
- var select_date = function(_mm, _dd, _yy) {
355
- try {
356
- if(_mm === undefined || _dd === undefined || _yy === undefined) {
357
- throw new YoException('undefined paramter(s)');
358
- }
359
-
360
- var js_date = _mm + '_' + _dd + '_' + _yy;
361
-
362
- // If cfg.id_name has a value then we have a single calendar
363
- // datepicker. Otherwise we have a multi-month calendar and
364
- // cfg.date_range is an object that idicates what date is being
365
- // selected, either the begin date or the end date.
366
- if(cfg.id_name !== '' || cfg.date_range) {
367
- var elem = date_input_element();
368
-
369
- if(cfg.date_range && cfg.date_range.stop) {
370
- var start_date = raw2date(cfg.date_range.start_date_raw);
371
- var stop_date = raw2date(js_date);
372
- // do this check before we set stop_date_raw
373
- if(stop_date < start_date) {
374
- console.log('end date cannot be < start date');
375
- return;
376
- } else if(start_date.getTime() === stop_date.getTime()) {
377
- // user clicked a stop_date same as the start_date
378
-
379
- // set start date highlight off
380
- highlight_date(cfg.date_range.start_date_raw, false);
381
-
382
- // clear the start_date
383
- reset_date_inputs();
384
- return;
385
- }
386
-
387
- cfg.date_range.stop_date_raw = js_date;
388
- stop_date = raw2date(cfg.date_range.stop_date_raw);
389
- _yodatepicker.highlight_selected_dates(start_date, stop_date);
390
- }
391
-
392
- if(cfg.date_range && cfg.date_range.start) {
393
- if(cfg.date_range.start) {
394
- // set colors back original values
395
- _yodatepicker.set_custom_day_colors();
396
- }
397
- // set the colors for the start date just selected
398
- highlight_date(js_date, true);
399
-
400
- cfg.date_range.start_date_raw = js_date;
401
- cfg.date_range.stop_date_raw = '';
402
- }
403
- if(cfg.use_date_range) { toggle_date_range(); }
404
- put_date_DOM(elem, _mm, _dd, _yy);
405
- }
406
-
407
- if(cfg.ondateselected_callback) { cfg.ondateselected_callback(); }
408
-
409
- if(!cfg.use_date_range && cfg.close_onselect) {
410
- close_datepicker();
411
- } else if(cfg.use_date_range && cfg.date_range.start_date_raw && cfg.date_range.stop_date_raw && cfg.close_onselect) {
412
- close_datepicker();
413
- }
414
- } catch(e) {
415
- console.log(e.toString());
416
- return false;
417
- }
418
- return true;
419
- /* jshint unused: true */
420
- };
421
-
422
- var put_date_DOM = function(elem, _mm, _dd, _yy) {
423
- if(!elem) { return; }
424
- _mm++; // Note: _mm is the month number 0 - 11 so always add 1.
425
-
426
- var the_month = (_mm < 10) ? '0' + _mm : _mm.toString();
427
- var the_day = (_dd < 10) ? '0' + _dd : _dd.toString();
428
-
429
- /* jshint evil: true */
430
- if(cfg.locale === 'en') {
431
- eval('document.getElementById("' + elem + '").value=' +
432
- 'the_month + "/" + the_day + "/" + _yy');
433
- } else {
434
- eval('document.getElementById("' + elem + '").value=' +
435
- 'the_day + "/" + the_month + "/" + _yy');
436
- }
437
- /* jshint evil: false */
438
- };
439
-
440
- var text = function(_text) {
441
- // Create and set a text node and return it.
442
- var node = document.createTextNode(_text);
443
- return node;
444
- };
445
-
446
- var element = function(_name, _attrs) {
447
- // Create and set an element node and return it.
448
- var node = document.createElement(_name);
449
- if(_attrs) {
450
- if(_attrs.id) { node.setAttribute('id', _attrs.id); }
451
- if(_attrs.klass) { node.setAttribute('class', _attrs.klass); }
452
- if(_attrs.style) { node.setAttribute('style', _attrs.style); }
453
- if(_attrs.colspan) { node.setAttribute('colspan', _attrs.colspan); }
454
- if(_attrs.value) { node.setAttribute('value', _attrs.value); }
455
- if(_attrs.type) { node.setAttribute('type', _attrs.type); }
456
- }
457
- return(node);
458
- };
459
-
460
- var remove_element = function(_node, _id) {
461
- if(document.getElementById(_id)) {
462
- _node.removeChild(document.getElementById(_id));
463
- }
464
- };
465
-
466
- var month_inc = function() {
467
- var scroll_date = new Date(cfg.yy, cfg.mn, cfg.today.getDate());
468
- if((scroll_date.getFullYear() === cfg.max_date.getFullYear()) &&
469
- (scroll_date.getMonth() >= cfg.max_date.getMonth())) {
470
- return;
471
- }
472
-
473
- if(cfg.mn < 11) { cfg.mn++; }
474
- else { cfg.mn = 0; cfg.yy++; }
475
- _yodatepicker.show();
476
-
477
- if(cfg.date_range) {
478
- var start_raw = cfg.date_range.start_date_raw;
479
- var stop_raw = cfg.date_range.stop_date_raw;
480
- if(!start_raw || !stop_raw) { return; }
481
- var start_date = raw2date(start_raw);
482
- var stop_date = raw2date(stop_raw);
483
- _yodatepicker.highlight_selected_dates(start_date, stop_date, true);
484
- }
485
- };
486
-
487
- var month_dec = function() {
488
- var scroll_date = new Date(cfg.yy, cfg.mn, cfg.today.getDate());
489
- if((scroll_date.getFullYear() === cfg.min_date.getFullYear()) &&
490
- (scroll_date.getMonth() <= cfg.min_date.getMonth())) {
491
- return;
492
- }
493
-
494
- if(cfg.mn > 0) { cfg.mn--; }
495
- else { cfg.mn = 11; cfg.yy--; }
496
- _yodatepicker.show();
497
-
498
- if(cfg.date_range) {
499
- var start_raw = cfg.date_range.start_date_raw;
500
- var stop_raw = cfg.date_range.stop_date_raw;
501
- if(!start_raw || !stop_raw) { return; }
502
- var start_date = raw2date(start_raw);
503
- var stop_date = raw2date(stop_raw);
504
- _yodatepicker.highlight_selected_dates(start_date, stop_date, true);
505
- }
506
- };
507
-
508
- var leap_year = function(yr) {
509
- return(yr % 400 === 0) || (yr % 4 === 0 && yr % 100 !== 0);
510
- };
511
-
512
- var get_dow_names = function(locale, dow_heading) {
513
- var names = [];
514
- switch(dow_heading) {
515
- case 'single_name':
516
- names = dow_single_names(locale);
517
- break;
518
- case 'short_name':
519
- names = dow_short_names(locale);
520
- break;
521
- case 'full_name':
522
- names = dow_full_names(locale);
523
- break;
524
- default:
525
- names = dow_single_names(locale);
526
- }
527
- return names;
528
- };
529
-
530
- var dow_single_names = function(locale) {
531
- var names = [];
532
- switch(locale) {
533
- case 'es':
534
- names = ['D', 'L', 'M', 'M', 'J', 'V', 'S'];
535
- break;
536
- case 'fr':
537
- names = ['D', 'L', 'M', 'M', 'J', 'V', 'S'];
538
- break;
539
- case 'de':
540
- names = ['S', 'M', 'D', 'M', 'D', 'F', 'S'];
541
- break;
542
- default:
543
- names = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
544
- }
545
- return names;
546
- };
547
-
548
- var dow_short_names = function(locale) {
549
- var names = [];
550
- switch(locale) {
551
- case 'es':
552
- names = ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'];
553
- break;
554
- case 'fr':
555
- names = ['Dim', 'Lu', 'Ma', 'Me', 'Jeu', 'Vend', 'Sam'];
556
- break;
557
- case 'de':
558
- names = ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'];
559
- break;
560
- default:
561
- names = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
562
- }
563
- return names;
564
- };
565
-
566
- var dow_full_names = function(locale) {
567
- var names = [];
568
- switch(locale) {
569
- case 'es':
570
- names = ['Domingo', 'Lunes', 'Martes', 'Miercoles',
571
- 'Jueves', 'Viernes', 'Sabado'];
572
- break;
573
- case 'fr':
574
- names = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi',
575
- 'Jeudi', 'Vendredi', 'Samedi'];
576
- break;
577
- case 'de':
578
- names = ['zondag', 'maandag', 'dinsdag', 'woensdag',
579
- 'donderdag', 'vrijdag', 'zaterdag'];
580
- break;
581
- default:
582
- names = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
583
- 'Thursday', 'Friday', 'Saturday'];
584
- }
585
- return names;
586
- };
587
-
588
- var get_month_names = function(locale) {
589
- if(locale === undefined || locale === null) { locale = 'en'; }
590
-
591
- if(locale === 'es') {
592
- return(['Enero', 'Febrero', 'Marzo', 'Abril',
593
- 'Mayo', 'Junio', 'Julio', 'Augosto',
594
- 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']);
595
- }
596
- else if(locale === 'fr') {
597
- return(['Janvier', 'Fevrier', 'Mars', 'Avril',
598
- 'Mai', 'Juin', 'Juillet', 'Aout',
599
- 'Septembre', 'Octobre', 'Novembre', 'Decembre']);
600
- }
601
- else if(locale === 'de') {
602
- return(['Januar', 'Februar', 'Marz', 'April',
603
- 'Mai', 'Juni', 'Juli', 'August',
604
- 'September', 'Oktober', 'November', 'Dezember']);
605
- }
606
-
607
- return(['January', 'February', 'March', 'April', 'May', 'June', 'July',
608
- 'August', 'September', 'October', 'November', 'December']);
609
- };
610
-
611
- var days_in_month = function(month_num, full_year) {
612
- // Jan == 0, Feb == 1, Mar == 2, ...
613
- if(month_num === 0 || month_num === 2 || month_num === 4 ||
614
- month_num === 6 || month_num === 7 || month_num === 9 ||
615
- month_num === 11) {
616
- return(31);
617
- }
618
- else if(month_num === 3 || month_num === 5 ||
619
- month_num === 8 || month_num === 10) {
620
- return(30);
621
- }
622
-
623
- return(leap_year(full_year) ? 29 : 28);
624
- };
625
-
626
- var get_max_date = function(param_max_date) {
627
- // Return a date object set to max_date.
628
- // Acceptable parameter formats: 3M, 6M, 9M, 1Y, 2Y, * (infinity)
629
- var date = new Date();
630
- var month = date.getMonth();
631
- var year = date.getFullYear();
632
-
633
- switch(param_max_date) {
634
- case '3M':
635
- if((month + 3) > 11) { month = (month +3) % 12; year++; }
636
- else { month += 3; }
637
- break;
638
- case '6M':
639
- if((month + 6) > 11) { month = (month +6) % 12; year++; }
640
- else { month += 6; }
641
- break;
642
- case '9M':
643
- if((month + 9) > 11) { month = (month +9) % 12; year++; }
644
- else { month += 9; }
645
- break;
646
- case '2Y':
647
- year += 2;
648
- break;
649
- case '*': // infinity
650
- year = 3125;
651
- break;
652
- default: // default to '1Y'
653
- year += 1;
654
- }
655
- return(new Date(year, month, date.getDate()));
656
- };
657
-
658
- var get_min_date = function(param_min_date) {
659
- // Return a date object set to min_date.
660
- // Acceptable parameter formats: 0, 3M, 6M, 9M, 1Y, 2Y, * (infinity)
661
- var date = new Date();
662
- var month = date.getMonth();
663
- var year = date.getFullYear();
664
-
665
- // If a Date object is passed in, use that.
666
- if(param_min_date instanceof Date) { return(param_min_date); }
667
-
668
- switch(param_min_date) {
669
- case '3M':
670
- if((month - 3) < 0) { month = (month -3) % 12; year--; }
671
- else { month -= 3; }
672
- break;
673
- case '6M':
674
- if((month - 6) < 0) { month = (month -6) % 12; year--; }
675
- else { month -= 6; }
676
- break;
677
- case '9M':
678
- if((month - 9) < 0) { month = (month -9) % 12; year--; }
679
- else { month -= 9; }
680
- break;
681
- case '1Y':
682
- year -= 1;
683
- break;
684
- case '2Y':
685
- year -= 2;
686
- break;
687
- case '*':
688
- year = 1900;
689
- break;
690
- default:
691
- break; // default is the current date
692
- }
693
- return(new Date(year, month, date.getDate()));
694
- };
695
-
696
- var cfg = configure(options);
697
-
698
- // This object is returned and represents the public properties and methods.
699
- var _yodatepicker = {
700
- version: 'yo-yo',
701
-
702
- hide: function() {
703
- close_datepicker();
704
- },
705
-
706
- /* jshint loopfunc: true */
707
- highlight_selected_dates : function(start_date, stop_date) {
708
- if(!start_date || !stop_date) { return false; }
709
- var td_item = 'yo-datepicker-day-multi';
710
- var rate_item = 'yo-rate-item';
711
- var curr_item = 'yo-datepicker-day-current-multi';
712
-
713
- var items = document.getElementsByClassName(td_item);
714
-
715
- if(cfg.months_to_display === 1) {
716
- td_item = 'yo-datepicker-day';
717
- curr_item = 'yo-datepicker-day-current';
718
- items = document.getElementsByClassName(td_item);
719
- }
720
-
721
- for(var i = 0; i < items.length; i++) {
722
- var id_date = items[i].id.replace('yo-' + cfg.dp_id_name + '_', '');
723
- var curr_date = raw2date(id_date);
724
- var elem = document.getElementById(items[i].id);
725
- var item = elem.getElementsByClassName(rate_item);
726
- if(!item) { continue; }
727
-
728
- // if the current date is between start and stop dates
729
- if(curr_date >= start_date && curr_date <= stop_date) {
730
- // change colors to hover colors
731
- elem.style.color = cfg.selected_rate_color;
732
- elem.style.backgroundColor = cfg.day_mouseover_bgcolor;
733
- // yo-rate-item
734
- item[0].style.color = cfg.selected_rate_color;
735
-
736
- elem.onmouseleave = function() {
737
- // leave hover colors on
738
- this.style.color = cfg.selected_rate_color;
739
- this.style.backgroundColor = cfg.day_mouseover_bgcolor;
740
- // yo-rate-item
741
- var r_item = this.getElementsByClassName(rate_item);
742
- if(!r_item) { return; }
743
- r_item[0].style.color = cfg.selected_rate_color;
744
- };
745
- } else {
746
- // change back to original
747
- item[0].style.color = cfg.rate_mouseleave_fgcolor;
748
- elem.style.color = cfg.day_mouseleave_fgcolor;
749
- elem.style.backgroundColor = cfg.day_mouseleave_bgcolor;
750
- elem.onmouseleave = function() {
751
- this.style.color = cfg.day_mouseleave_fgcolor;
752
- this.style.backgroundColor = cfg.day_mouseleave_bgcolor;
753
- // yo-rate-item
754
- var r_item = this.getElementsByClassName(rate_item);
755
- if(!r_item) { return; }
756
- r_item[0].style.color = cfg.rate_mouseleave_fgcolor;
757
- };
758
- }
759
- }
760
-
761
- // Adding/removing highlight from day-current
762
- var elem_curr = document.getElementsByClassName(curr_item)[0];
763
- if(elem_curr) {
764
- var id_date = elem_curr.id.replace('yo-' + cfg.dp_id_name + '_', '');
765
- var curr_date = raw2date(id_date);
766
- var item = elem_curr.getElementsByClassName(rate_item);
767
- if(!item) { return; }
768
-
769
- if(curr_date >= start_date && curr_date <= stop_date) {
770
- // yo-rate-item
771
- item[0].style.color = cfg.selected_rate_color;
772
- elem_curr.style.color = cfg.selected_rate_color;
773
- elem_curr.style.backgroundColor = cfg.day_mouseover_bgcolor;
774
- elem_curr.onmouseleave = function() {
775
- // leave hover colors on
776
- this.style.color = cfg.selected_rate_color;
777
- this.style.backgroundColor = cfg.day_mouseover_bgcolor;
778
- // yo-rate-item
779
- var r_item = this.getElementsByClassName(rate_item);
780
- if(!r_item) { return; }
781
- r_item[0].style.color = cfg.selected_rate_color;
782
- };
783
- } else {
784
- // change back to original
785
- item[0].style.color = cfg.rate_mouseleave_fgcolor;
786
- elem_curr.style.color = cfg.day_mouseleave_fgcolor;
787
- elem_curr.style.backgroundColor = cfg.day_mouseleave_bgcolor;
788
- elem_curr.onmouseleave = function() {
789
- this.style.color = cfg.day_mouseleave_fgcolor;
790
- this.style.backgroundColor = cfg.day_mouseleave_bgcolor;
791
-
792
- // yo-rate-item
793
- var r_item = this.getElementsByClassName(rate_item);
794
- if(!r_item) { return; }
795
- r_item[0].style.color = cfg.rate_mouseleave_fgcolor;
796
- };
797
- }
798
- }
799
- },
800
- /* jshint loopfunc: false */
801
-
802
- set_min_date: function(mdate) {
803
- // This will override the cfg.min_date param.
804
- if(!mdate instanceof Date) { return false; }
805
-
806
- cfg.min_date = mdate;
807
-
808
- cfg.mn = (cfg.currdate.getTime() < cfg.min_date.getTime()) ?
809
- cfg.min_date.getMonth() : cfg.currdate.getMonth();
810
-
811
- cfg.yy = (cfg.currdate.getTime() < cfg.min_date.getTime()) ?
812
- cfg.min_date.getFullYear() : cfg.currdate.getFullYear();
813
-
814
- return cfg.min_date;
815
- },
816
-
817
- create_title_header: function(params) {
818
- // Creates the header on the yodatepicker.
819
- try {
820
- if(!params.tbody || !params.month || !params.year) {
821
- throw new YoException(params);
822
- }
823
-
824
- var tr_class = 'yo-calendar-title-bar' + params.multi_cal;
825
- var tr = params.tbody.appendChild(
826
- element('tr', { klass: tr_class }));
827
- var yo_id = params.yo_id;
828
-
829
- // previous month navigation element
830
- var prev_style = 'yo-previous-month' + params.multi_cal;
831
- var prev_id = yo_id + '-prev-month' + params.multi_cal + '-' +
832
- params.calendar_number;
833
-
834
- if(cfg.prev_fa_class) {
835
- tr.appendChild(element('td', {klass: prev_style, colspan: '1'}))
836
- .appendChild(element('span', {id: prev_id}))
837
- .appendChild(element('i', {klass: cfg.prev_fa_class}));
838
- } else {
839
- tr.appendChild(element('td', {klass: prev_style, colspan: '1'}))
840
- .appendChild(element('span', {id: prev_id}))
841
- .appendChild(text('<'));
842
- }
843
-
844
- // month name element
845
- var text_style = 'yo-calendar-month' + params.multi_cal;
846
- tr.appendChild(element('td', {klass: text_style, colspan: '5'}))
847
- .appendChild(text(params.month + ' ' + params.year));
848
-
849
- // next month navigation element
850
- var next_style = 'yo-next-month' + params.multi_cal;
851
- var next_id = yo_id + '-next-month' + params.multi_cal + '-' +
852
- params.calendar_number;
853
- if(cfg.next_fa_class) {
854
- tr.appendChild(element('td', {klass: next_style, colspan: '1'}))
855
- .appendChild(element('span', {id: next_id}))
856
- .appendChild(element('i', {klass: cfg.next_fa_class}));
857
- } else {
858
- tr.appendChild(element('td', {klass: next_style, colspan: '1'}))
859
- .appendChild(element('span', {id: next_id}))
860
- .appendChild(text('>'));
861
- }
862
-
863
- // suppress inner nav buttons
864
- if(params.calendar_number > 0) {
865
- prev_id = 'yo-previous-month' + params.multi_cal;
866
- document.getElementsByClassName(prev_id)[1].innerHTML = '';
867
- document.getElementsByClassName(prev_id)[1].style.cursor = 'default';
868
- next_id = 'yo-next-month' + params.multi_cal;
869
- document.getElementsByClassName(next_id)[0].innerHTML = '';
870
- document.getElementsByClassName(next_id)[0].style.cursor = 'default';
871
- }
872
- } catch(e) {
873
- console.log(e.toString());
874
- return false;
875
- }
876
- return true;
877
- },
878
-
879
- create_dow_header: function(params) {
880
- // Creates the day-of-week header for yodatepicker.
881
- try {
882
- if(!params.tbody) { throw new YoException(params.tbody); }
883
- var tr = params.tbody.appendChild(element('tr'));
884
- var td_class = 'yo-calendar-dow-title' + params.multi_cal;
885
- for(var i = 0; i < cfg.day_names.length; i++) {
886
- tr.appendChild(element('td', {klass: td_class}))
887
- .appendChild(text(cfg.day_names[i]));
888
- }
889
- } catch(e) {
890
- console.log(e.toString());
891
- return false;
892
- }
893
- return true;
894
- },
895
-
896
- create_empty_week: function(tbody_node) {
897
- // Creates an entire week with empty days.
898
- try {
899
- if(!tbody_node) { throw new YoException(tbody_node); }
900
- var multi_cal = (cfg.months_to_display > 1) ? '-multi' : '';
901
- var td_class = 'yo-datepicker-day-empty' + multi_cal;
902
- var tr = tbody_node.appendChild(element('tr'));
903
- for(var i = 0; i < 7; i++) {
904
- tr.appendChild(element('td', {klass: td_class}))
905
- .appendChild(text(' '));
906
- }
907
- } catch(e) {
908
- console.log(e.toString());
909
- return false;
910
- }
911
- return true;
912
- },
913
-
914
- create_day: function(tr, content, _id, _klass) {
915
- // Styles for a single day (cell) should be one of these classes:
916
- //
917
- // .yo-datepicker-day // day is selectable
918
- // .yo-datepicker-day-current // day is the current day
919
- // .yo-datepicker-day-empty // empty content
920
- // .yo-datepicker-day-noselect // day is not selectable
921
- //
922
- // .yo-datepicker-day-multi // day is selectable
923
- // .yo-datepicker-day-current-multi // day is the current day
924
- // .yo-datepicker-day-empty-multi // empty content
925
- // .yo-datepicker-day-noselect-multi // day is not selectable
926
- try {
927
- tr.appendChild(element('td', {klass: _klass, id: _id}))
928
- .appendChild(text(content));
929
- } catch(e) {
930
- console.log(e.toString());
931
- return false;
932
- }
933
- return true;
934
- },
935
-
936
- create_month_calendar: function(params) {
937
- var tbody_node = false;
938
- for(var i = 0; i < cfg.months_to_display; i++) {
939
- var table_class = 'yo-calendar' + params.multi_cal;
940
- tbody_node = params.td_node
941
- .appendChild(element('table', {klass: table_class}))
942
- .appendChild(element('tbody'));
943
-
944
- citem.day = 1;
945
- citem.month = cfg.mn;
946
- citem.year = cfg.yy;
947
-
948
- if(i > 0) {
949
- if(cfg.mn < 11) { citem.month = cfg.mn +1; }
950
- else { citem.month = 0; citem.year = cfg.yy +1; }
951
- }
952
-
953
- cfg.currdate.setDate(1); // set day of month to the 1st
954
- cfg.currdate.setMonth(citem.month); // set the month
955
- cfg.currdate.setFullYear(citem.year); // set to 4-digit year
956
-
957
- citem.offset = 0;
958
- citem.first_dow = cfg.currdate.getDay(); // 0 - 6 (sun - sat)
959
- citem.total_days = days_in_month(cfg.currdate.getMonth(),
960
- cfg.currdate.getFullYear());
961
-
962
- this.create_title_header({
963
- tbody: tbody_node,
964
- month: cfg.month_names[citem.month],
965
- year: citem.year,
966
- calendar_number: i,
967
- multi_cal: params.multi_cal,
968
- yo_id: params.yo_id
969
- });
970
-
971
- this.create_dow_header({
972
- tbody: tbody_node,
973
- multi_cal: params.multi_cal
974
- });
975
-
976
- var weeks_created = 0;
977
- for(var j = 0; j < 6; j++) {
978
- if(citem.first_dow === 999) { break; }
979
- var yo_tbody_tr = tbody_node.appendChild(element('tr'));
980
- for(var k = 0; k < 7; k++) {
981
- citem.markup({
982
- yo_id: params.yo_id,
983
- tr_node: yo_tbody_tr,
984
- multi_cal: params.multi_cal
985
- });
986
- }
987
- weeks_created++;
988
- }
989
-
990
- // Output empty rows if needed so we have 6 rows total.
991
- for(var b = 0; b < (6-weeks_created); b++) {
992
- this.create_empty_week(tbody_node);
993
- }
994
- }
995
- return tbody_node;
996
- },
997
-
998
- set_custom_nav_colors: function(css_ext) {
999
- if(cfg.prev_month_nav_color) {
1000
- var klass_name = 'yo-previous-month' + css_ext;
1001
- var items = document.getElementsByClassName(klass_name);
1002
- for(var i = 0; i < items.length; i++) {
1003
- items[i].style.color = cfg.prev_month_nav_color;
1004
- }
1005
- }
1006
-
1007
- if(cfg.next_month_nav_color) {
1008
- var klass_name = 'yo-next-month' + css_ext;
1009
- var items = document.getElementsByClassName(klass_name);
1010
- for(var i = 0; i < items.length; i++) {
1011
- items[i].style.color = cfg.next_month_nav_color;
1012
- }
1013
- }
1014
- },
1015
-
1016
- /* jshint loopfunc: true */
1017
- set_custom_day_colors: function(css_ext) {
1018
- var td_item = 'yo-datepicker-day' + css_ext;
1019
- var rate_item = 'yo-rate-item';
1020
- var curr_item = 'yo-datepicker-day-current' + css_ext;
1021
-
1022
- if(cfg.day_mouseover_bgcolor && cfg.day_mouseover_fgcolor) {
1023
- // when mouseover this element change colors
1024
- var items = document.getElementsByClassName(td_item);
1025
- for(var i = 0; i < items.length; i++) {
1026
- var elem = document.getElementById(items[i].id);
1027
- if(!elem) { continue; }
1028
- elem.style.color = cfg.selected_rate_color;
1029
- elem.style.backgroundColor = cfg.day_mouseleave_bgcolor;
1030
- // yo-rate-item
1031
- var item = elem.getElementsByClassName(rate_item);
1032
- if(item[0]) {
1033
- item[0].style.color = cfg.selected_rate_color;
1034
- }
1035
- // Mouse over event: setup colors
1036
- items[i].onmouseover = function(event) {
1037
- var id = event.srcElement.id;
1038
- if(!id) { id = event.srcElement.parentElement.id; }
1039
- var el = document.getElementById(id);
1040
- if(!el) { return; }
1041
- el.style.color = cfg.selected_rate_color;
1042
- el.style.backgroundColor = cfg.day_mouseover_bgcolor;
1043
- // yo-rate-item
1044
- var item = el.getElementsByClassName(rate_item);
1045
- if(item[0]) {
1046
- item[0].style.color = cfg.selected_rate_color;
1047
- }
1048
- };
1049
- }
1050
-
1051
- // changing colors of day-current on mouseover
1052
- var elem_curr = document.getElementsByClassName(curr_item)[0];
1053
- if(elem_curr) {
1054
- elem_curr.style.color = cfg.selected_rate_color;
1055
- elem_curr.style.backgroundColor = cfg.day_mouseleave_bgcolor;
1056
- elem_curr.onmouseover = function(event) {
1057
- var id = event.srcElement.id;
1058
- if(!id) { id = event.srcElement.parentElement.id; }
1059
-
1060
- var el = document.getElementById(id);
1061
- if(el) {
1062
- el.style.color = cfg.selected_rate_color;
1063
- el.style.backgroundColor = cfg.day_mouseover_bgcolor;
1064
- }
1065
-
1066
- // yo-rate-item
1067
- var item = el.getElementsByClassName(rate_item);
1068
- if(item[0]) {
1069
- item[0].style.color = cfg.selected_rate_color;
1070
- }
1071
- };
1072
- }
1073
- }
1074
-
1075
- if(cfg.day_mouseleave_bgcolor && cfg.day_mouseleave_fgcolor) {
1076
- // yo-rate-item: setup foreground color on all elements
1077
- var items = document.getElementsByClassName(rate_item);
1078
-
1079
- // when mouseleave this element change colors
1080
- items = document.getElementsByClassName(td_item);
1081
- for(var i = 0; i < items.length; i++) {
1082
- // Mouse leave event: setup colors
1083
- items[i].onmouseleave = function(event) {
1084
- var id = event.srcElement.id;
1085
- if(!id) { id = event.srcElement.parentElement.id; }
1086
- var elem = document.getElementById(id);
1087
- if(!elem) { return; }
1088
- elem.style.color = cfg.selected_rate_color;
1089
- elem.style.backgroundColor = cfg.day_mouseleave_bgcolor;
1090
- // yo-rate-item
1091
- var item = elem.getElementsByClassName(rate_item);
1092
- if(item[0]) {
1093
- item[0].style.color = cfg.selected_rate_color;
1094
- }
1095
- };
1096
- }
1097
-
1098
- // changing colors of day-current on mouseleave
1099
- var elem_curr = document.getElementsByClassName(curr_item)[0];
1100
- if(elem_curr) {
1101
- elem_curr.onmouseleave = function(event) {
1102
- var id = event.srcElement.id;
1103
- if(!id) { id = event.srcElement.parentElement.id; }
1104
-
1105
- var elem = document.getElementById(id);
1106
- if(elem) {
1107
- elem.style.color = cfg.selected_rate_color;
1108
- elem.style.backgroundColor = cfg.day_mouseleave_bgcolor;
1109
- }
1110
-
1111
- // yo-rate-item
1112
- var item = elem.getElementsByClassName(rate_item);
1113
- if(item[0]) {
1114
- item[0].style.color = cfg.selected_rate_color;
1115
- }
1116
- };
1117
- }
1118
- }
1119
- },
1120
- /* jshint loopfunc: false */
1121
-
1122
- show: function() {
1123
- var yo_id = 'yo-' + cfg.dp_id_name;
1124
- var root_node = document.getElementById(cfg.dp_id_name);
1125
- var css_ext = (cfg.months_to_display > 1) ? '-multi' : '';
1126
-
1127
- if(!root_node) { throw new YoException(root_node); }
1128
-
1129
- if(document.getElementById(yo_id)) {
1130
- remove_element(root_node, yo_id);
1131
- }
1132
-
1133
- var td_node = root_node
1134
- .appendChild(element('table', {id: yo_id, klass: 'yo-content'}))
1135
- .appendChild(element('tbody')).appendChild(element('tr'))
1136
- .appendChild(element('td'));
1137
-
1138
- this.create_month_calendar({
1139
- td_node: td_node,
1140
- yo_id: yo_id,
1141
- multi_cal: css_ext
1142
- });
1143
-
1144
- this.set_custom_nav_colors(css_ext);
1145
- this.set_custom_day_colors(css_ext);
1146
-
1147
- this.highlight_selected_dates(
1148
- cfg.current_start_date, cfg.current_stop_date
1149
- );
1150
-
1151
- // Attach event listeners for the previous and next buttons.
1152
- var prev_month_id = yo_id + '-prev-month' + css_ext + '-';
1153
- var next_month_id = yo_id + '-next-month' + css_ext + '-';
1154
- var elem;
1155
- for(var x = 0; x < cfg.months_to_display; x++) {
1156
- elem = document.getElementById(prev_month_id + x);
1157
- if(elem) {
1158
- elem.onclick = month_dec;
1159
- elem.style.display = 'block';
1160
- }
1161
-
1162
- elem = document.getElementById(next_month_id + x);
1163
- if(elem) {
1164
- elem.onclick = month_inc;
1165
- elem.style.display = 'block';
1166
- }
1167
- }
1168
-
1169
- // Attach event listeners to the following events so that the
1170
- // datepicker will close when the user clicks outside the calendar.
1171
- document.getElementsByTagName('body')[0]
1172
- .onmousedown = close_datepicker;
1173
-
1174
- // Event onmouseover is set to disable onmousedown so that when
1175
- // mouseover the datepicker, mousedown doesn't close it.
1176
- document.getElementById(yo_id).onmouseover = function(e) {
1177
- // IE 7-8 does not support event.currentTarget but does
1178
- // so for event.srcElement;
1179
- var elem, elem_id, ev = e || window.event;
1180
-
1181
- try { elem = ev.currentTarget; }
1182
- catch(err) { elem = ev.srcElement; }
1183
-
1184
- try { elem_id = elem.id; }
1185
- catch(err) { elem_id = (elem) ? elem : yo_id; }
1186
-
1187
- if(elem_id) {
1188
- document.getElementById(elem_id).onmouseover = function() {
1189
- document.getElementsByTagName('body')[0]
1190
- .onmousedown = null;
1191
- };
1192
- }
1193
- document.getElementsByTagName('body')[0].onmousedown = null;
1194
- };
1195
-
1196
- // Event onmouseout is set to close_datepicker.
1197
- document.getElementById(yo_id).onmouseout = function(e) {
1198
- // IE 7-8 does not support event.currentTarget but does
1199
- // so for event.srcElement;
1200
- var elem, elem_id, ev = e || window.event;
1201
-
1202
- try { elem = ev.currentTarget; }
1203
- catch(err) { elem = ev.srcElement; }
1204
-
1205
- try { elem_id = elem.id; }
1206
- catch(err) { elem_id = (elem) ? elem : yo_id; }
1207
-
1208
- if(elem_id) {
1209
- document.getElementById(elem_id).onmouseout = function() {
1210
- document.getElementsByTagName('body')[0]
1211
- .onmousedown = close_datepicker;
1212
- };
1213
- }
1214
- document.getElementsByTagName('body')[0]
1215
- .onmousedown = close_datepicker;
1216
- };
1217
-
1218
- // Bind event listeners to each day for the onclick event.
1219
- // Get an array of elements by the class name so we can get
1220
- // each element id name to bind the onclick handler.
1221
- var day_selectors = 'yo-datepicker-day' + css_ext;
1222
- var day_tds = document.getElementsByClassName(day_selectors);
1223
- for(var y = 0; y < day_tds.length; y++) {
1224
- // string to match: 'yo-rates_calendar_id_9_22_2014'
1225
- // Split on '_' then we can use the last three elements.
1226
- var items = day_tds[y].id.split('_');
1227
- var mmtmp = items[items.length -3];
1228
- var ddtmp = items[items.length -2];
1229
- var yytmp = items[items.length -1];
1230
- var t_id = yo_id + '_' + mmtmp + '_' + ddtmp + '_' + yytmp;
1231
- var s = 'document.getElementById("' + t_id + '")' +
1232
- '.onclick = function() { select_date(' +
1233
- mmtmp + ',' + ddtmp + ',' + yytmp + '); };';
1234
- if(document.getElementById(t_id)) {
1235
- /* jshint evil: true */
1236
- eval(s);
1237
- /* jshint evil: false */
1238
- }
1239
- }
1240
-
1241
- // The current day node will have a different class name so
1242
- // we get that and bind the onclick handler.
1243
- var selector = 'yo-datepicker-day-current' + css_ext;
1244
- var curr_day_td = document.getElementsByClassName(selector);
1245
- if(curr_day_td.length > 0) {
1246
- var items = curr_day_td[0].id.split('_');
1247
- var mmtmp = items[items.length -3];
1248
- var ddtmp = items[items.length -2];
1249
- var yytmp = items[items.length -1];
1250
- var t_id = yo_id + '_' + mmtmp + '_' + ddtmp + '_' + yytmp;
1251
- var s = 'document.getElementById("' + t_id + '")' +
1252
- '.onclick = function() ' + '{ select_date(' +
1253
- mmtmp + ',' + ddtmp + ',' + yytmp + '); };';
1254
- if(document.getElementById(t_id)) {
1255
- /* jshint evil: true */
1256
- eval(s);
1257
- /* jshint evil: false */
1258
- }
1259
- }
1260
-
1261
- return true;
1262
- }
1263
- };
1264
-
1265
- return _yodatepicker;
1266
- };