1(function ($) { 2 Drupal.behaviors.prlib_calendar = { 3 attach: function (context, settings) { 4 var // todo: УÑоÑниÑÑ ÑелекÑоÑ. 5 $view = $('#content .view'), 6 viewAjax = false, 7 urlPath = location.pathname.substr(1), 8 locale = settings.prlib_calendar.language; 9 10 if ($view.length) { 11 // todo: ÐеÑенеÑÑи даннÑе о views в аÑÑибÑÑÑ data или полÑÑаÑÑ Ð¸Ð· settings. 12 var className = $view.attr('class').split(' '), 13 viewName = className[2].substr(8), 14 viewDisplayId = className[3].substr(16), 15 viewDomId = className[4].substr(12), 16 ajaxData = { 17 view_path: urlPath, 18 view_name: viewName, 19 view_display_id: viewDisplayId, 20 view_dom_id: viewDomId, 21 view_args: '', 22 js: true 23 }; 24 viewAjax = true; 25 } 26 27 $('#prlib-calendar-datetimepicker').once(function() { 28 var $picker = $(this); 29 30 $picker.datetimepicker({ 31 inline: true, 32 format: 'L', 33 // showClear: true, 34 // showTodayButton: true, 35 locale: locale 36 }); 37 38 // ÐÑделиÑÑ Ð²Ñе дни ÑекÑÑего меÑÑÑа. 39 $picker.selectDays = function() { 40 var $days = $('.datepicker-days', $(this)); 41 $('.day:not(".old, .new")', $days).addClass('selected'); 42 $('.day.selected:first', $days).addClass('first'); 43 $('.day.selected:last', $days).addClass('last'); 44 }; 45 46 // ÐÑделиÑÑ Ð²Ñе меÑÑÑÑ ÑекÑÑего года. 47 $picker.selectMonths = function() { 48 $('.datepicker-months .month', $(this)).addClass('selected'); 49 }; 50 51 var picker = $picker.data('DateTimePicker'); 52 53 54 // 55 // ТекÑÑее ÑоÑÑоÑние календаÑÑ. 56 // -------------------------------------------------- 57 58 var uri = new URI(), 59 query = uri.search(true); 60 61 // ÐÑли в GET пеÑедана даÑа. 62 if (typeof query.date !== 'undefined') { 63 date = query.date; 64 var match = date.match(/^\d{1,2}-\d{1,2}-\d{4}$/); 65 if (match) { 66 picker.date(moment(match[0], 'DD-M-YYYY')).locale(locale); 67 } 68 else { 69 match = date.match(/^\d{1,2}-\d{4}$/); 70 if (match) { 71 picker.date(moment(match[0], 'M-YYYY')).locale(locale); 72 $picker.selectDays(); 73 } 74 else { 75 match = date.match(/^\d{4}$/); 76 if (match) { 77 picker.date(moment(match[0], 'YYYY')).locale(locale); 78 picker.viewMode('months'); 79 $picker.selectMonths(); 80 } 81 } 82 } 83 } 84 85 86 // 87 // ÐлеменÑÑ ÑпÑавлениÑ: СегоднÑ, ÐеÑÑÑ, Ðод. 88 // -------------------------------------------------- 89 90 var $tr = $('.picker-switch tr', $picker); 91 92 $tr.append($('<td>').append($('<a>') 93 .attr({ 'data-prlib-action': 'today' }) 94 .append($('<span>').text(Drupal.t('Today'))))); 95 96 $tr.append($('<td>').append($('<a>') 97 .attr({ 'data-prlib-action': 'month' }) 98 .append($('<span>').text(Drupal.t('Month'))))); 99 100 $tr.append($('<td>').append($('<a>') 101 .attr({ 'data-prlib-action': 'year' }) 102 .append($('<span>').text(Drupal.t('Year'))))); 103 104 $('.picker-switch a', $picker).on('click', function(e) { 105 var $self = $(this), 106 action = $self.data('prlib-action'), 107 viewDate = picker.viewDate(), 108 d, year, month, requestDate; 109 110 // Ðод. 111 if (action == 'year') { 112 picker.viewMode('months'); 113 $picker.selectMonths(); 114 115 d = viewDate.startOf('year'); 116 requestDate = d.year(); 117 } 118 119 // ÐеÑÑÑ. 120 if (action == 'month') { 121 picker.viewMode('days'); 122 $picker.selectDays(); 123 124 d = viewDate.startOf('month'); 125 requestDate = (d.month() + 1) + '-' + d.year(); 126 } 127 128 // СегоднÑ. 129 if (action == 'today') { 130 picker.viewMode('days'); 131 132 d = moment().locale(locale); 133 requestDate = d.date() + '-' + (d.month() + 1) + '-' + d.year(); 134 135 picker.viewDate(d); 136 picker.date(d); 137 } 138 139 ajaxData.view_path = urlPath + '?date=' + requestDate; 140 pushStateHistory(requestDate, document.title, ajaxData.view_path); 141 if (viewAjax) { 142 viewRequest($self, requestDate); 143 } 144 else { 145 $(window).attr('location', createUrl(requestDate)); 146 } 147 }); 148 149 150 // 151 // Ðо ÐºÐ»Ð¸ÐºÑ Ð½Ð° меÑÑÑ. 152 // -------------------------------------------------- 153 154 $('.datepicker-months td', $picker).on('click', function (e) {
155 var month = $(e.target).closest('tbody').find('span').index($(e.target)) + 1, 156 year = picker.viewDate().year(), 157 requestDate = month + '-' + year; 158 159 picker.prlib_action = 'months'; 160 161 ajaxData.view_path = urlPath + '?date=' + requestDate; 162 pushStateHistory(requestDate, document.title, ajaxData.view_path); 163 viewRequest($picker, requestDate); 164 }); 165 166 167 // 168 // ÐÑи изменении ÑекÑÑей даÑÑ viewDate. 169 // -------------------------------------------------- 170 171 $picker.on('dp.update', function (e) { 172 // ÐÑли изменилÑÑ Ð¼ÐµÑÑÑ. 173 if (e.change == 'M' && typeof picker.prlib_action !== 'undefined') { 174 $picker.selectDays(); 175 delete $(this).data('DateTimePicker').prlib_action; 176 } 177 }); 178 179 180 // 181 // ÐÑи изменении ÑекÑÑей даÑÑ. 182 // -------------------------------------------------- 183 184 $picker.once().on('dp.change', function(e) { 185 if (typeof picker.prlib_action === 'undefined') { 186 var requestDate = e.date.date() + '-' + (e.date.month() + 1) + '-' + e.date.year(); 187 ajaxData.view_path = urlPath + '?date=' + requestDate; 188 pushStateHistory(requestDate, document.title, ajaxData.view_path); 189 viewRequest(e.target, requestDate); 190 } 191 }); 192 193 // Ðобавление нового ÑоÑÑоÑÐ½Ð¸Ñ Ð² иÑÑоÑÐ¸Ñ Ð±ÑаÑзеÑа. 194 function pushStateHistory(data, title, url) { 195 url = '/' + url; 196 window.history.pushState(data, title, url); 197 } 198 199 function createUrl(search) { 200 if (search.length) { 201 search = '?date=' + search; 202 } 203 var loc = $(location).attr('origin') + $(location).attr('pathname'); 204 return loc + search; 205 } 206 207 function viewRequest(el, search) { 208 // todo: УÑоÑниÑÑ ÑелекÑоÑ. 209 $('#content .view').addClass('lock'); 210 211 ajaxData.view_args = 'date=' + search; 212 213 var lang = Drupal.settings.prlib_calendar.language; 214 var langDafault = Drupal.settings.prlib_calendar.defaultLanguage; 215 var urlDef = '/views/ajax?date=' + search; 216 217 var url = langDafault !== lang ? '/' + lang + urlDef : urlDef; 218 219 var settings = { 220 url : url, 221 submit: ajaxData, 222 selector: '#content .view', 223 success: function(response, status) { 224 Drupal.ajax.prototype.success.apply(this, arguments); 225 226 // Ðбновление ÑÑÑлок пеÑеклÑÑÐµÐ½Ð¸Ñ ÑзÑка. 227 $('.language-switcher-locale-url a').each(function() { 228 var uri = new URI($(this).attr('href')); 229 uri.removeSearch('date').addSearch('date', search); 230 $(this).attr('href', uri); 231 }); 232 } 233 }; 234 var ajax = new Drupal.ajax(false, false, settings); 235 ajax.eventResponse(ajax, {}); 236 } 237 }); 238 239 } 240 }; 241})(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.