1/** 2 * jQuery calendarLite plugin 3 * 4 * Copyright (c) 2009 Snitko Roman 5 * Dual licensed under the MIT (MIT-LICENSE.txt) 6 * and GPL (GPL-LICENSE.txt) licenses. 7 * 8 * @author Roman Snitko [email protected] 9 * @link http://snowcore.net/ 10 * @version 0.1.11 11 */ 12;(function($){ 13 $.fn.calendarLite = function(options) { 14 var opts = $.extend({}, $.fn.calendarLite.defaults, options); 15 return this.each(function() { 16 $this = $(this); 17 var o = $.meta ? $.extend({}, opts, $this.data()) : opts; 18 $.fn.calendarLite.draw(o); 19 }); 20 }; 21 22 /** 23 * Get calendar's header (day names) 24 * @param {Object} opts 25 */ 26 $.fn.calendarLite.getHead = function(opts) { 27 var html = []; 28 for (var i = 0; i < opts.days.length; i++) { 29 /* some modification 06 April 2010 */ 30 if (i > 4) 31 html.push('<th class="weekend">' + opts.days[i] + '</th>'); 32 else 33 html.push('<th>' + opts.days[i] + '</th>'); 34 } 35 return html.join(''); 36 }; 37 38 /** 39 * Main function for drawing calendar 40 * @param {Object} opts 41 */ 42 $.fn.calendarLite.draw = function(opts) { 43 var o = $.extend({}, this.defaults, opts); 44 45 month = parseInt(o.month, 10); 46 year = parseInt(o.year, 10); 47 48 /* try to add sected date different from current 07 April 2010 */ 49 var selDay = parseInt(o.selday,10); 50 var selMonth = parseInt(o.selmonth,10); 51 var selYear = parseInt(o.selyear); 52 var selDate = new Date(); 53 if (!isNaN(selDay)) { 54 selDate.setDate(selDay); 55 } 56 if (!isNaN(selMonth)) { 57 selDate.setMonth(selMonth-1); 58 } 59 if (!isNaN(selYear)) { 60 //alert('selyear='+selYear); 61 selDate.setFullYear(selYear); 62 } 63 64 65 //alert(selDate.getDate()+'.'+selDate.getMonth()+'.'+selDate.getFullYear()); 66 /* end of trying */ 67 68 var today = new Date(); 69 var srcDate = new Date(); 70 if (!isNaN(year)) { 71 srcDate.setDate(1); 72 srcDate.setFullYear(year); 73 } 74 if (!isNaN(month)) { 75 srcDate.setDate(1); 76 srcDate.setMonth(month); 77 } 78 var curDate = srcDate.getDate(); 79 var curMonth = srcDate.getMonth(); 80 var curYear = srcDate.getFullYear(); 81 82 var dates = []; 83 var dayCount = new Date(curYear, curMonth + 1, 0).getDate(); 84 for (var i = 1; i <= dayCount; i++) { 85 var tmpDate = new Date(curYear, curMonth, i); 86 if (tmpDate.getMonth() == curMonth && tmpDate.getFullYear() == curYear) { 87 dates.push(tmpDate); 88 } 89 } 90 91 var table = $('<table cellspacing="1" class="table"></table>'); 92 var str = '<tbody><tr>' + this.getHead(o) + '</tr>', cl = ''; 93 var line = []; 94 for (var j = 0; j < dates.length; j++) { 95 var day = dates[j].getDay(); 96 var month = dates[j].getMonth(); 97 var year = dates[j].getFullYear(); 98 99 var date = dates[j].getDate(); 100 var rel = _formatLink(o.dateFormat, dates[j]); 101 cl = ''; 102 if (date == today.getDate() && curMonth == today.getMonth() && curYear == today.getFullYear()) { 103 cl = ' class="curr"'; 104 } else if (date == selDate.getDate() && curMonth == selDate.getMonth() && curYear == selDate.getFullYear()) { 105 cl = ' class="sell"'; 106 // alert('ggggg!'); 107 } else if (day == 6 || day == 0) { 108 cl = ' class="weekend"'; 109 } 110 var href = '#'; 111 if (o.linkFormat != null && o.linkFormat != undefined) { 112 href = _formatLink(o.linkFormat, dates[j]); 113 } 114 line.push('<td' + cl + '><a href="' + href + '" rel="' + rel + '">' + date + '</a></td>'); 115 if (dates[j].getDay() == 0) { 116 if (line.length < 7) { 117 var ln = line.length; 118 var pad = []; 119 for (var k = 0; k < (7 - ln); k++) { 120 pad.push('<td class="empt">
120 </td>'); 121 } 122 line = pad.concat(line); 123 } 124 str += '<tr>' + line.join('') + '</tr>'; 125 line = []; 126 } else if (j == (dates.length - 1)) { 127 /* draw empty cells in the end of month */ 128 if(dates[j].getDay() != 0) { 129 if (line.length < 7) { 130 var ln = line.length; 131 var pad = []; 132 for (var k = 0; k < (7 - ln); k++) { 133 pad.push('<td class="empt"> </td>'); 134 } 135 line = line.concat(pad); 136 } 137 } 138 str += '<tr>' + line.join('') + '</tr>'; 139 } 140 } 141 str += '</tbody>'; 142 table.html(str); 143 if (typeof o.onSelect == 'function') { 144 table.find('a').click(function(){ 145 return o.onSelect($(this).attr('rel')); 146 }); 147 table.find('td:not(.empt)').click(function(){ 148 return o.onSelect($(this).children('a').attr('rel')); 149 }); 150 } 151 var y = ''; 152 if (o.showYear == true) { 153 y = ' ' + curYear + ' '; 154 } 155 $this[0].innerHTML = '<span class="state" style="display:none;">' + curMonth + '.' + curYear + '</span><div class="monthName"><a href="#" class="next">' + o.nextArrow + '</a><a href="#" class="prev">' + o.prevArrow + '</a> ' + o.months[curMonth] + y + ' </div>'; 156 $this.append(table) 157 .find('.monthName')/*.width($this.find('.table').width())*/; 158 this.next($this.find('.next'), o); 159 this.prev($this.find('.prev'), o); 160 }; 161 162 /** 163 * Format link 164 * @param {String} format 165 * @param {Object} objDate 166 */ 167 function _formatLink(format, objDate) { 168 var date = objDate.getDate(); 169 var month = objDate.getMonth() + 1; 170 var year = objDate.getFullYear(); 171 if (format.indexOf('{%dd}') != -1) {
172 date = _formatNum(date); 173 } 174 if (format.indexOf('{%mm}') != -1) { 175 month = _formatNum(month); 176 } 177 if (format.indexOf('{%yy}') != -1) { 178 year = year.toString().slice(2); 179 } 180 var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year); 181 return link; 182 }; 183 184 /** 185 * Format date for link's 'rel' attribute 186 * @param {String} format 187 * @param {Object} objDate 188 */ 189 function _formatDate(format, objDate) { 190 var date = objDate.getDate(); 191 var month = objDate.getMonth(); 192 var year = objDate.getFullYear(); 193 if (format.indexOf('{%dd}') != -1) { 194 date = _formatNum(date); 195 } 196 if (format.indexOf('{%mm}') != -1) { 197 month = _formatNum(month); 198 } 199 if (format.indexOf('{%yy}') != -1) { 200 year = year.toString().slice(2); 201 } 202 month++; 203 var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year); 204 return link; 205 }; 206 207 /** 208 * Show next month 209 */ 210 $.fn.calendarLite.next = function(button, o) { 211 this.change(button, 1, o); 212 }; 213 214 /** 215 * Show previous month 216 * @param {Object} button 217 */ 218 $.fn.calendarLite.prev = function(button, o) { 219 this.change(button, -1, o); 220 }; 221 222 /** 223 * Switch to another month 224 * @param {Object} button 225 * @param {Integer} monthDelta 226 */ 227 $.fn.calendarLite.change = function(button, monthDelta, o) { 228 var opts = $.extend({}, $.fn.calendarLite.defaults, o); 229 var _self = this; 230 var parent = button.parent('.monthName').parent(); 231 button.click(function(){ 232 var state = _self.getState(parent); 233 var d = new Date(state[1], state[0] + monthDelta, 1); 234 opts.month = d.getMonth(); 235 opts.year = d.getFullYear(); 236 parent.calendarLite(opts); 237 return false; 238 }); 239 }; 240 241 /** 242 * Get current calendar's state (month and year) 243 */ 244 $.fn.calendarLite.getState = function(div) { 245 var st = div.find('.state')[0].innerHTML.split('.'); 246 return [parseInt(st[0], 10), parseInt(st[1], 10)]; 247 }; 248 249 /** 250 * Format number (pad with zero) 251 * @param {Integer} num 252 */ 253 function _formatNum(num) { 254 num = parseInt(num, 10); 255 if (num < 10) { 256 return '0' + num; 257 } 258 return num; 259 }; 260 261 /** 262 * Default options 263 */ 264 $.fn.calendarLite.defaults = { 265 /** 266 * Names of week's days 267 */ 268 days: ['Ðн', 'ÐÑ', 'СÑ', 'ЧÑ', 'ÐÑ', 'Сб', 'ÐÑ'], 269 270 /** 271 * Month names 272 */ 273 months: ['ЯнваÑÑ', 'ФевÑалÑ', 'ÐаÑÑ', 'ÐпÑелÑ', 'Ðай', 'ÐÑнÑ', 'ÐÑлÑ', 'ÐвгÑÑÑ', 274 'СенÑÑбÑÑ', 'ÐкÑÑбÑÑ', 'ÐоÑбÑÑ', 'ÐекабÑÑ'], 275 276 /** 277 * Link to be assigned for each link in cell: 278 * e.g.: http://snowcore.net/events/{%dd}-{%mm}-{%yyyy} 279 * 280 * Possible values: 281 * {%dd} - date with leading zero 282 * {%d} - date without leading zero 283 * {%mm} - month with leading zero 284 * {%m} - month without leading zero 285 * {%yy} - yar (two digits) 286 * {%yyyy} - full year (for digits) 287 */ 288 linkFormat: null, 289 290 /** 291 * Format for date in 'rel' attribute (onSelect callback function retrieves this value) 292 * Formatting options are the same as for 'linkFormat' option 293 * Default: mm.dd.yyyy ('{%dd}.{%mm}.{%yyyy}') 294 */ 295 dateFormat: '{%dd}.{%mm}.{%yyyy}', 296 297 /** 298 * Callback function, fires when user click on the cell 299 * Function retrives one parameter - date 300 * (in format that has been assigned by 'dateFormat' option): 301 */ 302 onSelect: null, 303 304 /** 305 * When set to true, full year is displaying in the calendar caption 306 */ 307 showYear: false, 308 309 /** 310 * Prev/Next arrows (you can also use ← and →) 311 */ 312 prevArrow: '«', 313 nextArrow: '»', 314 /** 315 * 316 */ 317 selmonth: '01', 318 selday: '01', 319 selyear: '2010' 320 }; 321})(jQuery);
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.