Comparing version 0.0.2 to 0.0.3
@@ -20,9 +20,2 @@ /** | ||
" <tr class='date-daysofweek'>" + | ||
" <th>S</th>" + | ||
" <th>M</th>" + | ||
" <th>T</th>" + | ||
" <th>W</th>" + | ||
" <th>R</th>" + | ||
" <th>F</th>" + | ||
" <th>S</th>" + | ||
" </tr>" + | ||
@@ -35,8 +28,2 @@ " </thead>" + | ||
var months = [ | ||
'January', 'February', 'March', 'April' | ||
, 'May', 'June', 'July', 'August' | ||
, 'September', 'October', 'November', 'December' | ||
] | ||
function isLeapYear(year) { | ||
@@ -49,12 +36,18 @@ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) | ||
function getMonthNumberFromName(name) { | ||
return months.indexOf(name) + 1 | ||
} | ||
function Calendar (el, options) { | ||
var self = this | ||
this.options = options || {} | ||
this.months = (this.options.months || 'January February March April May June July August September October November December').split(' ') | ||
this.$input = $(el).first() | ||
this.$calendar = $(template).appendTo('body') | ||
this.formatDate = (this.options.formatDate || function(year, month, day) { | ||
return [ month, day, year].join('-') | ||
}) | ||
this.weekStart = this.options.weekStart || 0 | ||
var daysOfWeek = (this.options.daysOfWeek || 'S M T W T F S').split(' ') | ||
daysOfWeek = daysOfWeek.slice(this.weekStart).concat(daysOfWeek.slice(0, this.weekStart)) | ||
this.$calendar.find('.date-daysofweek').append('<th>' + daysOfWeek.join('</th><th>') + '</th>') | ||
this.$calendar.delegate('tbody td', 'mouseover', function () { | ||
@@ -73,2 +66,6 @@ $(this).closest('tbody').find('td:nth-child(' + (this.cellIndex + 1) + ')').addClass('hover') | ||
var getMonthNumberFromName = function(name) { | ||
return self.months.indexOf(name) + 1 | ||
} | ||
this.$calendar.delegate('tbody td', 'mouseout', function () { | ||
@@ -79,7 +76,7 @@ $(this).closest('tbody').find('td:nth-child(' + (this.cellIndex + 1) + ')').removeClass('hover') | ||
var day = $(this).html() | ||
self.$input.val([ | ||
getMonthNumberFromName(self.$calendar.find('.date-current-month').html()) | ||
, day | ||
, self.$calendar.find('.date-current-year').html()].join('-') | ||
) | ||
self.$input.val(self.formatDate( | ||
self.$calendar.find('.date-current-year').html(), | ||
getMonthNumberFromName(self.$calendar.find('.date-current-month').html()), | ||
day | ||
)) | ||
self.$calendar.removeClass('active') | ||
@@ -92,3 +89,3 @@ }) | ||
if (--m == -1) --y && (m = 11) | ||
self.setDate(months[m] + ' 1,' + y) | ||
self.setDate([y, m + 1, 1].join('-')) | ||
}) | ||
@@ -98,5 +95,5 @@ | ||
var y = parseFloat(self.$calendar.find('.date-current-year').html()) | ||
, m = getMonthNumberFromName($('.date-current-month').html()) | ||
, m = getMonthNumberFromName(self.$calendar.find('.date-current-month').html()) | ||
if ((m == 12)) ++y && (m = 0) | ||
self.setDate(months[m] + ' 1,' + y) | ||
self.setDate([y, m + 1, 1].join('-')) | ||
}) | ||
@@ -117,5 +114,6 @@ | ||
, theDay = 0 | ||
, dateBegin = daysInPreviousMonth - monthStart | ||
, weekOffset = this.weekStart - (monthStart < this.weekStart? 7 : 0) | ||
, dateBegin = daysInPreviousMonth - monthStart + weekOffset | ||
, daysInMonth = getDaysInMonth(d.getYear(), d.getMonth()) | ||
, remainingWeeks = Math.floor((daysInMonth + monthStart - 7) / 7) | ||
, remainingWeeks = Math.floor((daysInMonth + monthStart - 7 - weekOffset) / 7) | ||
, i = 0 | ||
@@ -125,3 +123,3 @@ | ||
this.$calendar.find('.date-current-year').html(d.getFullYear()) | ||
this.$calendar.find('.date-current-month').html(months[d.getMonth()]) | ||
this.$calendar.find('.date-current-month').html(this.months[d.getMonth()]) | ||
@@ -132,3 +130,3 @@ html.push('<tr>') | ||
} | ||
while (monthStart < 7) { | ||
while (monthStart < 7 + weekOffset) { | ||
html.push('<td>' + (++theDay) + '</td>') | ||
@@ -191,2 +189,2 @@ monthStart++ | ||
}, true) | ||
}(ender); | ||
}(ender); |
{ | ||
"name": "calender" | ||
, "description": "Simple, themable, Datepicker for Ender" | ||
, "version": "0.0.2" | ||
, "version": "0.0.3" | ||
, "homepage": "https://github.com/ded/calEnder" | ||
@@ -6,0 +6,0 @@ , "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)" |
Sorry, the diff of this file is not supported yet
14369
247