PageSourceSearch

https://www.dcstockphotos.com/js/BS/1788533357/0.8.2/BS.com.Calendar.js

js dcstockphotos.com collected 2026-09-30 10:10:06 UTC 10,955 bytes, 491 lines download raw bytes

1BS.com.Calendar = function (obj, key, value)
2{
3	this.mm = new BS.com.Delete('BsCalendar');
4	this.obj = obj;
5	this.key = key;
6	this.val = ['YYYY', '', 'DD'];
7
8	this.param = {
9		showcal:	true,
10		future:		false,
11		eval:		null,
12		zindex:		'100',
13		offset:		[0,0]
14	};
15	
16	this.clearE = this.mm.ceNew('clearEvt', this);
17	this.clearE.addCB(this._clear);
18
19	this.clearFocE = this.mm.ceNew('clearFocEvt', this);
20	this.clearFocE.addCB(this._clearFoc);
21
22	this.setE = this.mm.ceNew('set', this);
23	this.setE.addCB(this._setCB);
24
25	this.date = new Date();
26
27	if (value) this.setVal(value);
28};
29
30BS.com.Calendar.prototype = {
31	f_init:			false,
32	cal:			null,
33
34	_delete: function ()
35	{
36		this.obj = null;
37		delete this.param;
38		delete this.date;
39
40		this.mm._delete();
41	},
42	
43	_calSet: function (y, m, d)
44	{
45		var month = (m.toString().length < 2) ? '0'+m : m;
46		var day = (d.toString().length < 2) ? '0'+d : d;
47		var year = (y.toString().length == 2) ? '19'+y : y;
48	
49		BS.utl.form.setValue(this.yyINP, year);
50		this.mmSEL.setVal(month);
51		BS.utl.form.setValue(this.ddINP, day);
52	},
53
54	_setCB: function (type, data, args)
55	{
56		var		str = args[0];
57
58		var y = str.substr(0, 4);
59		var m = str.substr(5, 2);
60		var d = str.substr(8, 2);
61
62		this._calSet(y, m, d);
63	},
64	
65	_calShow: function (type, data, args) 
66	{
67		var popDate;
68
69		var dd = this.ddINP.value;
70		if (dd.length < 2) dd = '0' + dd;
71
72		var inp = this.yyINP.value + '-' + this.mmSEL.getVal() + '-' + dd;
73
74		if (!inp.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}/))
75			inp = this.date.strftime('%Y-%m-%d');
76
77		if (!this.cal)
78			this.cal = this.mm.oNew(BS.com.Calendar.Popup, this.setE);
79
80		if (this.getParam('future'))
81			this.cal.disableDates(null, this.date);
82
83		if (this.getParam('zindex'))
84			this.cal.setZindex(this.getParam('zindex'));
85
86		if (this.getParam('pos'))
87			this.cal.setPos(this.getParam('pos'));
88
89		this.cal.showLink(inp, this.mmSEL.sel);
90
91		// eval anything in param.eval - sort of a hack,
92		// works with "calopt" argument in smarty
93		if (this.param.eval) eval(this.param.eval);
94	},		
95
96	_draw: function ()
97	{
98		if (this.f_init) return;
99		this.f_init = true;
100
101		var moA = [];
102
103		this.mmSEL = this.mm.oNew(BS.com.Form.Select, this.obj, this.key + '[MM]', ['','']);
104
105		for (var i = 0; i < BS.utl.date.MO_NUM_A.length; i++)
106			moA.push([BS.utl.date.MO_NUM_A[i], BS.utl.date.MO_STR2_A[i]]);
107
108		this.mmSEL.load(moA, true);
109
110		this.ddINP = this.mm.domNew(this.obj, 'input');
111		with (this.ddINP) {
112			setAttribute('name', this.key + '[DD]');
113			setAttribute('size', 3); setAttribute('maxlength', 2);
114		}
115
116		this.yyINP = this.mm.domNew(this.obj, 'input');
117		with (this.yyINP) {
118			setAttribute('name', this.key + '[YYYY]');
119			setAttribute('size', 5); setAttribute('maxlength', 4);
120		}
121
122		this.clearFocE.attach(this.ddINP, 'focus');
123		this.clearFocE.attach(this.yyINP, 'focus');
124
125		// if we do not want to show the pop-up
126		if (this.getParam('showCal') == 'false')
127			return;
128
129		this.calB = this.mm.domNew(this.obj, 'a', 'calB');
130		this.calB.innerHTML = '<img border="0" src="/img/calendar/cal.gif">';
131		this.clearB = this.mm.domNew(this.obj, 'a', 'clearB');
132		this.clearB.innerHTML = '<img border="0" src="/img/calendar/cal-clear.gif">';
133
134		this.calE = this.mm.ceNew('calEvt', this);
135		this.calE.addCB(this._calShow);
136		this.calE.attach(this.calB, 'click');
137
138		this.clearE.attach(this.clearB, 'click');
139	},
140
141	_clear: function ()
142	{
143		this.setVal('');
144		this.show();
145	},
146
147	_clearFoc: function (type, data, args)
148	{
149		var t = BS.utl.event.getTarget(args[0]);
150		t.value = '';
151	},
152
153	/*!\param	Returns parameter value for specified name.
154	* \param	name		name
155	* \return	value
156	*/
157	getParam: function (name)
158	{
159		if (this.param[name]) return this.param[name];
160	},
161	
162	/*!\brief	Sets parameter value for specified name.
163	* \param	name		name
164	* \param	value		value 
165	*/
166	setParam: function (name, value)
167	{
168		if (name == 'className') this.mm.setParam(name, value);
169		else this.param[name] = value;
170	},
171
172	getVal: function ()
173	{
174		var mon = this.mmSEL.getVal();
175		var day = this.ddINP.value;
176		var yr = this.yyINP.value;
177
178		if (yr == '' || yr == 'YYYY') return '';
179
180		if (mon == '') mon = '01';
181		if (day == '' || day == 'DD') day = '01';
182		if (day.length < 2) day = '0' + day;
183
184		this.value = BS.utl.date.toDate(yr + '-' + mon + '-' + day);
185
186		return this.value;
187	},
188
189	setVal: function (value)
190	{
191		var re = new RegExp('^[0-9]{4}-[0-9]{0,2}-[0-9]{0,2}');
192		if (!re.test(value)) {
193			this.value = null;
194			this.val[0] = this.val[1] = this.val[2] = '';
195			return;
196		}
197
198		this.value = BS.utl.date.toDate(value);
199		this.val[0] = this.value.strftime('%Y');
200		this.val[1] = this.value.strftime('%m');
201		this.val[2] = this.value.strftime('%d');
202	},
203
204	/*!\brief	Show widget on the page. */
205	show: function ()
206	{
207		this._draw();
208
209		BS.utl.form.setValue(this.yyINP, this.val[0]);
210		this.mmSEL.setVal(this.val[1]);
211		BS.utl.form.setValue(this.ddINP, this.val[2]);
212	}
213};
214
215BS.com.Calendar.Popup = function (submitE)
216{
217	var			tmp;
218
219	var gvId = BS.utl.mkGvId();
220	BS.utl.gvA[gvId] = this;
221	this.gvStr = 'BS.utl.gvA[' + gvId + ']';
222
223	this.submitE = submitE;
224
225	this.mm = new BS.com.Delete('BsCalendarPopup');
226
227	this.date = new Date();
228	this.pos = [0,0];
229
230	this.obj = this.mm.domNew(document.body, 'div');
231	this.obj.id = BS.utl.dom.mkid();
232
233	if (BS.utl.browser.isIE) {
234		this.ieMask = this.mm.domNew(null, 'iframe', 'BsCalendarPopup');
235		with (this.ieMask) {
236			setAttribute('src', '/com/mask.html');
237			setAttribute('width', '1');
238			setAttribute('height', '1');
239			setAttribute('border', '0');
240			setAttribute('scrolling', 'no');
241		}
242		BS.utl.dom.setStyle(this.ieMask, 'position', 'absolute');
243		BS.utl.dom.setStyle(this.ieMask, 'visibility', 'hidden');
244		BS.utl.dom.setStyle(this.ieMask, 'zIndex', '1');
245		document.body.appendChild(this.ieMask);
246	}
247
248	tmp = this.mm.domNew(this.obj, 'h1');
249	this.prevA = this.mm.domNew(tmp, 'a', 'bscLink bscPrev');
250	this.nextA = this.mm.domNew(tmp, 'a', 'bscLink bscNext');
251	this.prevA.innerHTML = '&lt;'; this.nextA.innerHTML = '&gt;';
252	this.titleSPAN = this.mm.domNew(tmp, 'span');
253
254	tmp = this.mm.domNew(this.obj, 'ul', 'bscCal bscCalHead');
255	tmp.innerHTML = '<li>S</li><li>M</li><li>T</li><li>W</li><li>T</li><li>F</li><li>S</li>';
256
257	this.UL = this.mm.domNew(this.obj, 'ul', 'bscCal');
258
259	this.clickE = BS.utl.mm.ceNew(null, this);
260	this.clickE.addCB(this._click);
261	this.clickE.attach(this.prevA, 'click');
262	this.clickE.attach(this.nextA, 'click');
263
264	this.bodyE = BS.utl.mm.ceNew(null, this);
265	this.bodyE.addCB(this._body);
266};
267
268BS.com.Calendar.Popup.prototype = {
269	curDate:		null,
270	setDate:		null,
271	sD:			null,
272	eD:			null,
273	pos:			null,
274
275	_delete: function ()
276	{
277		this.bodyE.attach(document.body, 'click');
278		this.submitE = this.curDate = this.setDate = null;
279		delete this.date;
280		delete this.pos;
281		this.mm._delete;
282	},
283
284	/*!\brief    Returns an array the day of the week the specified month starts
285	 *	     and the number of days in the specified month.
286	 * \param    year        4 digit year
287	 * \param    month        month (1-12)
288	 */
289	_dateDayCnt: function (date)
290	{
291		var		d = new Date;
292		var		r = [];
293
294		var		month = date.getUTCMonth();
295		var		year = date.getUTCFullYear();
296
297		d.setUTCFullYear(year);
298		d.setUTCMonth(month, 1);
299		d.setUTCHours(0, 0, 0, 0);
300		
301		r.push(d.getUTCDay());
302		
303		for (i=28; d.setUTCDate(i) && d.getUTCMonth() == month; i++);
304		
305		r.push(i - 1);
306		
307		return r;
308	},
309
310	_addMonth: function (d, n)
311	{
312		var		month = d.getUTCMonth();
313		var		year = d.getUTCFullYear();
314
315		month += n;
316		if (month < 0) {
317			month = 11;
318			year--;
319		}
320		else if (month > 11) {
321			month = 0;
322			year++;
323		}
324	
325		d.setUTCMonth(month); d.setUTCFullYear(year);
326		return d;
327	},
328
329	_click: function (type, data, args)
330	{
331		var e = args[0];
332		var node = BS.utl.event.getTarget(e);
333
334		switch (node) {
335		case this.prevA:
336			this.curDate = this._addMonth(this.curDate, -1);
337			break;
338		case this.nextA:
339			this.curDate = this._addMonth(this.curDate, 1);
340			break;
341		}
342
343		this._draw();
344	},
345
346	_body: function (type, data, args)
347	{
348		var e = args[0];
349		var node = BS.utl.event.getTarget(e);
350
351		for (; node && (node.id != this.obj.id); node = node.parentNode);
352
353		if (node) return;
354
355		this.show(false);
356		BS.utl.event.preventDefault(e);
357	},
358
359	_attachBody: function () { this.bodyE.attach(document.body, 'click'); },
360
361	_chkDate: function (d)
362	{
363		if (!this.sD && !this.eD) return true;
364
365		var f = 0;
366		if (this.sD) {
367			if (BS.utl.date.compare(d, this.sD) > 0)
368				f--;
369			else f++;
370		}
371
372		if (this.eD) {
373			if (BS.utl.date.compare(d, this.eD) < 0)
374				f--;
375			else f++;
376		}
377
378		if (f < 0) return false;
379		return true;
380	},
381
382	_draw: function ()
383	{
384		if (!this.curDate) return;
385
386		var d = new Date(this.curDate.valueOf());
387
388		this.titleSPAN.innerHTML = d.strftime('%B %Y');
389
390		var days = this._dateDayCnt(d);
391		var set = null;
392		var str = '';
393
394		if (this.setDate.strftime('%Y%m') == d.strftime('%Y%m'))
395			set = this.setDate.getUTCDate();
396
397		for (var i = 0; i < days[0]; i++)
398			str += '<li>&nbsp;</li>';
399
400		for (var i = 1; i <= days[1]; i++) {
401			d.setUTCDate(i);
402			if (this._chkDate(d)) {
403				str += '<li><a href="javascript:' + this.gvStr + '.set(\'' + d.strftime('%Y-%m-%d') + '\');"';
404				if (i == set) str += ' class="bscSet"';
405				str += '>' + i + '</a></li>';
406			}
407			else
408				str += '<li>' + i + '</li>';
409		}
410
411		this.UL.innerHTML = str;
412	},
413
414	_reset: function (date)
415	{
416		var val = date.valueOf();
417
418		delete this.curDate;
419		delete this.setDate;
420
421		this.curDate = new Date(val);
422		this.setDate = new Date(val);
423	},
424
425	disableDates: function (sD, eD)
426	{
427		this.sD = sD;
428		this.eD = eD;
429	},
430
431	set: function (str)
432	{
433		if (this.submitE) this.submitE.exec(str);
434		this.show(false);
435	},
436
437	setZindex: function (zindex)
438	{
439		BS.utl.dom.setStyle(this.obj, 'zIndex', zindex);
440	},
441
442	setPos: function (pos)
443	{
444		delete this.pos;
445		this.pos = pos.slice();
446	},
447
448	show: function (mode, date)
449	{
450		if (mode) {
451			if (!date) date = this.date;
452
453			this._reset(date);
454
455			this._draw();
456
457			if (this.ieMask) {
458				var size = BS.utl.dom.size(this.obj);
459				var pos = BS.utl.dom.pageOfs(this.obj);
460				var scroll = BS.utl.dom.scrollOfs();
461				pos = BS.utl.xy.sub(pos, scroll);
462				pos = BS.utl.xy.add(pos, this.pos);
463				BS.utl.dom.setStyle(this.ieMask, 'width', size[0] + 'px');
464				BS.utl.dom.setStyle(this.ieMask, 'height', size[1] + 'px');
465				BS.utl.dom.setPageOfs(this.ieMask, pos);
466			}
467			BS.utl.event.setTimeout(0, this._attachBody, this);
468		} else {
469			this.bodyE.detach(document.body, 'click');
470		}
471
472		BS.utl.dom.setStyle(this.obj, 'visibility', (mode) ? 'visible' : 'hidden');
473		if (this.ieMask)
474			BS.utl.dom.setStyle(this.ieMask, 'visibility', (mode) ? 'visible' : 'hidden');
475	},
476
477	showLink: function (dateStr, div)
478	{
479		if (div) {		
480			var pos = BS.utl.dom.pageOfs(div);
481			pos = BS.utl.xy.add(pos, this.pos);
482			if (BS.utl.browser.isIE) {
483				var scroll = BS.utl.dom.scrollOfs();
484				pos = BS.utl.xy.sub(pos, scroll);
485			}
486			BS.utl.dom.setPageOfs(this.obj, pos);
487		}
488
489		this.show(true, BS.utl.date.toDate(dateStr));
490	}
491};

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.