'))},_getBody:function(){var e=new Date(this.year,this.month+1,0),t=e.getDate(),n=new Date(this.year,e.getMonth(),1),r=(new Date(this.year,this.month,0)).getDate();this.startingDay=n.getDay();var i='
',s=1;for(var o=0;o<7;o++){for(var u=0;u<=6;u++){var a=this.startingDay-this.options.startIn,f=a<0?6+a+1:a,l="",c=this.month===this.today.getMonth()&&this.year===this.today.getFullYear()&&s===this.today.getDate(),h=this.year
0)){if(s>t){l=''+(s-t)+' ';++s}else if(s==1){l=''+(r-f+1)+' ';++r}l+=this.options.weekabbrs[u+this.options.startIn>6?u+this.options.startIn-6-1:u+this.options.startIn]+" "}if(s<=t&&(o>0||u>=f)){l=''+s+' '+this.options.weekabbrs[u+this.options.startIn>6?u+this.options.startIn-6-1:u+this.options.startIn]+" ";var d=(this.month+1<10?"0"+(this.month+1):this.month+1)+"-"+(s<10?"0"+s:s)+"-"+this.year,v=this.caldata[d],m=(this.month+1<10?"0"+(this.month+1):this.month+1)+"-"+(s<10?"0"+s:s)+"-YYYY",g=this.caldata[m],y="MM-"+(s<10?"0"+s:s)+"-"+this.year,b=this.caldata[y],w="MM"+"-"+(s<10?"0"+s:s)+"-YYYY",E=this.caldata[w],S=(this.month+1<10?"0"+(this.month+1):this.month+1)+"-DD-"+this.year,x=this.caldata[S],T=(this.month+1<10?"0"+(this.month+1):this.month+1)+"-DD-YYYY",N=this.caldata[T];if(c&&this.caldata.TODAY)p+=this._parseDataToDay(this.caldata.TODAY,s);if(v)p+=this._parseDataToDay(v,s);if(b)p+=this._parseDataToDay(b,s);if(x)p+=this._parseDataToDay(x,s,true);if(N)p+=this._parseDataToDay(N,s,true);if(E)p+=this._parseDataToDay(E,s);if(g)p+=this._parseDataToDay(g,s);if(p!=="")l+=''+p+"
";++s}else{c=false}var C=c?"fc-today ":"";if(h)C+="fc-past ";else C+="fc-future ";if(p!=="")C+="fc-content";i+=(C!==""?'':"
")+l+"
"}if(s>t){this.rowTotal=o+1;break}else{i+='
'}}return i+"
"},_move:function(e,t,n){if(t==="previous"){if(e==="month"){this.year=this.month>0?this.year:--this.year;this.month=this.month>0?--this.month:11}else if(e==="year")this.year=--this.year}else if(t==="next"){if(e==="month"){this.year=this.month<11?this.year:++this.year;this.month=this.month<11?++this.month:0}else if(e==="year")this.year=++this.year}this._generateTemplate(false,n)},option:function(e,t){if(t)this.options[e]=t;else return this.options[e]},getYear:function(){return this.year},getMonth:function(){return this.month+1},getMonthName:function(){return this.options.displayMonthAbbr?this.options.monthabbrs[this.month]:this.options.months[this.month]},getCell:function(e){var t=Math.floor((e+this.startingDay-this.options.startIn-1)/7),n=e+this.startingDay-this.options.startIn-t*7-1;return this.$cal.find("div.fc-body").children("div.fc-row").eq(t).children("div").eq(n)},setData:function(t,n){t=this._processCaldata(t);if(n)this.caldata=t;else e.extend(this.caldata,t);this._generateTemplate(false)},gotoNow:function(e){this.month=this.today.getMonth();this.year=this.today.getFullYear();this._generateTemplate(false,e)},gotoMonth:function(e,t,n){this.month=e-1;this.year=t;this._generateTemplate(false,n)},gotoPreviousMonth:function(e){this._move("month","previous",e)},gotoPreviousYear:function(e){this._move("year","previous",e)},gotoNextMonth:function(e){this._move("month","next",e)},gotoNextYear:function(e){this._move("year","next",e)},feed:function(t){var n=this;e.post(n.options.feedParser,{dates:this.caldata}).always(function(e){if(t)t.call(this,JSON.parse(e).hevent)})},version:function(){return this.VERSION}};var r=function(e){throw new Error(e)};e.fn.calendario=function(t){var n=e.data(this,"calendario");if(typeof t==="string"){var i=Array.prototype.slice.call(arguments,1);this.each(function(){if(!n){r("Cannot call methods on calendario prior to initialization; Attempted to call method '"+t+"'");return}if(!e.isFunction(n[t])||t.charAt(0)==="_"){r("No such method '"+t+"' for calendario instance.")}n[t].apply(n,i)})}else{this.each(function(){if(n)n._init();else n=e.data(this,"calendario",new e.Calendario(t,this))})}n.$el.trigger(e.Event("shown.calendar.calendario"),[n]);return n}})(jQuery,window)
2 |
--------------------------------------------------------------------------------
/index4.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Flexible Calendar
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
41 |
50 |
51 |
52 | all-day
53 |
54 |
55 | 00:00
56 |
57 |
58 | 01:00
59 |
60 |
61 | 02:00
62 |
63 |
64 | 03:00
65 |
66 |
67 | 04:00
68 |
69 |
70 | 05:00
71 |
72 |
73 | 06:00
74 |
75 |
76 | 07:00
77 |
78 |
79 | 08:00
80 |
81 |
82 | 09:00
83 |
84 |
85 | 10:00
86 |
87 |
88 | 11:00
89 |
90 |
91 | 12:00
92 |
93 |
94 | 13:00
95 |
96 |
97 | 14:00
98 |
99 |
100 | 15:00
101 |
102 |
103 | 16:00
104 |
105 |
106 | 17:00
107 |
108 |
109 | 18:00
110 |
111 |
112 | 19:00
113 |
114 |
115 | 20:00
116 |
117 |
118 | 21:00
119 |
120 |
121 | 22:00
122 |
123 |
124 | 23:00
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
244 |
245 |
246 |
--------------------------------------------------------------------------------
/js/jquery.calendario.js:
--------------------------------------------------------------------------------
1 | /**
2 | * jquery.calendario.js v3.2.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 2014, Codrops
9 | * http://www.codrops.com
10 | *
11 | * || Notable Changes ||
12 | * Calendario gets more flexible : Boží Ďábel (https://github.com/deviprsd21) (https://github.com/codrops/Calendario/pull/11)
13 | * Multiple Events : Mattias Lyckne (https://github.com/olyckne) (https://github.com/codrops/Calendario/pull/22)
14 | * Flexibility In-built : Boží Ďábel (https://github.com/deviprsd21) (https://github.com/codrops/Calendario/pull/23)
15 | * Now with Time : Boží Ďábel (https://github.com/deviprsd21) (https://github.com/codrops/Calendario/pull/25)
16 | */
17 | ;(function($, window, undefined){
18 | 'use strict';
19 |
20 | $.Calendario = function(options, element){
21 | this.$el = $(element);
22 | this._init(options);
23 | };
24 |
25 | // the options
26 | $.Calendario.defaults = {
27 | /*
28 | you can also pass:
29 | month : initialize calendar with this month (1-12). Default is today.
30 | year : initialize calendar with this year. Default is today.
31 | caldata : initial data/content for the calendar.
32 | caldata format:
33 | {
34 | 'MM-DD-YYYY' : 'HTML Content',
35 | 'MM-DD-YYYY' : 'HTML Content',
36 | ...
37 | }
38 | */
39 | weeks : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
40 | weekabbrs : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
41 | months : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
42 | monthabbrs : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
43 | displayWeekAbbr : false, // choose between values in options.weeks or options.weekabbrs
44 | displayMonthAbbr : false, // choose between values in options.months or options.monthabbrs
45 | startIn : 1, // left most day in the calendar (0 - Sunday, 1 - Monday, ... , 6 - Saturday)
46 | events: 'click',
47 | fillEmpty: true,
48 | feedParser: './feed/',
49 | zone: '00:00', // Ex: IST zone time is '+05:30' by default it is GMT, Sign is important.
50 | checkUpdate: true //Check if any new version of Calendario is released (Details will be in the browser console)
51 | };
52 |
53 | $.Calendario.prototype = {
54 | _init : function(options){
55 | // options
56 | this.VERSION = '3.2.0';
57 | this.UNIQUE = '%{unique}%'; //UNIQUE helps us differentiate your js from others and help us keep a track of run time.
58 | this.options = $.extend(true, {}, $.Calendario.defaults, options);
59 | this.today = new Date();
60 | this.month = (isNaN(this.options.month) || this.options.month === null) ? this.today.getMonth() : this.options.month - 1;
61 | this.year = (isNaN(this.options.year) || this.options.year === null) ? this.today.getFullYear() : this.options.year;
62 | this.caldata = this._processCaldata(this.options.caldata);
63 | // if hover is passed as an event then throw error if jQuery is 1.9 or above 1.9, because, hover psuedo name isn't supported
64 | if(parseFloat($().jquery) >= 1.9 && this.options.events.indexOf('hover') != -1)
65 | this.logError('\'hover\' psuedo-name is not supported' + ' in jQuery 1.9+. Use \'mouseenter\' \'mouseleave\' events instead.');
66 |
67 | this.options.events = this.options.events.split(',');
68 | this.options.zone = this.options.zone.charAt(0) != '+' && this.options.zone.charAt(0) != '-' ? '+' + this.options.zone : this.options.zone;
69 | this._generateTemplate(true);
70 | this._initEvents();
71 | },
72 |
73 | _processCaldataObj: function(val, key){
74 | if(typeof val !== 'object') val = {content: val, startTime: '00:00', endTime: '23:59', allDay: true};
75 | if(!val.content) this.logError('Content is missing in date ' + key);
76 | if(val.startTime && !val.endTime) val.endTime = parseInt(val.startTime.split(':')[0]) + 1 + ':' + val.startTime.split(':')[1];
77 | if(!val.startTime && !val.endTime) val = $.extend({}, val, {startTime: '00:00', endTime: '23:59', allDay: true});
78 | if(val.startTime && val.endTime && val.allDay === undefined) val.allDay = false;
79 | if(/^\d{2}-DD-\d{4}/.test(key) || /^\d{2}-DD-YYYY/.test(key)) {
80 | var det = /^(\d{2})-DD-(\d{4})/.exec(key) || /^(\d{2})-DD-YYYY/.exec(key), chkDate;
81 | if(det.length == 3) chkDate = new Date(det[2], det[1], 0);
82 | else if(det.length == 2) chkDate = new Date(this.year, det[1], 0)
83 | if(!val.startDate) val.startDate = 1;
84 | if(!val.endDate && chkDate.getDate() != 1) val.endDate = chkDate.getDate();
85 | if(!val.endDate && chkDate.getDate() == 1 && det.length == 3) val.endDate = chkDate.getDate();
86 | }
87 | return val;
88 | },
89 |
90 | _processCaldata: function(caldata){
91 | var self = this;
92 | caldata = caldata || {};
93 | $.each(caldata, function(key, val){
94 | if(/^\d{2}-\d{2}-\d{4}/.test(key) || /^\d{2}-\d{2}-YYYY/.test(key) || /^\d{2}-DD-YYYY/.test(key) || /^MM-\d{2}-YYYY/.test(key) ||
95 | /^\d{2}-DD-YYYY/.test(key) || /^MM-\d{2}-\d{4}/.test(key) || /^\d{2}-DD-\d{4}/.test(key) || key == 'TODAY') {} else
96 | self.logError(key + ' is an Invalid Date. Date should not contain spaces, should be separated by \'-\' and should be in the ' +
97 | 'format \'MM-DD-YYYY\'. That ain\'t that difficult!');
98 | if(Array.isArray(val)) {
99 | $.each(val, function(i, c){
100 | val[i] = self._processCaldataObj(c, key);
101 | });
102 | caldata[key] = val;
103 | } else {
104 | caldata[key] = self._processCaldataObj(val, key);
105 | }
106 | });
107 | return caldata;
108 | },
109 |
110 | _propDate: function($cell, event){
111 | var idx = $cell.index(),
112 | data = {allDay : [], content: [], endTime: [], startTime: []},
113 | dateProp = {
114 | day : $cell.children('span.fc-date').text(),
115 | month : this.month + 1,
116 | monthname : this.options.displayMonthAbbr ? this.options.monthabbrs[this.month] : this.options.months[this.month],
117 | year : this.year,
118 | weekday : idx + this.options.startIn,
119 | weekdayname : this.options.weeks[(idx==6?0:idx + this.options.startIn)]
120 | };
121 |
122 | $cell.children( 'div.fc-calendar-events').children('div.fc-calendar-event').each(function(i, e){
123 | var $html = $('
' + $(e).html() + '
');
124 | data.startTime[i] = new Date($html.find('time.fc-starttime').attr('datetime'));
125 | data.endTime[i] = new Date($html.find('time.fc-endtime').attr('datetime'));
126 | data.allDay[i] = $html.find('time.fc-allday').attr('datetime') === 'true' ? true : false;
127 | $html.find('time').remove();
128 | data.content[i] = $html.html();
129 | });
130 |
131 | if(dateProp.day) this.options[event]($cell, data, dateProp);
132 | },
133 |
134 | _initEvents : function() {
135 | var self = this, event = [], calendarioEventNameFormat = [];
136 | for(var i = 0; i < self.options.events.length; i++) {
137 | event[i] = self.options.events[i].toLowerCase().trim();
138 | calendarioEventNameFormat[i] = 'onDay' + event[i].charAt(0).toUpperCase() + event[i].slice(1);
139 |
140 | if(this.options[calendarioEventNameFormat[i]] === undefined)
141 | this.options[calendarioEventNameFormat[i]] = function($el, $content, dateProperties) {return false;};
142 |
143 | this.$el.on(event[i] + '.calendario', 'div.fc-row > div', function(e) {
144 | if(e.type == 'mouseenter' || e.type == 'mouseleave') e.type = $.inArray(e.type, event) == -1 ? 'hover' : e.type;
145 | self._propDate($(this), calendarioEventNameFormat[$.inArray(e.type, event)]);
146 | });
147 | }
148 | this.$el.on('shown.calendar.calendario', function(e, instance){
149 | // If check update set to true, then contact calendario's update servers for details. We didn't want to slow down your code. So we
150 | // check after the calendar is rendered.
151 | if(instance && instance.options.checkUpdate) self._checkUpdate();
152 | });
153 | // newday trigger. This trigger is exactly triggered at 00:00 hours the next day with an uncertainty of 6ms.
154 | this.$el.delay(new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate() + 1, 0, 0, 0) - new Date().getTime())
155 | .queue(function(){
156 | self.today = new Date();
157 | if(self.today.getMonth() == self.month || self.today.getMonth() + 1 == self.month) self._generateTemplate(true);
158 | self.$el.trigger($.Event('newday.calendar.calendario'));
159 | });
160 | },
161 |
162 | _checkUpdate : function() {
163 | var self = this;
164 | $.getScript("https://raw.githubusercontent.com/codrops/Calendario/master/js/update.js")
165 | .done(function(script, textStatus){
166 | if(calendario.current != self.version() && parseFloat(calendario.current) >= parseFloat(self.version()))
167 | console.info(calendario.msg);
168 | })
169 | .fail(function(jqxhr, settings, exception){
170 | console.error(exception);
171 | });
172 | },
173 |
174 | // Calendar logic based on http://jszen.blogspot.pt/2007/03/how-to-build-simple-calendar-with.html
175 | _generateTemplate : function(firstRun, callback) {
176 | var head = this._getHead(),
177 | body = this._getBody(),
178 | rowClass;
179 |
180 | switch(this.rowTotal) {
181 | case 4 : rowClass = 'fc-four-rows'; break;
182 | case 5 : rowClass = 'fc-five-rows'; break;
183 | case 6 : rowClass = 'fc-six-rows'; break;
184 | }
185 |
186 | this.$cal = $('
').append(head, body);
187 | this.$el.find('div.fc-calendar').remove().end().append(this.$cal);
188 | this.$el.find('.fc-emptydate').parent().css({'background':'transparent', 'cursor':'default'});
189 |
190 | if(!firstRun) this.$el.trigger($.Event('shown.calendario'));
191 | if(callback) callback.call();
192 | },
193 |
194 | _getHead : function() {
195 | var html = '
';
196 | for(var i = 0; i <= 6; i++){
197 | var pos = i + this.options.startIn,
198 | j = pos > 6 ? pos - 6 - 1 : pos;
199 | html += '
' + (this.options.displayWeekAbbr ? this.options.weekabbrs[j] : this.options.weeks[j]) + '
';
200 | }
201 | return html + '
';
202 | },
203 |
204 | _parseDataToDay : function (data, day, other) {
205 | var content = '';
206 | if(!other){
207 | if(Array.isArray(data)) content = this._convertDayArray(data, day);
208 | else content = this._wrapDay(data, day, true);
209 | }else{
210 | if (!Array.isArray(data)) data = [data];
211 | for(var i = 0; i < data.length; i++){
212 | if(this.month != 1 && (day >= data[i].startDate) && (day <= data[i].endDate)) content += this._wrapDay(data[i], day, true);
213 | else if(this.month == 1 && (day >= data[i].startDate)){
214 | if(data[i].endDate && (day <= data[i].endDate)) content += this._wrapDay(data[i], day, true);
215 | else if(!data[i].endDate) content += this._wrapDay(data[i], day, true);
216 | }
217 | }
218 | }
219 | return content;
220 | },
221 |
222 | _toDateTime : function(time, day, start) {
223 | var zoneH = parseInt(this.options.zone.split(':')[0]),
224 | zoneM = parseInt(this.options.zone.charAt(0) + this.options.zone.split(':')[1]),
225 | hour = parseInt(time.split(':')[0]) - zoneH,
226 | minutes = parseInt(time.split(':')[1]) - zoneM,
227 | d = new Date(Date.UTC(this.year, this.month, day, hour, minutes, 0, 0));
228 | if(start) {
229 | var hStart = parseInt(start.split(':')[0]) - zoneH,
230 | mStart = parseInt(start.split(':')[1]) - zoneM;
231 | if(d.getTime() - new Date(Date.UTC(this.year, this.month, day, hStart, mStart, 0, 0)).getTime() < 0)
232 | d = new Date(Date.UTC(this.year, this.month, day + 1, hour, minutes, 0, 0));
233 | }
234 | return d.toISOString();
235 | },
236 |
237 | _timeHtml : function(day, date){
238 | var content = day.content;
239 | content += '
';
240 | content += '
' + day.startTime + ' ';
241 | content += '
' + day.endTime + ' ';
242 | return content;
243 | },
244 |
245 | _wrapDay: function (day, date, wrap) {
246 | if(date){
247 | if(wrap) return '
' + this._timeHtml(day, date) + '
';
248 | else return this._timeHtml(day, date);
249 | } else return '
' + day + '
';
250 | },
251 |
252 | _convertDayArray: function (day, date) {
253 | var wrap_days = []
254 | for(var i = 0; i < day.length; i++){
255 | wrap_days[i] = this._wrapDay(day[i], date, false);
256 | }
257 | return this._wrapDay(wrap_days.join('
'));
258 | },
259 |
260 | _getBody : function() {
261 | var d = new Date(this.year, this.month + 1, 0),
262 | monthLength = d.getDate(), // number of days in the month
263 | firstDay = new Date(this.year, d.getMonth(), 1),
264 | pMonthLength = new Date(this.year, this.month, 0).getDate();
265 |
266 | // day of the week
267 | this.startingDay = firstDay.getDay();
268 |
269 | var html = '
',
270 | day = 1; // fill in the days
271 |
272 | for (var i = 0; i < 7; i++){ // this loop is for weeks (rows)
273 | for (var j = 0; j <= 6; j++) { // this loop is for weekdays (cells)
274 | var pos = this.startingDay - this.options.startIn,
275 | p = pos < 0 ? 6 + pos + 1 : pos,
276 | inner = '',
277 | today = this.month === this.today.getMonth() && this.year === this.today.getFullYear() && day === this.today.getDate(),
278 | past = this.year < this.today.getFullYear() || this.month < this.today.getMonth() && this.year === this.today.getFullYear() ||
279 | this.month === this.today.getMonth() && this.year === this.today.getFullYear() && day < this.today.getDate(),
280 | content = '';
281 |
282 | if(this.options.fillEmpty && (j < p || i > 0)){
283 | if(day > monthLength) {
284 | inner = '
' + (day - monthLength) + ' ';
285 | ++day;
286 | } else if (day == 1) {
287 | inner = '' + (pMonthLength - p + 1) + ' ';
288 | ++pMonthLength;
289 | }
290 | inner += this.options.weekabbrs[j + this.options.startIn > 6 ? j + this.options.startIn - 6 - 1 : j + this.options.startIn] + ' ';
291 | }
292 | if (day <= monthLength && (i > 0 || j >= p)){
293 | inner = '' + day + ' ' + this.options.weekabbrs[j +
294 | this.options.startIn > 6 ? j + this.options.startIn - 6 - 1 : j + this.options.startIn ] + ' ';
295 |
296 | var strdate = (this.month + 1 < 10 ? '0' + (this.month + 1) : this.month + 1) + '-' + (day < 10 ? '0' + day : day) + '-' + this.year,
297 | dayData = this.caldata[strdate],
298 | strdateyear = (this.month + 1 < 10 ? '0' + (this.month + 1) : this.month + 1) + '-' + (day < 10 ? '0' + day : day) + '-YYYY',
299 | dayDataYear = this.caldata[strdateyear],
300 | strdatemonth = 'MM-' + (day < 10 ? '0' + day : day) + '-' + this.year,
301 | dayDataMonth = this.caldata[strdatemonth],
302 | strdatemonthyear = 'MM' + '-' + (day < 10 ? '0' + day : day) + '-YYYY',
303 | dayDataMonthYear = this.caldata[strdatemonthyear],
304 | strdatemonthlyyear = (this.month + 1 < 10 ? '0' + (this.month + 1) : this.month + 1) + '-DD-' + this.year,
305 | dayDataMonthlyYear = this.caldata[strdatemonthlyyear],
306 | strdatemonthly = (this.month + 1 < 10 ? '0' + (this.month + 1) : this.month + 1) + '-DD-YYYY',
307 | dayDataMonthly = this.caldata[strdatemonthly];
308 |
309 | if(today && this.caldata.TODAY) content += this._parseDataToDay(this.caldata.TODAY, day);
310 | if(dayData) content += this._parseDataToDay(dayData, day);
311 | if(dayDataMonth) content += this._parseDataToDay(dayDataMonth, day);
312 | if(dayDataMonthlyYear) content += this._parseDataToDay(dayDataMonthlyYear, day, true);
313 | if(dayDataMonthly) content += this._parseDataToDay(dayDataMonthly, day, true);
314 | if(dayDataMonthYear) content += this._parseDataToDay( dayDataMonthYear, day );
315 | if(dayDataYear) content += this._parseDataToDay( dayDataYear, day );
316 | if(content !== '') inner += '' + content + '
';
317 | ++day;
318 | } else {
319 | today = false;
320 | }
321 |
322 | var cellClasses = today ? 'fc-today ' : '';
323 |
324 | if(past) cellClasses += 'fc-past ';
325 | else cellClasses += 'fc-future ';
326 |
327 | if(content !== '') cellClasses += 'fc-content';
328 |
329 | html += (cellClasses !== '' ? '' : '
') + inner + '
';
330 | }
331 |
332 | if(day > monthLength){ // stop making rows if we've run out of days
333 | this.rowTotal = i + 1;
334 | break;
335 | } else {
336 | html += '
';
337 | }
338 | }
339 | return html + '
';
340 | },
341 |
342 | _move : function(period, dir, callback){
343 | if(dir === 'previous'){
344 | if(period === 'month'){
345 | this.year = this.month > 0 ? this.year : --this.year;
346 | this.month = this.month > 0 ? --this.month : 11;
347 | } else if(period === 'year') this.year = --this.year;
348 | }
349 | else if(dir === 'next'){
350 | if(period === 'month'){
351 | this.year = this.month < 11 ? this.year : ++this.year;
352 | this.month = this.month < 11 ? ++this.month : 0;
353 | } else if(period === 'year') this.year = ++this.year;
354 | }
355 | this._generateTemplate(false, callback);
356 | },
357 |
358 | /*************************
359 | ***** PUBLIC METHODS *****
360 | **************************/
361 | option : function(option, value) {
362 | if(value) this.options[option] = value;
363 | else return this.options[option];
364 | },
365 | getYear : function(){
366 | return this.year;
367 | },
368 | getMonth : function(){
369 | return this.month + 1;
370 | },
371 | getMonthName : function(){
372 | return this.options.displayMonthAbbr ? this.options.monthabbrs[this.month] : this.options.months[this.month];
373 | },
374 | // gets the cell's content div associated to a day of the current displayed month
375 | // day : 1 - [28||29||30||31]
376 | getCell : function(day){
377 | var row = Math.floor((day + this.startingDay - this.options.startIn - 1) / 7),
378 | pos = day + this.startingDay - this.options.startIn - (row * 7) - 1;
379 | return this.$cal.find('div.fc-body').children('div.fc-row').eq(row).children('div').eq(pos);
380 | },
381 | setData : function(caldata, clear) {
382 | caldata = this._processCaldata(caldata);
383 | if(clear) this.caldata = caldata;
384 | else $.extend(this.caldata, caldata);
385 | this._generateTemplate(false);
386 | },
387 | // goes to today's month/year
388 | gotoNow : function(callback) {
389 | this.month = this.today.getMonth();
390 | this.year = this.today.getFullYear();
391 | this._generateTemplate(false, callback);
392 | },
393 | // goes to month/year
394 | gotoMonth : function(month, year, callback){
395 | this.month = month - 1;
396 | this.year = year;
397 | this._generateTemplate(false, callback);
398 | },
399 | gotoPreviousMonth : function(callback){
400 | this._move('month', 'previous', callback);
401 | },
402 | gotoPreviousYear : function(callback){
403 | this._move('year', 'previous', callback);
404 | },
405 | gotoNextMonth : function(callback){
406 | this._move('month', 'next', callback);
407 | },
408 | gotoNextYear : function(callback){
409 | this._move('year', 'next', callback);
410 | },
411 | feed : function(callback){
412 | var self = this;
413 | $.post(self.options.feedParser, {dates: this.caldata})
414 | .always(function(data){
415 | if(callback) callback.call(this, JSON.parse(data).hevent);
416 | });
417 | },
418 | version : function() {
419 | return this.VERSION;
420 | }
421 | };
422 |
423 | var logError = function(message){
424 | throw new Error(message);
425 | };
426 |
427 | $.fn.calendario = function(options) {
428 | var instance = $.data(this, 'calendario');
429 | if(typeof options === 'string'){
430 | var args = Array.prototype.slice.call(arguments, 1);
431 | this.each(function(){
432 | if(!instance){
433 | logError("Cannot call methods on calendario prior to initialization; Attempted to call method '" + options + "'");
434 | return;
435 | }
436 | if (!$.isFunction(instance[options]) || options.charAt(0) === "_"){
437 | logError("No such method '" + options + "' for calendario instance.");
438 | }
439 | instance[options].apply(instance, args);
440 | });
441 | } else {
442 | this.each(function(){
443 | if (instance) instance._init();
444 | else instance = $.data(this, 'calendario', new $.Calendario(options, this));
445 | });
446 | }
447 | instance.$el.trigger($.Event('shown.calendar.calendario'), [instance]);
448 | return instance;
449 | };
450 | })(jQuery, window);
451 |
--------------------------------------------------------------------------------