-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjsuites.js
8748 lines (7548 loc) · 273 KB
/
jsuites.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* (c) jSuites Javascript Web Components (v3.8.3)
*
* Author: Paul Hodel <[email protected]>
* Website: https://bossanova.uk/jsuites/
* Description: Create amazing web based applications.
*
* MIT License
*
*/
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.jSuites = factory();
}(this, (function () {
'use strict';
var jSuites = function(options) {
var obj = {}
obj.init = function() {
}
return obj;
}
jSuites.ajax = (function(options, complete) {
if (Array.isArray(options)) {
// Create multiple request controller
var multiple = {
instance: [],
complete: complete,
}
if (options.length > 0) {
for (var i = 0; i < options.length; i++) {
options[i].multiple = multiple;
multiple.instance.push(jSuites.ajax(options[i]));
}
}
return multiple;
}
if (! options.data) {
options.data = {};
}
if (options.type) {
options.method = options.type;
}
// Default method
if (! options.method) {
options.method = 'GET';
}
// Default type
if (! options.dataType) {
options.dataType = 'json';
}
if (options.data) {
// Parse object to variables format
var parseData = function(value, key) {
var vars = [];
var keys = Object.keys(value);
if (keys.length) {
for (var i = 0; i < keys.length; i++) {
if (key) {
var k = key + '[' + keys[i] + ']';
} else {
var k = keys[i];
}
if (typeof(value[keys[i]]) == 'object') {
var r = parseData(value[keys[i]], k);
var o = Object.keys(r);
for (var j = 0; j < o.length; j++) {
vars[o[j]] = r[o[j]];
}
} else {
vars[k] = value[keys[i]];
}
}
}
return vars;
}
var data = [];
var d = parseData(options.data);
var k = Object.keys(d);
for (var i = 0; i < k.length; i++) {
data.push(k[i] + '=' + encodeURIComponent(d[k[i]]));
}
if (options.method == 'GET' && data.length > 0) {
if (options.url.indexOf('?') < 0) {
options.url += '?';
}
options.url += data.join('&');
}
}
var httpRequest = new XMLHttpRequest();
httpRequest.open(options.method, options.url, true);
httpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if (options.method == 'POST') {
httpRequest.setRequestHeader('Accept', 'application/json');
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
} else {
if (options.dataType == 'json') {
httpRequest.setRequestHeader('Content-Type', 'text/json');
}
}
// No cache
if (options.cache != true) {
httpRequest.setRequestHeader('pragma', 'no-cache');
httpRequest.setRequestHeader('cache-control', 'no-cache');
}
// Authentication
if (options.withCredentials == true) {
httpRequest.withCredentials = true
}
// Before send
if (typeof(options.beforeSend) == 'function') {
options.beforeSend(httpRequest);
}
httpRequest.onload = function() {
if (httpRequest.status === 200) {
if (options.dataType == 'json') {
try {
var result = JSON.parse(httpRequest.responseText);
if (options.success && typeof(options.success) == 'function') {
options.success(result);
}
} catch(err) {
if (options.error && typeof(options.error) == 'function') {
options.error(err, result);
}
}
} else {
var result = httpRequest.responseText;
if (options.success && typeof(options.success) == 'function') {
options.success(result);
}
}
} else {
if (options.error && typeof(options.error) == 'function') {
options.error(httpRequest.responseText);
}
}
// Global queue
if (jSuites.ajax.queue && jSuites.ajax.queue.length > 0) {
jSuites.ajax.send(jSuites.ajax.queue.shift());
}
// Global complete method
if (jSuites.ajax.requests && jSuites.ajax.requests.length) {
// Get index of this request in the container
var index = jSuites.ajax.requests.indexOf(httpRequest);
// Remove from the ajax requests container
jSuites.ajax.requests.splice(index, 1);
// Last one?
if (! jSuites.ajax.requests.length) {
if (options.complete && typeof(options.complete) == 'function') {
options.complete(result);
}
}
// Controllers
if (options.multiple && options.multiple.instance) {
// Get index of this request in the container
var index = options.multiple.instance.indexOf(httpRequest);
// Remove from the ajax requests container
options.multiple.instance.splice(index, 1);
// If this is the last one call method complete
if (! options.multiple.instance.length) {
if (options.multiple.complete && typeof(options.multiple.complete) == 'function') {
options.multiple.complete(result);
}
}
}
}
}
// Data
httpRequest.data = data;
// Queue
if (options.queue == true && jSuites.ajax.requests.length > 0) {
jSuites.ajax.queue.push(httpRequest);
} else {
jSuites.ajax.send(httpRequest)
}
return httpRequest;
});
jSuites.ajax.send = function(httpRequest) {
if (httpRequest.data) {
httpRequest.send(httpRequest.data.join('&'));
} else {
httpRequest.send();
}
jSuites.ajax.requests.push(httpRequest);
}
jSuites.ajax.exists = function(url, __callback) {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
if (http.status) {
__callback(http.status);
}
}
jSuites.ajax.requests = [];
jSuites.ajax.queue = [];
jSuites.alert = function(message) {
if (jSuites.getWindowWidth() < 800 && jSuites.dialog) {
jSuites.dialog.open({
title:'Alert',
message:message,
});
} else {
alert(message);
}
}
jSuites.animation = {};
jSuites.animation.slideLeft = function(element, direction, done) {
if (direction == true) {
element.classList.add('slide-left-in');
setTimeout(function() {
element.classList.remove('slide-left-in');
if (typeof(done) == 'function') {
done();
}
}, 400);
} else {
element.classList.add('slide-left-out');
setTimeout(function() {
element.classList.remove('slide-left-out');
if (typeof(done) == 'function') {
done();
}
}, 400);
}
}
jSuites.animation.slideRight = function(element, direction, done) {
if (direction == true) {
element.classList.add('slide-right-in');
setTimeout(function() {
element.classList.remove('slide-right-in');
if (typeof(done) == 'function') {
done();
}
}, 400);
} else {
element.classList.add('slide-right-out');
setTimeout(function() {
element.classList.remove('slide-right-out');
if (typeof(done) == 'function') {
done();
}
}, 400);
}
}
jSuites.animation.slideTop = function(element, direction, done) {
if (direction == true) {
element.classList.add('slide-top-in');
setTimeout(function() {
element.classList.remove('slide-top-in');
if (typeof(done) == 'function') {
done();
}
}, 400);
} else {
element.classList.add('slide-top-out');
setTimeout(function() {
element.classList.remove('slide-top-out');
if (typeof(done) == 'function') {
done();
}
}, 400);
}
}
jSuites.animation.slideBottom = function(element, direction, done) {
if (direction == true) {
element.classList.add('slide-bottom-in');
setTimeout(function() {
element.classList.remove('slide-bottom-in');
if (typeof(done) == 'function') {
done();
}
}, 400);
} else {
element.classList.add('slide-bottom-out');
setTimeout(function() {
element.classList.remove('slide-bottom-out');
if (typeof(done) == 'function') {
done();
}
}, 100);
}
}
jSuites.animation.fadeIn = function(element, done) {
element.classList.add('fade-in');
setTimeout(function() {
element.classList.remove('fade-in');
if (typeof(done) == 'function') {
done();
}
}, 2000);
}
jSuites.animation.fadeOut = function(element, done) {
element.classList.add('fade-out');
setTimeout(function() {
element.classList.remove('fade-out');
if (typeof(done) == 'function') {
done();
}
}, 1000);
}
jSuites.calendar = (function(el, options) {
var obj = {};
obj.options = {};
// Global container
if (! jSuites.calendar.current) {
jSuites.calendar.current = null;
}
// Default configuration
var defaults = {
// Render type: [ default | year-month-picker ]
type: 'default',
// Restrictions
validRange: null,
// Starting weekday - 0 for sunday, 6 for saturday
startingDay: null,
// Date format
format: 'DD/MM/YYYY',
// Allow keyboard date entry
readonly: false,
// Today is default
today: false,
// Show timepicker
time: false,
// Show the reset button
resetButton: true,
// Placeholder
placeholder: '',
// Translations can be done here
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
monthsFull: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
weekdays: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
weekdays_short: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
textDone: 'Done',
textReset: 'Reset',
textUpdate: 'Update',
// Value
value: null,
// Fullscreen (this is automatic set for screensize < 800)
fullscreen: false,
// Create the calendar closed as default
opened: false,
// Events
onopen: null,
onclose: null,
onchange: null,
onupdate: null,
// Internal mode controller
mode: null,
position: null,
};
// Loop through our object
for (var property in defaults) {
if (options && options.hasOwnProperty(property)) {
obj.options[property] = options[property];
} else {
obj.options[property] = defaults[property];
}
}
// Value
if (! obj.options.value) {
if (el.tagName == 'INPUT' && el.value) {
obj.options.value = el.value;
}
}
// Date
obj.date = null;
if (obj.options.value) {
obj.date = jSuites.calendar.toArray(obj.options.value);
} else {
if (obj.options.today) {
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var h = date.getHours();
var i = date.getMinutes();
obj.date = [ y, m, d, h, i, 0 ];
}
}
// Calendar elements
var calendarReset = document.createElement('div');
calendarReset.className = 'jcalendar-reset';
calendarReset.innerHTML = obj.options.textReset;
var calendarConfirm = document.createElement('div');
calendarConfirm.className = 'jcalendar-confirm';
calendarConfirm.innerHTML = obj.options.textDone;
var calendarControls = document.createElement('div');
calendarControls.className = 'jcalendar-controls'
calendarControls.style.borderBottom = '1px solid #ddd';
if (obj.options.resetButton) {
calendarControls.appendChild(calendarReset);
}
calendarControls.appendChild(calendarConfirm);
var calendarContainer = document.createElement('div');
calendarContainer.className = 'jcalendar-container';
var calendarContent = document.createElement('div');
calendarContent.className = 'jcalendar-content';
calendarContainer.appendChild(calendarContent);
// Main element
if (el.tagName == 'DIV') {
var calendar = el;
calendar.className = 'jcalendar-inline';
} else {
// Add controls to the screen
calendarContent.appendChild(calendarControls);
var calendar = document.createElement('div');
calendar.className = 'jcalendar';
}
calendar.appendChild(calendarContainer);
// Table container
var calendarTableContainer = document.createElement('div');
calendarTableContainer.className = 'jcalendar-table';
calendarContent.appendChild(calendarTableContainer);
// Previous button
var calendarHeaderPrev = document.createElement('td');
calendarHeaderPrev.setAttribute('colspan', '2');
calendarHeaderPrev.className = 'jcalendar-prev';
// Header with year and month
var calendarLabelYear = document.createElement('span');
calendarLabelYear.className = 'jcalendar-year';
var calendarLabelMonth = document.createElement('span');
calendarLabelMonth.className = 'jcalendar-month';
var calendarHeaderTitle = document.createElement('td');
calendarHeaderTitle.className = 'jcalendar-header';
calendarHeaderTitle.setAttribute('colspan', '3');
calendarHeaderTitle.appendChild(calendarLabelMonth);
calendarHeaderTitle.appendChild(calendarLabelYear);
var calendarHeaderNext = document.createElement('td');
calendarHeaderNext.setAttribute('colspan', '2');
calendarHeaderNext.className = 'jcalendar-next';
var calendarHeaderRow = document.createElement('tr');
calendarHeaderRow.appendChild(calendarHeaderPrev);
calendarHeaderRow.appendChild(calendarHeaderTitle);
calendarHeaderRow.appendChild(calendarHeaderNext);
var calendarHeader = document.createElement('thead');
calendarHeader.appendChild(calendarHeaderRow);
var calendarBody = document.createElement('tbody');
var calendarFooter = document.createElement('tfoot');
// Calendar table
var calendarTable = document.createElement('table');
calendarTable.setAttribute('cellpadding', '0');
calendarTable.setAttribute('cellspacing', '0');
calendarTable.appendChild(calendarHeader);
calendarTable.appendChild(calendarBody);
calendarTable.appendChild(calendarFooter);
calendarTableContainer.appendChild(calendarTable);
var calendarSelectHour = document.createElement('select');
calendarSelectHour.className = 'jcalendar-select';
calendarSelectHour.onchange = function() {
obj.date[3] = this.value;
// Event
if (typeof(obj.options.onupdate) == 'function') {
obj.options.onupdate(el, obj.getValue());
}
}
for (var i = 0; i < 24; i++) {
var element = document.createElement('option');
element.value = i;
element.innerHTML = jSuites.two(i);
calendarSelectHour.appendChild(element);
}
var calendarSelectMin = document.createElement('select');
calendarSelectMin.className = 'jcalendar-select';
calendarSelectMin.onchange = function() {
obj.date[4] = this.value;
// Event
if (typeof(obj.options.onupdate) == 'function') {
obj.options.onupdate(el, obj.getValue());
}
}
for (var i = 0; i < 60; i++) {
var element = document.createElement('option');
element.value = i;
element.innerHTML = jSuites.two(i);
calendarSelectMin.appendChild(element);
}
// Footer controls
var calendarControlsFooter = document.createElement('div');
calendarControlsFooter.className = 'jcalendar-controls';
var calendarControlsTime = document.createElement('div');
calendarControlsTime.className = 'jcalendar-time';
calendarControlsTime.style.maxWidth = '140px';
calendarControlsTime.appendChild(calendarSelectHour);
calendarControlsTime.appendChild(calendarSelectMin);
var calendarControlsUpdateButton = document.createElement('input');
calendarControlsUpdateButton.setAttribute('type', 'button');
calendarControlsUpdateButton.className = 'jcalendar-update';
calendarControlsUpdateButton.value = obj.options.textUpdate;
var calendarControlsUpdate = document.createElement('div');
calendarControlsUpdate.style.flexGrow = '10';
calendarControlsUpdate.appendChild(calendarControlsUpdateButton);
calendarControlsFooter.appendChild(calendarControlsTime);
// Only show the update button for input elements
if (el.tagName == 'INPUT') {
calendarControlsFooter.appendChild(calendarControlsUpdate);
}
calendarContent.appendChild(calendarControlsFooter);
var calendarBackdrop = document.createElement('div');
calendarBackdrop.className = 'jcalendar-backdrop';
calendar.appendChild(calendarBackdrop);
// Update actions button
var updateActions = function() {
var currentDay = calendar.querySelector('.jcalendar-selected');
if (currentDay && currentDay.classList.contains('jcalendar-disabled')) {
calendarControlsUpdateButton.setAttribute('disabled', 'disabled');
calendarSelectHour.setAttribute('disabled', 'disabled');
calendarSelectMin.setAttribute('disabled', 'disabled');
} else {
calendarControlsUpdateButton.removeAttribute('disabled');
calendarSelectHour.removeAttribute('disabled');
calendarSelectMin.removeAttribute('disabled');
}
}
/**
* Open the calendar
*/
obj.open = function (value) {
if (! calendar.classList.contains('jcalendar-focus')) {
if (! calendar.classList.contains('jcalendar-inline')) {
obj.getDays();
// Get content
if (obj.options.type == 'year-month-picker') {
obj.getMonths();
}
// Get time
if (obj.options.time) {
calendarSelectHour.value = obj.date[3];
calendarSelectMin.value = obj.date[4];
}
if (jSuites.calendar.current) {
jSuites.calendar.current.close();
}
// Current
jSuites.calendar.current = obj;
// Show calendar
calendar.classList.add('jcalendar-focus');
// Get the position of the corner helper
if (jSuites.getWindowWidth() < 800 || obj.options.fullscreen) {
// Full
calendar.classList.add('jcalendar-fullsize');
// Animation
jSuites.animation.slideBottom(calendarContent, 1);
} else {
var rect = el.getBoundingClientRect();
var rectContent = calendarContent.getBoundingClientRect();
if (obj.options.position) {
calendarContainer.style.position = 'fixed';
if (window.innerHeight < rect.bottom + rectContent.height) {
calendarContainer.style.top = (rect.top - (rectContent.height + 2)) + 'px';
} else {
calendarContainer.style.top = (rect.top + rect.height + 2) + 'px';
}
calendarContainer.style.left = rect.left + 'px';
} else {
if (window.innerHeight < rect.bottom + rectContent.height) {
calendarContainer.style.bottom = (1 * rect.height + rectContent.height + 2) + 'px';
} else {
calendarContainer.style.top = 2 + 'px';
}
}
}
// Events
if (typeof(obj.options.onopen) == 'function') {
obj.options.onopen(el);
}
}
}
}
obj.close = function (ignoreEvents, update) {
if (jSuites.calendar.current) {
// Current
jSuites.calendar.current = null;
if (update !== false) {
var element = calendar.querySelector('.jcalendar-selected');
if (typeof(update) == 'string') {
var value = update;
} else if (! element || element.classList.contains('jcalendar-disabled')) {
var value = obj.options.value
} else {
var value = obj.getValue();
}
obj.setValue(value);
}
// Events
if (! ignoreEvents && typeof(obj.options.onclose) == 'function') {
obj.options.onclose(el);
}
// Hide
calendar.classList.remove('jcalendar-focus');
}
return obj.options.value;
}
obj.prev = function() {
// Check if the visualization is the days picker or years picker
if (obj.options.mode == 'years') {
obj.date[0] = obj.date[0] - 12;
// Update picker table of days
obj.getYears();
} else if (obj.options.mode == 'months') {
obj.date[0] = parseInt(obj.date[0]) - 1;
// Update picker table of months
obj.getMonths();
} else {
// Go to the previous month
if (obj.date[1] < 2) {
obj.date[0] = obj.date[0] - 1;
obj.date[1] = 12;
} else {
obj.date[1] = obj.date[1] - 1;
}
// Update picker table of days
obj.getDays();
}
}
obj.next = function() {
// Check if the visualization is the days picker or years picker
if (obj.options.mode == 'years') {
obj.date[0] = parseInt(obj.date[0]) + 12;
// Update picker table of days
obj.getYears();
} else if (obj.options.mode == 'months') {
obj.date[0] = parseInt(obj.date[0]) + 1;
// Update picker table of months
obj.getMonths();
} else {
// Go to the previous month
if (obj.date[1] > 11) {
obj.date[0] = parseInt(obj.date[0]) + 1;
obj.date[1] = 1;
} else {
obj.date[1] = parseInt(obj.date[1]) + 1;
}
// Update picker table of days
obj.getDays();
}
}
obj.setValue = function(val) {
if (! val) {
val = '' + val;
}
// Values
var newValue = val;
var oldValue = obj.options.value;
if (oldValue != newValue) {
// Set label
var value = obj.setLabel(newValue, obj.options);
var date = newValue.split(' ');
if (! date[1]) {
date[1] = '00:00:00';
}
var time = date[1].split(':')
var date = date[0].split('-');
var y = parseInt(date[0]);
var m = parseInt(date[1]);
var d = parseInt(date[2]);
var h = parseInt(time[0]);
var i = parseInt(time[1]);
obj.date = [ y, m, d, h, i, 0 ];
var val = obj.setLabel(newValue, obj.options);
// New value
obj.options.value = newValue;
if (typeof(obj.options.onchange) == 'function') {
obj.options.onchange(el, newValue, oldValue);
}
// Lemonade JS
if (el.value != val) {
el.value = val;
if (typeof(el.onchange) == 'function') {
el.onchange({
type: 'change',
target: el,
value: el.value
});
}
}
}
obj.getDays();
}
obj.getValue = function() {
if (obj.date) {
if (obj.options.time) {
return jSuites.two(obj.date[0]) + '-' + jSuites.two(obj.date[1]) + '-' + jSuites.two(obj.date[2]) + ' ' + jSuites.two(obj.date[3]) + ':' + jSuites.two(obj.date[4]) + ':' + jSuites.two(0);
} else {
return jSuites.two(obj.date[0]) + '-' + jSuites.two(obj.date[1]) + '-' + jSuites.two(obj.date[2]) + ' ' + jSuites.two(0) + ':' + jSuites.two(0) + ':' + jSuites.two(0);
}
} else {
return "";
}
}
/**
* Calendar
*/
obj.update = function(element, v) {
if (element.classList.contains('jcalendar-disabled')) {
// Do nothing
} else {
var elements = calendar.querySelector('.jcalendar-selected');
if (elements) {
elements.classList.remove('jcalendar-selected');
}
element.classList.add('jcalendar-selected');
if (element.classList.contains('jcalendar-set-month')) {
obj.date[1] = v;
} else {
obj.date[2] = element.innerText;
}
if (! obj.options.time) {
obj.close();
} else {
obj.date[3] = calendarSelectHour.value;
obj.date[4] = calendarSelectMin.value;
}
// Event
if (typeof(obj.options.onupdate) == 'function') {
obj.options.onupdate(el, obj.getValue());
}
}
// Update
updateActions();
}
/**
* Set to blank
*/
obj.reset = function() {
// Close calendar
obj.setValue('');
obj.close(false, false);
}
/**
* Get calendar days
*/
obj.getDays = function() {
// Mode
obj.options.mode = 'days';
// Setting current values in case of NULLs
var date = new Date();
// Current selection
var year = obj.date && jSuites.isNumeric(obj.date[0]) ? obj.date[0] : parseInt(date.getFullYear());
var month = obj.date && jSuites.isNumeric(obj.date[1]) ? obj.date[1] : parseInt(date.getMonth()) + 1;
var day = obj.date && jSuites.isNumeric(obj.date[2]) ? obj.date[2] : parseInt(date.getDate());
var hour = obj.date && jSuites.isNumeric(obj.date[3]) ? obj.date[3] : parseInt(date.getHours());
var min = obj.date && jSuites.isNumeric(obj.date[4]) ? obj.date[4] : parseInt(date.getMinutes());
// Selection container
obj.date = [ year, month, day, hour, min, 0 ];
// Update title
calendarLabelYear.innerHTML = year;
calendarLabelMonth.innerHTML = obj.options.months[month - 1];
// Current month and Year
var isCurrentMonthAndYear = (date.getMonth() == month - 1) && (date.getFullYear() == year) ? true : false;
var currentDay = date.getDate();
// Number of days in the month
var date = new Date(year, month, 0, 0, 0);
var numberOfDays = date.getDate();
// First day
var date = new Date(year, month-1, 0, 0, 0);
var firstDay = date.getDay() + 1;
// Index value
var index = obj.options.startingDay || 0;
// First of day relative to the starting calendar weekday
firstDay = firstDay - index;
// Reset table
calendarBody.innerHTML = '';
// Weekdays Row
var row = document.createElement('tr');
row.setAttribute('align', 'center');
calendarBody.appendChild(row);
// Create weekdays row
for (var i = 0; i < 7; i++) {
var cell = document.createElement('td');
cell.classList.add('jcalendar-weekday')
cell.innerHTML = obj.options.weekdays_short[index];
row.appendChild(cell);
// Next week day
index++;
// Restart index
if (index > 6) {
index = 0;
}
}
// Index of days
var index = 0;
var d = 0;
// Calendar table
for (var j = 0; j < 6; j++) {
// Reset cells container
var row = document.createElement('tr');
row.setAttribute('align', 'center');
// Data control
var emptyRow = true;
// Create cells
for (var i = 0; i < 7; i++) {
// Create cell
var cell = document.createElement('td');
cell.classList.add('jcalendar-set-day');
if (index >= firstDay && index < (firstDay + numberOfDays)) {
// Day cell
d++;
cell.innerHTML = d;
// Selected
if (d == day) {
cell.classList.add('jcalendar-selected');
}
// Current selection day is today
if (isCurrentMonthAndYear && currentDay == d) {
cell.style.fontWeight = 'bold';
}
// Current selection day
var current = jSuites.calendar.now(new Date(year, month-1, d), true);
// Available ranges
if (obj.options.validRange) {
if (! obj.options.validRange[0] || current >= obj.options.validRange[0]) {
var test1 = true;
} else {
var test1 = false;
}
if (! obj.options.validRange[1] || current <= obj.options.validRange[1]) {
var test2 = true;
} else {
var test2 = false;
}
if (! (test1 && test2)) {
cell.classList.add('jcalendar-disabled');
}
}
// Control
emptyRow = false;
}
// Day cell
row.appendChild(cell);
// Index
index++;
}
// Add cell to the calendar body
if (emptyRow == false) {
calendarBody.appendChild(row);
}
}
// Show time controls
if (obj.options.time) {
calendarControlsTime.style.display = '';
} else {
calendarControlsTime.style.display = 'none';
}
// Update
updateActions();
}
obj.getMonths = function() {
// Mode
obj.options.mode = 'months';
// Loading month labels
var months = obj.options.months;
// Value
var value = obj.options.value;
// Current date
var date = new Date();