' ).append( head, body );
this.$el.find( 'div.fc-calendar' ).remove().end().append( this.$cal );
if( callback ) { callback.call(); }
},
_getHead : function() {
var html = '
';
return html;
},
_getBody : function() {
var d = new Date( this.year, this.month + 1, 0 ),
// number of days in the month
monthLength = d.getDate(),
firstDay = new Date( this.year, this.month, 1 );
// day of the week
this.startingDay = firstDay.getDay();
var html = '
',
// fill in the days
day = 1;
// this loop is for weeks (rows)
for ( var i = 0; i < 7; i++ ) {
// this loop is for weekdays (cells)
for ( var j = 0; j <= 6; j++ ) {
var pos = this.startingDay - this.options.startIn,
p = pos < 0 ? 6 + pos + 1 : pos,
inner = '',
today = this.month === this.today.getMonth() && this.year === this.today.getFullYear() && day === this.today.getDate(),
content = '';
if ( day <= monthLength && ( i > 0 || j >= p ) ) {
inner += '
' + day + '' + this.options.weekabbrs[ j + this.options.startIn > 6 ? j + this.options.startIn - 6 - 1 : j + this.options.startIn ] + '';
// this day is:
var strdate = ( this.month + 1 < 10 ? '0' + ( this.month + 1 ) : this.month + 1 ) + '-' + ( day < 10 ? '0' + day : day ) + '-' + this.year,
dayData = this.caldata[ strdate ];
if( dayData ) {
content = dayData;
}
if( content !== '' ) {
inner += '
' + content + '
';
}
++day;
}
else {
today = false;
}
var cellClasses = today ? 'fc-today ' : '';
if( content !== '' ) {
cellClasses += 'fc-content';
var str = 'register';
if (/register/.test(content)) {
cellClasses += ' yellow';
}
}
html += cellClasses !== '' ? '
' : '
';
html += inner;
html += '
';
}
// stop making rows if we've run out of days
if (day > monthLength) {
this.rowTotal = i + 1;
break;
}
else {
html += '
';
}
}
html += '
';
return html;
},
// based on http://stackoverflow.com/a/8390325/989439
_isValidDate : function( date ) {
date = date.replace(/-/gi,'');
var month = parseInt( date.substring( 0, 2 ), 10 ),
day = parseInt( date.substring( 2, 4 ), 10 ),
year = parseInt( date.substring( 4, 8 ), 10 );
if( ( month < 1 ) || ( month > 12 ) ) {
return false;
}
else if( ( day < 1 ) || ( day > 31 ) ) {
return false;
}
else if( ( ( month == 4 ) || ( month == 6 ) || ( month == 9 ) || ( month == 11 ) ) && ( day > 30 ) ) {
return false;
}
else if( ( month == 2 ) && ( ( ( year % 400 ) == 0) || ( ( year % 4 ) == 0 ) ) && ( ( year % 100 ) != 0 ) && ( day > 29 ) ) {
return false;
}
else if( ( month == 2 ) && ( ( year % 100 ) == 0 ) && ( day > 29 ) ) {
return false;
}
return {
day : day,
month : month,
year : year
};
},
_move : function( period, dir, callback ) {
if( dir === 'previous' ) {
if( period === 'month' ) {
this.year = this.month > 0 ? this.year : --this.year;
this.month = this.month > 0 ? --this.month : 11;
}
else if( period === 'year' ) {
this.year = --this.year;
}
}
else if( dir === 'next' ) {
if( period === 'month' ) {
this.year = this.month < 11 ? this.year : ++this.year;
this.month = this.month < 11 ? ++this.month : 0;
}
else if( period === 'year' ) {
this.year = ++this.year;
}
}
this._generateTemplate( callback );
},
/*************************
******PUBLIC METHODS *****
**************************/
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 ];
},
// gets the cell's content div associated to a day of the current displayed month
// day : 1 - [28||29||30||31]
getCell : function( day ) {
var row = Math.floor( ( day + this.startingDay - this.options.startIn ) / 7 ),
pos = day + this.startingDay - this.options.startIn - ( row * 7 ) - 1;
return this.$cal.find( 'div.fc-body' ).children( 'div.fc-row' ).eq( row ).children( 'div' ).eq( pos ).children( 'div' );
},
setData : function( caldata ) {
caldata = caldata || {};
$.extend( this.caldata, caldata );
this._generateTemplate();
},
// goes to today's month/year
gotoNow : function( callback ) {
this.month = this.today.getMonth();
this.year = this.today.getFullYear();
this._generateTemplate( callback );
},
// goes to month/year
goto : function( month, year, callback ) {
this.month = month;
this.year = year;
this._generateTemplate( callback );
},
gotoPreviousMonth : function( callback ) {
this._move( 'month', 'previous', callback );
},
gotoPreviousYear : function( callback ) {
this._move( 'year', 'previous', callback );
},
gotoNextMonth : function( callback ) {
this._move( 'month', 'next', callback );
},
gotoNextYear : function( callback ) {
this._move( 'year', 'next', callback );
}
};
var logError = function( message ) {
if ( window.console ) {
window.console.error( message );
}
};
$.fn.calendario = function( options ) {
var instance = $.data( this, 'calendario' );
if ( typeof options === 'string' ) {
var args = Array.prototype.slice.call( arguments, 1 );
this.each(function() {
if ( !instance ) {
logError( "cannot call methods on calendario prior to initialization; " +
"attempted to call method '" + options + "'" );
return;
}
if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
logError( "no such method '" + options + "' for calendario instance" );
return;
}
instance[ options ].apply( instance, args );
});
}
else {
this.each(function() {
if ( instance ) {
instance._init();
}
else {
instance = $.data( this, 'calendario', new $.Calendario( options, this ) );
}
});
}
return instance;
};
} )( jQuery, window );