PageSourceSearch

https://www.socialmotus.com/js/wl_Date.js

js socialmotus.com collected 2026-10-04 21:14:36 UTC 3,833 bytes, 146 lines download raw bytes

1/*----------------------------------------------------------------------*/
2/* wl_Date v 1.0 by revaxarts.com
3/* description: extends the Datepicker
4/* dependency: jQuery Datepicker, mousewheel plugin
5/*----------------------------------------------------------------------*/
6
7
8$.fn.wl_Date = function (method) {
9
10	var args = arguments;
11	return this.each(function () {
12
13		var $this = $(this);
14
15
16		if ($.fn.wl_Date.methods[method]) {
17			return $.fn.wl_Date.methods[method].apply(this, Array.prototype.slice.call(args, 1));
18		} else if (typeof method === 'object' || !method) {
19			if ($this.data('wl_Date')) {
20				var opts = $.extend({}, $this.data('wl_Date'), method);
21			} else {
22				var opts = $.extend({}, $.fn.wl_Date.defaults, method, $this.data());
23			}
24		} else {
25			try {
26				return $this.datepicker(method, args[1], args[2]);
27			} catch (e) {
28				$.error('Method "' + method + '" does not exist');
29			}
30		}
31
32
33		if (!$this.data('wl_Date')) {
34
35			$this.data('wl_Date', {});
36
37			//call the jQuery UI datepicker plugin
38			$this.datepicker(opts);
39
40			//bind a mousewheel event to the input field
41			$this.bind('mousewheel.wl_Date', function (event, delta) {
42				if (opts.mousewheel) {
43					event.preventDefault();
44					//delta must be 1 or -1 (different on macs and with shiftkey pressed)
45					delta = (delta < 0) ? -1 : 1;
46					
47					//shift key is pressed
48					if (event.shiftKey) {
49						var _date = $this.datepicker('getDate');
50						//new delta is the current month day count (month in days)
51						delta *= new Date(_date.getFullYear(), _date.getMonth() + 1, 0).getDate();
52					}
53					//call the method
54					$.fn.wl_Date.methods.changeDay.call($this[0], delta);
55				}
56			});
57
58
59			//value is set and has to get translated (self-explanatory) 
60			if (opts.value) {
61				var today = new Date().getTime();
62				switch (opts.value) {
63				case 'now':
64				case 'today':
65					$this.datepicker('setDate', new Date());
66					break;
67				case 'next':
68				case 'tomorrow':
69					$this.datepicker('setDate', new Date(today + 864e5 * 1));
70					break;
71				case 'prev':
72				case 'yesterday':
73					$this.datepicker('setDate', new Date(today + 864e5 * -1));
74					break;
75				default:
76					//if a valid number add them as days to the date field
77					if (!isNaN(opts.value)) $this.datepicker('setDate', new Date(today + 864e5 * opts.value));
78				}
79
80			}
81			//disable if set
82			if (opts.disabled) {
83				$.fn.wl_Date.methods.disable.call(this);
84			}
85		} else {
86
87		}
88
89		if (opts) $.extend($this.data('wl_Date'), opts);
90	});
91
92};
93
94$.fn.wl_Date.defaults = {
95	value: null,
96	mousewheel: true
97};
98$.fn.wl_Date.version = '1.0';
99
100
101$.fn.wl_Date.methods = {
102	disable: function () {
103		var $this = $(this);
104		//disable the datepicker
105		$this.datepicker('disable');
106		$this.data('wl_Date').disabled = true;
107	},
108	enable: function () {
109		var $this = $(this);
110		//enable the datepicker
111		$this.datepicker('enable');
112		$this.data('wl_Date').disabled = false;
113	},
114	next: function () {
115		//select next day
116		$.fn.wl_Date.methods.changeDay.call(this, 1);
117	},
118	prev: function () {
119		//select previous day
120		$.fn.wl_Date.methods.changeDay.call(this, -1);
121	},
122	changeDay: function (delta) {
123		var $this = $(this),
124			_current = $this.datepicker('getDate') || new Date();
125		//set day to currentday + delta
126		_current.setDate(_current.getDate() + delta);
127		$this.datepicker('setDate', _current);
128	},
129	set: function () {
130		var $this = $(this),
131			options = {};
132		if (typeof arguments[0] === 'object') {
133			options = arguments[0];
134		} else if (arguments[0] && arguments[1] !== undefined) {
135			options[arguments[0]] = arguments[1];
136		}
137		$.each(options, function (key, value) {
138			if ($.fn.wl_Date.defaults[key] !== undefined || $.fn.wl_Date.defaults[key] == null) {
139				$this.data('wl_Date')[key] = value;
140			} else {
141				$.error('Key "' + key + '" is not defined');
142			}
143		});
144
145	}
146};

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.