1// Generated by CoffeeScript 1.6.1 2 3/*! 4 # Responsive Celendar widget script 5 # by w3widgets 6 # 7 # Author: Lukasz Kokoszkiewicz 8 # 9 # Copyright ̩̉ w3widgets 2013 All Rights Reserved 10*/ 11 12 13(function() { 14 15 (function($) { 16 "use strict"; 17 var Calendar, opts, spy; 18 Calendar = function(element, options) { 19 var time; 20 this.$element = element; 21 this.options = options; 22 this.weekDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; 23 this.time = new Date(); 24 this.currentYear = this.time.getFullYear(); 25 this.currentMonth = this.time.getMonth(); 26 if (this.options.time) { 27 time = this.splitDateString(this.options.time); 28 this.currentYear = time.year; 29 this.currentMonth = time.month; 30 } 31 this.initialDraw(); 32 return null; 33 }; 34 Calendar.prototype = { 35 addLeadingZero: function(num) { 36 if (num < 10) { 37 return "0" + num; 38 } else { 39 return "" + num; 40 } 41 }, 42 applyTransition: function($el, transition) { 43 $el.css('transition', transition); 44 $el.css('-ms-transition', '-ms-' + transition); 45 $el.css('-moz-transition', '-moz-' + transition); 46 return $el.css('-webkit-transition', '-webkit-' + transition); 47 }, 48 applyBackfaceVisibility: function($el) { 49 $el.css('backface-visibility', 'hidden'); 50 $el.css('-ms-backface-visibility', 'hidden'); 51 $el.css('-moz-backface-visibility', 'hidden'); 52 return $el.css('-webkit-backface-visibility', 'hidden'); 53 }, 54 applyTransform: function($el, transform) { 55 $el.css('transform', transform); 56 $el.css('-ms-transform', transform); 57 $el.css('-moz-transform', transform); 58 return $el.css('-webkit-transform', transform); 59 }, 60 splitDateString: function(dateString) { 61 var day, month, time, year; 62 time = dateString.split('-'); 63 year = parseInt(time[0]); 64 month = parseInt(time[1] - 1); 65 day = parseInt(time[2]); 66 return time = { 67 year: year, 68 month: month, 69 day: day 70 }; 71 }, 72 initialDraw: function() { 73 return this.drawDays(this.currentYear, this.currentMonth); 74 }, 75 editDays: function(events) { 76 var dateString, day, dayEvents, time, _results; 77 _results = []; 78 for (dateString in events) { 79 dayEvents = events[dateString]; 80 this.options.events[dateString] = events[dateString]; 81 time = this.splitDateString(dateString); 82 day = this.$element.find('[data-year="' + time.year + '"][data-month="' + (time.month + 1) + '"][data-day="' + time.day + '"]').parent('.day'); 83 day.removeClass('active'); 84 day.find('.badge').remove(); 85 day.find('a').removeAttr('href'); 86 if (this.currentMonth === time.month || this.options.activateNonCurrentMonths) { 87 _results.push(this.makeActive(day, dayEvents)); 88 } else { 89 _results.push(void 0); 90 } 91 } 92 return _results; 93 }, 94 clearDays: function(days) { 95 var dateString, day, time, _i, _len, _results; 96 _results = []; 97 for (_i = 0, _len = days.length; _i < _len; _i++) { 98 dateString = days[_i]; 99 delete this.options.events[dateString]; 100 time = this.splitDateString(dateString); 101 day = this.$element.find('[data-year="' + time.year + '"][data-month="' + (time.month + 1) + '"][data-day="' + time.day + '"]').parent('.day'); 102 day.removeClass('active'); 103 day.find('.badge').remove(); 104 _results.push(day.find('a').removeAttr('href')); 105 } 106 return _results; 107 }, 108 clearAll: function() { 109 var day, days, i, _i, _len, _results; 110 this.options.events = {}; 111 days = this.$element.find('[data-group="days"] .day'); 112 _results = []; 113 for (i = _i = 0, _len = days.length; _i < _len; i = ++_i) { 114 day = days[i]; 115 $(day).removeClass('active'); 116 $(day).find('.badge').remove(); 117 _results.push($(day).find('a').removeAttr('href')); 118 } 119 return _results; 120 }, 121 setMonth: function(dateString) { 122 var time; 123 time = this.splitDateString(dateString); 124 return this.currentMonth = this.drawDays(time.year, time.month); 125 }, 126 prev: function() { 127 if (this.currentMonth - 1 < 0) { 128 this.currentYear = this.currentYear - 1; 129 this.currentMonth = 11; 130 } else { 131 this.currentMonth = this.currentMonth - 1; 132 } 133 this.drawDays(this.currentYear, this.currentMonth); 134 if (this.options.onMonthChange) { 135 this.options.onMonthChange.call(this); 136 } 137 return null; 138 }, 139 next: function() { 140 if (this.currentMonth + 1 > 11) { 141 this.currentYear = this.currentYear + 1; 142 this.currentMonth = 0; 143 } else { 144 this.currentMonth = this.currentMonth + 1; 145 } 146 this.drawDays(this.currentYear, this.currentMonth); 147 if (this.options.onMonthChange) { 148 this.options.onMonthChange.call(this); 149 } 150 return null; 151 }, 152 addOthers: function(day, dayEvents) { 153 var badge; 154 if (typeof dayEvents === "object") { 155 if (dayEvents.number != null) { 156 badge = $("<span></span>").html(dayEvents.number).addClass("badge"); 157 if (dayEvents.badgeClass != null) { 158 badge.addClass(dayEvents.badgeClass); 159 } 160 day.append(badge); 161 } 162 if (dayEvents.url) { 163 day.find("a").attr("href", dayEvents.url); 164 } 165 } 166 return day; 167 }, 168 makeActive: function(day, dayEvents) { 169 var classes, eventClass, i, _i, _len; 170 if (dayEvents) { 171 if (dayEvents["class"]) { 172 classes = dayEvents["class"].split(" "); 173 for (i = _i = 0, _len = classes.length; _i < _len; i = ++_i) { 174 eventClass = classes[i]; 175 day.addClass(eventClass); 176 } 177 } else { 178 day.addClass("active"); 179 } 180 day = this.addOthers(day, dayEvents); 181 } 182 return day; 183 }, 184 getDaysInMonth: function(year, month) { 185 return new Date(year, month + 1, 0).getDate(); 186 }, 187 drawDay: function(lastDayOfMonth, yearNum, monthNum, dayNum, i) { 188 var calcDate, dateNow, dateString, day, dayDate, pastFutureClass; 189 day = $("<div></div>").addClass("day"); 190 dateNow = new Date(); 191 dateNow.setHours(0, 0, 0, 0); 192 dayDate = new Date(yearNum, monthNum - 1, dayNum); 193 if (dayDate.getTime() < dateNow.getTime()) { 194 pastFutureClass = "past"; 195 } else if (dayDate.getTime() === dateNow.getTime()) { 196 pastFutureClass = "today"; 197 } else { 198 pastFutureClass = "future"; 199 } 200 day.addClass(this.weekDays[i % 7]); 201 day.addClass(pastFutureClass); 202 dateString = yearNum + "-" + this.addLeadingZero(monthNum) + "-" + this.addLeadingZero(dayNum); 203 if (dayNum <= 0 || dayNum > lastDayOfMonth) { 204 calcDate = new Date(yearNum, monthNum - 1, dayNum); 205 dayNum = calcDate.getDate(); 206 monthNum = calcDate.getMonth() + 1; 207 yearNum = calcDate.getFullYear(); 208 day.addClass("not-current").addClass(pastFutureClass); 209 if (this.options.activateNonCurrentMonths) { 210 dateString = yearNum + "-" + this.addLeadingZero(monthNum) + "-" + this.addLeadingZero(dayNum); 211 } 212 } 213 day.append($("<a>" + dayNum + "</a>").attr("data-day", dayNum).attr("data-month", monthNum).attr("data-year", yearNum)); 214 if (this.options.monthChangeAnimation) { 215 this.applyTransform(day, 'rotateY(180deg)'); 216 this.applyBackfaceVisibility(day); 217 } 218 day = this.makeActive(day, this.options.events[dateString]); 219 return this.$element.find('[data-group="days"]').append(day); 220 }, 221 drawDays: function(year, month) { 222 var currentMonth, day, dayBase, days, delay, draw, firstDayOfMonth, i, lastDayOfMonth, loopBase, monthNum, multiplier, thisRef, time, timeout, yearNum, _i, _len; 223 thisRef = this; 224 time = new Date(year, month); 225 currentMonth = time.getMonth(); 226 monthNum = time.getMonth() + 1; 227 yearNum = time.getFullYear(); 228 time.setDate(1); 229 firstDayOfMonth = this.options.startFromSunday ? time.getDay() + 1 : time.getDay() || 7; 230 lastDayOfMonth = this.getDaysInMonth(year, month); 231 timeout = 0; 232 if (this.options.monthChangeAnimation) { 233 days = this.$element.find('[data-group="days"] .day'); 234 for (i = _i = 0, _len = days.length; _i < _len; i = ++_i) { 235 day = days[i];
236 delay = i * 0.01; 237 this.applyTransition($(day), 'transform .5s ease ' + delay + 's'); 238 this.applyTransform($(day), 'rotateY(180deg)'); 239 this.applyBackfaceVisibility($(day)); 240 timeout = (delay + 0.1) * 1000; 241 } 242 } 243 dayBase = 2; 244 if (this.options.allRows) { 245 loopBase = 42; 246 } else { 247 multiplier = Math.ceil((firstDayOfMonth - (dayBase - 1) + lastDayOfMonth) / 7); 248 loopBase = multiplier * 7; 249 } 250 this.$element.find("[data-head-year]").html(time.getFullYear()); 251 this.$element.find("[data-head-month]").html(this.options.translateMonths[time.getMonth()]); 252 draw = function() { 253 var dayNum, setEvents; 254 thisRef.$element.find('[data-group="days"]').empty(); 255 dayNum = dayBase - firstDayOfMonth; 256 i = thisRef.options.startFromSunday ? 0 : 1; 257 while (dayNum < loopBase - firstDayOfMonth + dayBase) { 258 thisRef.drawDay(lastDayOfMonth, yearNum, monthNum, dayNum, i); 259 dayNum = dayNum + 1; 260 i = i + 1; 261 } 262 setEvents = function() { 263 var _j, _len1; 264 days = thisRef.$element.find('[data-group="days"] .day'); 265 for (i = _j = 0, _len1 = days.length; _j < _len1; i = ++_j) { 266 day = days[i]; 267 thisRef.applyTransition($(day), 'transform .5s ease ' + (i * 0.01) + 's'); 268 thisRef.applyTransform($(day), 'rotateY(0deg)'); 269 } 270 if (thisRef.options.onDayClick) { 271 thisRef.$element.find('[data-group="days"] .day a').click(function() { 272 return thisRef.options.onDayClick.call(this, thisRef.options.events); 273 }); 274 } 275 if (thisRef.options.onDayHover) { 276 thisRef.$element.find('[data-group="days"] .day a').hover(function() { 277 return thisRef.options.onDayHover.call(this, thisRef.options.events); 278 }); 279 } 280 if (thisRef.options.onActiveDayClick) { 281 thisRef.$element.find('[data-group="days"] .day.active a').click(function() { 282 return thisRef.options.onActiveDayClick.call(this, thisRef.options.events); 283 }); 284 } 285 if (thisRef.options.onActiveDayHover) { 286 return thisRef.$element.find('[data-group="days"] .day.active a').hover(function() { 287 return thisRef.options.onActiveDayHover.call(this, thisRef.options.events); 288 }); 289 } 290 }; 291 return setTimeout(setEvents, 0); 292 }; 293 setTimeout(draw, timeout); 294 return currentMonth; 295 } 296 }; 297 $.fn.responsiveCalendar = function(option, params) { 298 var init, options, publicFunc; 299 if (params == null) { 300 params = void 0; 301 } 302 options = $.extend({}, $.fn.responsiveCalendar.defaults, typeof option === 'object' && option); 303 publicFunc = { 304 next: 'next', 305 prev: 'prev', 306 edit: 'editDays', 307 clear: 'clearDays', 308 clearAll: 'clearAll' 309 }; 310 init = function($this) { 311 var data; 312 options = $.metadata ? $.extend({}, options, $this.metadata()) : options; 313 $this.data('calendar', (data = new Calendar($this, options))); 314 if (options.onInit) { 315 options.onInit.call(data); 316 } 317 return $this.find("[data-go]").click(function() { 318 if ($(this).data("go") === "prev") { 319 data.prev(); 320 } 321 if ($(this).data("go") === "next") { 322 return data.next(); 323 } 324 }); 325 }; 326 return this.each(function() { 327 var $this, data; 328 $this = $(this); 329 data = $this.data('calendar'); 330 if (!data) { 331 init($this); 332 } else if (typeof option === 'string') { 333 if (publicFunc[option] != null) { 334 data[publicFunc[option]](params); 335 } else { 336 data.setMonth(option); 337 } 338 } else if (typeof option === 'number') { 339 data.jump(Math.abs(option) + 1); 340 } 341 return null; 342 }); 343 }; 344 $.fn.responsiveCalendar.defaults = { 345 translateMonths: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
345November", "December"], 346 events: {}, 347 time: void 0, 348 allRows: true, 349 startFromSunday: false, 350 activateNonCurrentMonths: false, 351 monthChangeAnimation: true, 352 onInit: void 0, 353 onDayClick: void 0, 354 onDayHover: void 0, 355 onActiveDayClick: void 0, 356 onActiveDayHover: void 0, 357 onMonthChange: void 0 358 }; 359 spy = $('[data-spy="responsive-calendar"]'); 360 if (spy.length) { 361 opts = {}; 362 if ((spy.data('translate-months')) != null) { 363 opts.translateMonths = spy.data('translate-months').split(','); 364 } 365 if ((spy.data('time')) != null) { 366 opts.time = spy.data('time'); 367 } 368 if ((spy.data('all-rows')) != null) { 369 opts.allRows = spy.data('all-rows'); 370 } 371 if ((spy.data('start-from-sunday')) != null) { 372 opts.startFromSunday = spy.data('start-from-sunday'); 373 } 374 if ((spy.data('activate-non-current-months')) != null) { 375 opts.activateNonCurrentMonths = spy.data('activate-non-current-months'); 376 } 377 if ((spy.data('month-change-animation')) != null) { 378 opts.monthChangeAnimation = spy.data('month-change-animation'); 379 } 380 return spy.responsiveCalendar(opts); 381 } 382 })(jQuery); 383 384}).call(this);
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.