var filterDates = []; var catsPredefined = ''; var newsLoadMoreSkip = 0; jQuery(function($) { $(".weekler tr.switches td").unbind('click'); $(".weekler tr.switches td").click(function(){ if ($(this).children('.day.other').length) { if ($(".weekler tr.switches td:first .day").hasClass('other')) { eventsFilterDate.monthPrev(); } else { eventsFilterDate.monthNext(); } } else { var index = $(".page-events-filter-week .weekler tr.switches td").index($(this)); var dateNow = new Date(); var day = eventsFilterDateCurrent.getDate() + index - eventsFilterDate.weekSkip; if ( eventsFilterDate.year > dateNow.getFullYear() || eventsFilterDate.year == dateNow.getFullYear() && eventsFilterDate.month - 1 > dateNow.getMonth() || eventsFilterDate.year == dateNow.getFullYear() && eventsFilterDate.month - 1 == dateNow.getMonth() && day > dateNow.getDate() ) { return false; } if ($("#filter-dates div").length == 0) { $("#filter-dates").html(''); } var date = eventsFilterDate.year + '.' + pad(eventsFilterDate.month, 2) + '.' + day; var date_reverse = day + '.' + pad(eventsFilterDate.month, 2) + '.' + eventsFilterDate.year; if (filterDates.indexOf(date) == -1) { $("#filter-dates").append('
' + date_reverse + '
'); $("#filter-dates").find("div:last").slideDown('fast'); filterDates.push(date); eventsFilterDate.highlight(filterDates); filterProcess(); } else { index = filterDates.indexOf(date); filterDates.splice(index, 1); eventsFilterDate.highlight(filterDates); $("#filter-dates div:eq("+index+")").slideUp('fast', function(){ $(this).remove(); if ($("#filter-dates div").length == 0) { $("#filter-dates").html('Выберите дату'); } }); filterProcess(); } } return false; }); $("li.switch a").click(function(){ $(this).parent('li').parent('ul').find('li.switch').removeClass('active'); $(this).parent('li').addClass('active'); return false; }); $(".checklist .check").click(function(){ $(this).parent('li').toggleClass('active'); filterProcess(); return false; }); $("#filter-dates .remove").live('click', function(){ var index = $("#filter-dates div").index($(this).parent('div')); filterDates.splice(index, 1); $(this).parent('div').slideUp('fast', function(){ $(this).remove(); if ($("#filter-dates div").length == 0) { $("#filter-dates").html('Выберите дату'); } }); eventsFilterDate.highlight(filterDates); filterProcess(); return false; }); $("#eventsFilterDatePrev, #eventsFilterDateNext, .chooser-month li a, .chooser-year li a").click(function(){ eventsFilterDate.highlight(filterDates); }); $("#news-filter-source li").click(function() { var _this = $(this); var id = _this.children('span').text(); _this.toggleClass('active'); if (!_this.hasClass('c')) { if (_this.hasClass('active')) { $("#news-filter-source .c-"+id).addClass('active'); } else { $("#news-filter-source .c-"+id).removeClass('active'); } } filterProcess(); return false; }); eventsFilterDate.init(false); eventsFilterDate.highlight(filterDates); filterProcess(); }); function filterProcess() { if (catsPredefined != '') { var cats = catsPredefined.split(','); catsPredefined = ''; } else { var cats = []; $(".checklist.event-type.col1 li a.check").each(function(){ if ($(this).parent('li').hasClass('active')) { cats.push($(this).attr('rel')); } }); } var locations = []; $(".checklist.event-type.col2 li a.check").each(function(){ if ($(this).parent('li').hasClass('active')) { locations.push($(this).attr('rel')); } }); var sources = []; $("#news-filter-source li").each(function(){ if ($(this).hasClass('active')) { sources.push($(this).children('span').text()); } }); $("#filter-count").html('...'); $.getJSON("/ajax/news.filter.count", { 'cats': cats.join(','), 'catsReal': $("#catsReal").val(), 'pid': '2', 'locations': locations.join(','), 'dates': filterDates.join(','), 'sources': sources.join(','), 'useful': $("#filter-check-useful").hasClass('active') ? '1' : '0', 'views': $("#filter-check-views").hasClass('active') ? '1' : '0', 'org': $("#org").val(), 'period': $("#period").val() }, function(e){ sidebarMapUpdate('news', 2, e.ids); $("#filter-count").html(e.count); }); return false; } function filterSubmit(ret) { var cats = []; $(".checklist.event-type.col1 li a.check").each(function(){ if ($(this).parent('li').hasClass('active')) { cats.push($(this).attr('rel')); } }); var locations = []; $(".checklist.event-type.col2 li a.check").each(function(){ if ($(this).parent('li').hasClass('active')) { locations.push($(this).attr('rel')); } }); var sources = []; $("#news-filter-source li").each(function(){ if ($(this).hasClass('active')) { sources.push($(this).children('span').text()); } }); var url = 'act=search' + '&archive=' + $("#archive").val() + '&cats=' + cats + '&catsReal=' + $("#catsReal").val() + '&pid=2' + '&locations=' + locations + '&sources=' + sources + '&dates=' + filterDates + '&useful=' + ($("#filter-check-useful").hasClass('active') ? '1' : '0') + '&views=' + ($("#filter-check-views").hasClass('active') ? '1' : '0') + '&org=' + $("#org").val() + '&period=' + $("#period").val() ; if (typeof(ret) != 'undefined' && ret == true) { return url; } else { window.location = ($("#searchURL").length ? $("#searchURL").val() : '') + '?' + url; } } function newsLoadMoreByCat(sender, skip, total, cat) { var _sender_text = sender.text(); sender.html('Загрузка...'); $.get("/ajax/news.getMultiNews", { 'cat': cat, 'skip': skip + newsLoadMoreSkip }, function(e) { newsLoadMoreSkip += 10; var _onpage = parseInt($("#onpage").val()) + newsLoadMoreSkip; sender.parent('div').prev('.news').append(e); sender.html(_sender_text); $(".paginator").html('Загрузка...'); $.get("/ajax/news.render.paginator", { 'total': total, 'page': Math.ceil(skip / _onpage), 'onpage': _onpage }, function(e) { $(".paginator").html(e); }); }); return false; } function newsLoadMoreByParams(sender, skip, total) { var _sender_text = sender.text(); sender.html('Загрузка...'); var _url = filterSubmit(true); $.get("/ajax/news.getFilterNews/?" + _url, { 'skip': skip + newsLoadMoreSkip }, function(e) { newsLoadMoreSkip += 10; var _onpage = parseInt($("#onpage").val()) + newsLoadMoreSkip; sender.parent('div').prev('.news').append(e); sender.html(_sender_text); $(".paginator").html('Загрузка...'); $.get("/ajax/news.render.paginator/?" + _url, { 'total': total, 'page': Math.ceil(skip / _onpage), 'onpage': _onpage }, function(e) { $(".paginator").html(e); }); }); return false; }