PageSourceSearch

https://teatris.lv/wp-content/themes/lnt/assets/vendor/jquery.calendario.js?ver=1.0.0

js teatris.lv collected 2026-10-02 13:00:32 UTC 10,379 bytes, 399 lines download raw bytes

1/**
2 * jquery.calendario.js v1.0.0
3 * http://www.codrops.com
4 *
5 * Licensed under the MIT license.
6 * http://www.opensource.org/licenses/mit-license.php
7 * 
8 * Copyright 2012, Codrops
9 * http://www.codrops.com
10 */
11;( function( $, window, undefined ) {
12	
13	'use strict';
14
15	$.Calendario = function( options, element ) {
16		
17		this.$el = $( element );
18		this._init( options );
19		
20	};
21
22	// the options
23	$.Calendario.defaults = {
24		/*
25		you can also pass:
26		month : initialize calendar with this month (1-12). Default is today.
27		year : initialize calendar with this year. Default is today.
28		caldata : initial data/content for the calendar.
29		caldata format:
30		{
31			'MM-DD-YYYY' : 'HTML Content',
32			'MM-DD-YYYY' : 'HTML Content',
33			'MM-DD-YYYY' : 'HTML Content'
34			...
35		}
36		*/
37		weeks : [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ],
38		weekabbrs : [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
39		months : [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
40		monthabbrs : [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
41		// choose between values in options.weeks or options.weekabbrs
42		displayWeekAbbr : false,
43		// choose between values in options.months or options.monthabbrs
44		displayMonthAbbr : false,
45		// left most day in the calendar
46		// 0 - Sunday, 1 - Monday, ... , 6 - Saturday
47		startIn : 1,
48		onDayClick : function( $el, $content, dateProperties ) { return false; }
49	};
50
51	$.Calendario.prototype = {
52
53		_init : function( options ) {
54			
55			// options
56			this.options = $.extend( true, {}, $.Calendario.defaults, options );
57
58			this.today = new Date();
59			this.month = ( isNaN( this.options.month ) || this.options.month == null) ? this.today.getMonth() : this.options.month - 1;
60			this.year = ( isNaN( this.options.year ) || this.options.year == null) ? this.today.getFullYear() : this.options.year;
61			this.caldata = this.options.caldata || {};
62			this._generateTemplate();
63			this._initEvents();
64
65		},
66		_initEvents : function() {
67
68			var self = this;
69
70			this.$el.on( 'click.calendario', 'div.fc-row > div > div.day-header', function() {
71
72				var $cell = $( this ),
73					idx = $cell.index(),
74					$content = $cell.children( 'div' ),
75					dateProp = {
76						day : $cell.children( 'span.fc-date' ).text(),
77						month : self.month + 1,
78						monthname : self.options.displayMonthAbbr ? self.options.monthabbrs[ self.month ] : self.options.months[ self.month ],
79						year : self.year,
80						weekday : idx + self.options.startIn,
81						weekdayname : self.options.weeks[ idx + self.options.startIn ]
82					};
83
84				if( dateProp.day ) {
85					self.options.onDayClick( $cell, $content, dateProp );
86				}
87
88			} );
89
90		},
91		// Calendar logic based on http://jszen.blogspot.pt/2007/03/how-to-build-simple-calendar-with.html
92		_generateTemplate : function( callback ) {
93
94			var head = this._getHead(),
95				body = this._getBody(),
96				rowClass;
97
98			switch( this.rowTotal ) {
99				case 4 : rowClass = 'fc-four-rows'; break;
100				case 5 : rowClass = 'fc-five-rows'; break;
101				case 6 : rowClass = 'fc-six-rows'; break;
102			}
103
104			this.$cal = $( '<div class="fc-calendar ' + rowClass + '">' ).append( head, body );
105
106			this.$el.find( 'div.fc-calendar' ).remove().end().append( this.$cal );
107
108			if( callback ) { callback.call(); }
109
110		},
111		_getHead : function() {
112
113			var html = '<div class="fc-head">';
114		
115			for ( var i = 0; i <= 6; i++ ) {
116
117				var pos = i + this.options.startIn,
118					j = pos > 6 ? pos - 6 - 1 : pos;
119
120				html += '<div class="week-day small">';
121				html += this.options.displayWeekAbbr ? this.options.weekabbrs[ j ] : this.options.weeks[ j ];
122				html += '</div>';
123
124			}
125
126			html += '</div>';
127
128			return html;
129
130		},
131		_getBody : function() {
132
133			var d = new Date( this.year, this.month + 1, 0 ),
134				// number of days in the month
135				monthLength = d.getDate(),
136				firstDay = new Date( this.year, this.month, 1 );
137
138			// day of the week
139			this.startingDay = firstDay.getDay();
140
141			var html = '<div class="fc-body"><div class="fc-row">',
142				// fill in the days
143				day = 1;
144
145			// this loop is for weeks (rows)
146			var counter = 1;
147			for ( var i = 0; i < 7; i++ ) {
148
149				// this loop is for weekdays (cells)
150				for ( var j = 0; j <= 6; j++ ) {
151
152					var pos = this.startingDay - this.options.startIn,
153						p = pos < 0 ? 6 + pos + 1 : pos,
154						inner = '',
155						today = this.month === this.today.getMonth() && this.year === this.today.getFullYear() && day === this.today.getDate(),
156						content = '';
157					
158					if ( day <= monthLength && ( i > 0 || j >= p ) ) {
159						// var fc_date = day;
160						var fc_date = (day < 10 ) ? '0' + day : day;
161						// inner += '<div class="day-header"><span class="fc-date">' + fc_date + '</span><span class="fc-weekday">' + this.options.weekabbrs[ j + this.options.startIn > 6 ? j + this.options.startIn - 6 - 1 : j + this.options.startIn ] + '</span></div>';
162						inner += '<div class="day-header"><span class="fc-date small">' + fc_date + '</span></div>';
163
164						// this day is:
165						var strdate = ( this.month + 1 < 10 ? '0' + ( this.month + 1 ) : this.month + 1 ) + '-' + ( day < 10 ? '0' + day : day ) + '-' + this.year,
166							dayData = this.caldata[ strdate ];
167
168						if( dayData ) {
169							content = dayData;
170						}
171
172						if( content !== '' ) {
173							inner += '<div class="cal-content">' + content + '</div>';
174						} else {
175							inner += '<div class="cal-content"></div>';
176						}
177
178						++day;
179
180					}
181					else {
182						today = false;
183					}
184
185					var cellClasses = today ? 'fc-today day' : 'day';
186					if( content !== '' ) {
187						cellClasses += ' fc-content';
188					}
189
190					if ( inner == '' ) {
191						cellClasses += ' fc-empty';
192					}
193					
194					html += cellClasses !== '' ? '<div class="' + cellClasses + '">' : '<div>';
195					html += inner;
196					html += '</div>';
197
198					counter++;
199				}
200
201				// stop making rows if we've run out of days
202				if (day > monthLength) {
203					this.rowTotal = i + 1;
204					break;
205				} 
206				else {
207					html += '</div><div class="fc-row">';
208				}
209
210			}
211			html += '</div></div>';
212
213			return html;
214
215		},
216		// based on http://stackoverflow.com/a/8390325/989439
217		_isValidDate : function( date ) {
218
219			date = date.replace(/-/gi,'');
220			var month = parseInt( date.substring( 0, 2 ), 10 ),
221				day = parseInt( date.substring( 2, 4 ), 10 ),
222				year = parseInt( date.substring( 4, 8 ), 10 );
223
224			if( ( month < 1 ) || ( month > 12 ) ) {
225				return false;
226			}
227			else if( ( day < 1 ) || ( day > 31 ) )  {
228				return false;
229			}
230			else if( ( ( month == 4 ) || ( month == 6 ) || ( month == 9 ) || ( month == 11 ) ) && ( day > 30 ) )  {
231				return false;
232			}
233			else if( ( month == 2 ) && ( ( ( year % 400 ) == 0) || ( ( year % 4 ) == 0 ) ) && ( ( year % 100 ) != 0 ) && ( day > 29 ) )  {
234				return false;
235			}
236			else if( ( month == 2 ) && ( ( year % 100 ) == 0 ) && ( day > 29 ) )  {
237				return false;
238			}
239
240			return {
241				day : day,
242				month : month,
243				year : year
244			};
245
246		},
247		_move : function( period, dir, callback ) {
248
249			if( dir === 'previous' ) {
250				
251				if( period === 'month' ) {
252					this.year = this.month > 0 ? this.year : --this.year;
253					this.month = this.month > 0 ? --this.month : 11;
254				}
255				else if( period === 'year' ) {
256					this.year = --this.year;
257				}
258
259			}
260			else if( dir === 'next' ) {
261
262				if( period === 'month' ) {
263					this.year = this.month < 11 ? this.year : ++this.year;
264					this.month = this.month < 11 ? ++this.month : 0;
265				}
266				else if( period === 'year' ) {
267					this.year = ++this.year;
268				}
269
270			}
271
272			this._generateTemplate( callback );
273
274		},
275		/************************* 
276		******PUBLIC METHODS *****
277		**************************/
278		getYear : function() {
279			return this.year;
280		},
281		getMonth : function() {
282			return this.month + 1;
283		},
284		getMonthName : function() {
285			return this.options.displayMonthAbbr ? this.options.monthabbrs[ this.month ] : this.options.months[ this.month ];
286		},
287		// gets the cell's content div associated to a day of the current displayed month
288		// day : 1 - [28||29||30||31]
289		getCell : function( day ) {
290
291			var row = Math.floor( ( day + this.startingDay - this.options.startIn ) / 7 ),
292				pos = day + this.startingDay - this.options.startIn - ( row * 7 ) - 1;
293
294			return this.$cal.find( 'div.fc-body' ).children( 'div.fc-row' ).eq( row ).children( 'div' ).eq( pos ).children( 'div' );
295
296		},
297		setData : function( caldata ) {
298
299			caldata = caldata || {};
300			// $.extend( this.caldata, caldata );
301			this.caldata = caldata;
302			this._generateTemplate();
303
304		},
305		// goes to today's month/year
306		gotoNow : function( callback ) {
307
308			this.month = this.today.getMonth();
309			this.year = this.today.getFullYear();
310			this._generateTemplate( callback );
311
312		},
313		// goes to month/year
314		goto : function( month, year, callback ) {
315
316			this.month = month;
317			this.year = year;
318			this._generateTemplate( callback );
319
320		},
321		gotoPreviousMonth : function( callback ) {
322			this._move( 'month', 'previous', callback );
323		},
324		gotoPreviousYear : function( callback ) {
325			this._move( 'year', 'previous', callback );
326		},
327		gotoNextMonth : function( callback ) {
328			this._move( 'month', 'next', callback );
329		},
330		gotoNextYear : function( callback ) {
331			this._move( 'year', 'next', callback );
332		}
333
334	};
335	
336	var logError = function( message ) {
337
338		if ( window.console ) {
339
340			window.console.error( message );
341		
342		}
343
344	};
345	
346	$.fn.calendario = function( options ) {
347
348		var instance = $.data( this, 'calendario' );
349		
350		if ( typeof options === 'string' ) {
351			
352			var args = Array.prototype.slice.call( arguments, 1 );
353			
354			this.each(function() {
355			
356				if ( !instance ) {
357
358					logError( "cannot call methods on calendario prior to initialization; " +
359					"attempted to call method '" + options + "'" );
360					return;
361				
362				}
363				
364				if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
365
366					logError( "no such method '" + options + "' for calendario instance" );
367					return;
368				
369				}
370				
371				instance[ options ].apply( instance, args );
372			
373			});
374		
375		} 
376		else {
377		
378			this.each(function() {
379				
380				if ( instance ) {
381
382					instance._init();
383				
384				}
385				else {
386
387					instance = $.data( this, 'calendario', new $.Calendario( options, this ) );
388				
389				}
390
391			});
392		
393		}
394		
395		return instance;
396		
397	};
398	
399} )( jQuery, window );

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.