PageSourceSearch

https://uralskie-pelmeni.com/js/calendar.js

js uralskie-pelmeni.com collected 2026-10-04 22:36:51 UTC 9,120 bytes, 281 lines download raw bytes

1/**
2 * jQuery calendarLite2 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 $(document).ready(function(){
13    $('#dateevents').calendarLite2({
14        linkFormat: '/afisha/date/{%mm}-{%dd}/'
15    });
16});
17//]]>
18
19;(function($){
20    $.fn.calendarLite2 = function(options) {
21        var opts = $.extend({}, $.fn.calendarLite2.defaults, options);
22        return this.each(function() {
23            $this = $(this);
24            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
25            $.fn.calendarLite2.draw(o);
26        });
27    };
28    
29    /**
30     * Get calendar's header (day names)
31     * @param {Object} opts
32     */
33    $.fn.calendarLite2.getHead = function(opts) {
34	    var html = [];
35	    for (var i = 0; i < opts.days.length; i++) {
36	        html.push('<th>' + opts.days[i] + '</th>');
37	    }
38	    return html.join('');
39    };
40    
41    /**
42     * Main function for drawing calendar
43     * @param {Object} opts
44     */
45    $.fn.calendarLite2.draw = function(opts) {
46        var o = $.extend({}, this.defaults, opts);
47        
48        month = parseInt(o.month, 10);
49        year = parseInt(o.year, 10);
50
51        var today = new Date();
52        var srcDate = new Date();
53        if (!isNaN(year)) {
54            srcDate.setDate(1);
55            srcDate.setFullYear(year);
56        }
57        if (!isNaN(month)) {
58            srcDate.setDate(1);
59            srcDate.setMonth(month);
60        }
61        var curDate = srcDate.getDate();
62        var curMonth = srcDate.getMonth();
63        var curYear = srcDate.getFullYear();
64
65        var dates = [];
66        var dayCount = new Date(curYear, curMonth + 1, 0).getDate();
67        for (var i = 1; i <= dayCount; i++) {
68            var tmpDate = new Date(curYear, curMonth, i);
69            if (tmpDate.getMonth() == curMonth && tmpDate.getFullYear() == curYear) {
70                dates.push(tmpDate);
71            }
72        }
73
74        var table = $('<table cellspacing="1" class="table"></table>');
75        var str = '<tbody><tr>' + this.getHead(o) + '</tr>', cl = '';
76        var line = [];
77        for (var j = 0; j < dates.length; j++) {
78            var day = dates[j].getDay();
79            var month = dates[j].getMonth();
80            var year = dates[j].getFullYear();
81            
82            var date = dates[j].getDate();
83            var rel = _formatLink(o.dateFormat, dates[j]);
84            cl = '';
85            if (date == today.getDate() && curMonth == today.getMonth() && curYear == today.getFullYear()) {
86                cl = ' class="curr"';
87            } else if (day == 6 || day == 0) {
88                cl = ' class="weekend"';
89            }
90            var href = '#';
91            if (o.linkFormat != null && o.linkFormat != undefined) {
92                href = _formatLink(o.linkFormat, dates[j]);
93            }
94            line.push('<td' + cl + '><a href="' + href + '" rel="' + rel + '">' + date + '</a></td>');
95            if (dates[j].getDay() == 0) {
96                if (line.length < 7) {
97                    var ln = line.length;
98                    var pad = [];
99                    for (var k = 0; k < (7 - ln); k++) {
100                        pad.push('<td style="background: none">&nbsp;</td>');
101                    }
102                    line = pad.concat(line);
103                }
104                str += '<tr>' + line.join('') + '</tr>';
105                line = [];
106            } else if (j == (dates.length - 1)) {
107                str += '<tr>' + line.join('') + '</tr>';
108            }
109        }
110        str += '</tbody>';
111        table.html(str);
112        if (typeof o.onSelect == 'function') {
113            table.find('a').click(function(){
114                return o.onSelect($(this).attr('rel'));
115            });
116        }
117        var y = '';
118        if (o.showYear == true) {
119            y = ' ' + curYear + ' ';
120        }
121        $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>';
122        $this.append(table)
123             .find('.monthName').width($this.find('.table'));
124        this.next($this.find('.next'), o);
125        this.prev($this.find('.prev'), o);
126    };
127    
128    /**
129     * Format link
130     * @param {String} format
131     * @param {Object} objDate
132     */
133    function _formatLink(format, objDate) {
134        var date = objDate.getDate();
135        var month = objDate.getMonth() + 1;
136        var year = objDate.getFullYear();
137        if (format.indexOf('{%dd}') != -1) {
138            date = _formatNum(date);
139        }
140        if (format.indexOf('{%mm}') != -1) {
141            month = _formatNum(month);
142        }
143        if (format.indexOf('{%yy}') != -1) {
144            year = year.toString().slice(2);
145        }
146        var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year);
147        return link;
148    };
149    
150    /**
151     * Format date for link's 'rel' attribute
152     * @param {String} format
153     * @param {Object} objDate
154     */
155    function _formatDate(format, objDate) {
156        var date = objDate.getDate();
157        var month = objDate.getMonth();
158        var year = objDate.getFullYear();
159        if (format.indexOf('{%dd}') != -1) {
160            date = _formatNum(date);
161        }
162        if (format.indexOf('{%mm}') != -1) {
163            month = _formatNum(month);
164        }
165        if (format.indexOf('{%yy}') != -1) {
166            year = year.toString().slice(2);
167        }
168        month++;
169        var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year);
170        return link;
171    };
172    
173    /**
174     * Show next month
175     */
176    $.fn.calendarLite2.next = function(button, o) {
177        this.change(button, 1, o);
178    };
179    
180    /**
181     * Show previous month
182     * @param {Object} button
183     */
184    $.fn.calendarLite2.prev = function(button, o) {
185        this.change(button, -1, o);
186    };
187    
188    /**
189     * Switch to another month
190     * @param {Object} button
191     * @param {Integer} monthDelta
192     */
193    $.fn.calendarLite2.change = function(button, monthDelta, o) {
194        var opts = $.extend({}, $.fn.calendarLite2.defaults, o);
195        var _self = this;
196        var parent = button.parent('.monthName').parent();
197        button.click(function(){
198            var state = _self.getState(parent);
199            var d = new Date(state[1], state[0] + monthDelta, 1);
200            opts.month = d.getMonth();
201            opts.year  = d.getFullYear();
202            parent.calendarLite2(opts);
203            return false;
204        });
205    };
206    
207    /**
208     * Get current calendar's state (month and year)
209     */
210    $.fn.calendarLite2.getState = function(div) {
211        var st = div.find('.state')[0].innerHTML.split('.');
212        return [parseInt(st[0], 10), parseInt(st[1], 10)];
213    };
214    
215    /**
216     * Format number (pad with zero)
217     * @param {Integer} num
218     */
219    function _formatNum(num) {
220        num = parseInt(num, 10);
221        if (num < 10) {
222            return '0' + num;
223        }
224        return num;
225    };
226    
227    /**
228     * Default options
229     */
230    $.fn.calendarLite2.defaults = {
231        /**
232         * Names of week's days
233         */
234        days: ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС'],
235        
236        /**
237         * Month names
238         */
239        months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август',
240                 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
241        
242        /**
243         * Link to be assigned for each link in cell:
244         *   e.g.: http://snowcore.net/events/{%dd}-{%mm}-{%yyyy}
245         * 
246         * Possible values:
247         *   {%dd} - date with leading zero
248         *   {%d}  - date without leading zero
249         *   {%mm} - month with leading zero
250         *   {%m}  - month without leading zero
251         *   {%yy} - yar (two digits)
252         *   {%yyyy}  - full year (for digits)
253         */
254        linkFormat: null,
255        
256        /**
257         * Format for date in 'rel' attribute (onSelect callback function retrieves this value)
258         * Formatting options are the same as for 'linkFormat' option
259         * Default: mm.dd.yyyy ('{%dd}.{%mm}.{%yyyy}')
260         */
261        dateFormat: '{%dd}.{%mm}.{%yyyy}',
262        
263        /**
264         * Callback function, fires when user click on the cell
265         * Function retrives one parameter - date
266         * (in format that has been assigned by 'dateFormat' option):
267         */
268        onSelect: null,
269        
270        /**
271         * When set to true, full year is displaying in the calendar caption
272         */
273        showYear: false,
274        
275        /**
276         * Prev/Next arrows (you can also use &larr; and &rarr;)
277         */
278        prevArrow: '',
279        nextArrow: ''
280    };
281})(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.