PageSourceSearch

https://besorassociates.com/js/wforms_calendar.js

js besorassociates.com collected 2026-10-07 11:04:08 UTC 3,604 bytes, 124 lines download raw bytes

1(function() {
2	
3	if(typeof Kalendae == 'undefined') { return false; }
4	
5	if(!wFORMS.helpers.calendar) {wFORMS.helpers.calendar = {}};
6	wFORMS.helpers.calendar.alreadyApplied = false;
7    
8	wFORMS.behaviors.calendar = {
9		CSS_SELECTOR : ".validate-datecal",
10		target: null,
11
12		applyTo: function(form) {
13			var instances = []
14			// Save reference to the form to find validation behavior later
15			// becuase repeted sections call applyTo we only need to store the value once
16			if (this.target == null) { this.target = form }
17
18			this.generateDefaultSettings();
19
20
21           Kalendae.moment.lang('zz',{
22            months: cfg.MONTHS_LONG, weekdaysMin: cfg.WEEKDAYS_SHORT
23           });
24
25			var elems = base2.DOM.Element.querySelectorAll(form, this.CSS_SELECTOR);
26			for(var i = 0; i<elems.length; i++) {
27				instances.push(new wFORMS.behaviors.calendar.instance(elems.item(i)));	
28			}
29
30			return instances;
31		},
32		
33		generateDefaultSettings : function(){
34			var locale = [];
35				
36		    try{
37				cfg =  wFORMS.helpers.calendar.locale;
38			}catch(e){
39				// default locale settings
40				cfg = {
41					MDY_DAY_POSITION : 1,
42					MDY_MONTH_POSITION : 2,
43					MDY_YEAR_POSITION : 3,
44					DATE_FIELD_DELIMITER : '/'
45				}
46			}
47			for(var field in cfg) {
48				if (field.match(/position/i)){
49					switch (field.match(/_(.*)_/)[1]){
50						case "DAY":
51							val = 'DD';
52							break;
53						case "MONTH":
54							val = 'MM';
55							break;
56						case "YEAR":
57							val = 'YYYY';
58							break;
59					}
60					locale[cfg[field]-1] = val;
61				}
62			}			
63
64			// set to the object:
65			wFORMS.behaviors.calendar.instance.prototype.defaultOptions = {
66				// For full list of options see: 
67				// https://github.com/ChiperSoft/Kalendae
68				format: locale.join(cfg.DATE_FIELD_DELIMITER),
69				selection: 'single',
70				weekStart: cfg.START_WEEKDAY,
71				side: 'bottom',
72				dayOutOfMonthClickable: true
73			}
74		}
75	}
76	
77	// Individual instances of the calendar behavior	
78	wFORMS.behaviors.calendar.instance =  function(elem){
79		var _self = this;
80		this.elem = elem;
81
82		this.cal = new Kalendae.Input(elem,this.defaultOptions);
83
84		this.cal.subscribe('show',function(){
85			wFORMS.behaviors.calendar.instance.prototype.updateRange(_self.elem,_self.cal);
86		})
87	}
88
89	// Placeholder for default options for the Kalendae object.
90	wFORMS.behaviors.calendar.instance.prototype.defaultOptions = {};
91
92	// Generates and installs function that allows only valid dates to be selected
93	wFORMS.behaviors.calendar.instance.prototype.updateRange = function(elem, cal){
94		var validation = wFORMS.getBehaviorInstance(wFORMS.behaviors.calendar.target,'validation');
95
96		if(elem.getAttribute(wFORMS.behaviors.validation.LOWER_BOUND_ATTRIBUTE)) {
97			var min = validation.analyzeDateComponents(elem.getAttribute(wFORMS.behaviors.validation.LOWER_BOUND_ATTRIBUTE));
98		}
99		if(elem.getAttribute(wFORMS.behaviors.validation.UPPER_BOUND_ATTRIBUTE)) {
100			var max = validation.analyzeDateComponents(elem.getAttribute(wFORMS.behaviors.validation.UPPER_BOUND_ATTRIBUTE));
101		}
102
103		// if there is any limit go ahead and set the blackout
104		cal.blackout = function(d){
105			if (min && (d.startOf('day').unix()*1000 < min.getTime())) {
106				return true;
107			}
108			if (max && (d.startOf('day').unix()*1000 > max.getTime())) {
109				return true;
110			}
111			return false;
112		}
113
114		// show user middle of allowed range
115		if((min && max) && (min.getTime() < max.getTime())) {
116			var middleRange = new Date();
117			middleRange.setTime(((max.getTime() - min.getTime())/2 ) + min.getTime());
118
119			cal.viewStartDate = Kalendae.moment(middleRange);
120		}
121
122		cal.draw(); // update pop-up with changes
123	};
124})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.