var Blog = { calendar: null, o: {}, onDatesLoaded: function(data, textStatus) { Blog.o.dates = ('object' == typeof data.dates) ? data.dates : {}; $(Blog.calendar).datepicker('refresh'); }, pad: function (val, len) { val = String(val); len = len || 2; while (val.length < len) val = "0" + val; return val; }, onBeforeShowDay: function(date) { var str = date.getFullYear() + '-' + Blog.pad(date.getMonth() + 1, 2) + '-' + Blog.pad(date.getDate(), 2); if (str in Blog.o.dates) { return [true, '']; } return [false]; }, onSelect: function(dateText, inst) { location.href = qs.constant('BASE_URL') + '/' + Blog.o.viewAlias + '/' + dateText; return false; }, onChangeMonthYear: function(year, month, inst) { var data = { action: 'calendar', year: year, month: month }; Blog.o.dates = {}; $.getJSON(Blog.o.viewAlias, data, Blog.onDatesLoaded); return true; }, initCalendar: function(o) { Blog.o = o || {}; if (!Blog.o.dates || !Blog.o.viewAlias) { alert('Error Blog: dates or viewAlias is not defined in initCalendar'); return false; } var params = { dateFormat: 'yy/mm/dd', onSelect: Blog.onSelect, beforeShowDay: Blog.onBeforeShowDay, onChangeMonthYear: Blog.onChangeMonthYear } if ('minDate' in Blog.o) { params.minDate = new Date(Blog.o.minDate); } if ('maxDate' in Blog.o) { params.maxDate = new Date(Blog.o.maxDate); } Blog.calendar = $("#blog-calendar"); $(Blog.calendar).datepicker(params); }, showCommentsForm: function () { $('.post-comment-submitted-block').hide(); $('.post-comment-form-block').show(); }, initComments: function() { $(document).ready(function() { $.scrollTo("div.post-comment-form", 400); }); } }