function events_calendar() { $("#calendar .month").attr("tabindex", "-1").removeClass("found").removeClass("on").attr('aria-disabled', true); if ($("#directory .event.on").length) { $("#calendar .month").each(function () { var match = $(this); var month = $(this).data("month"); $("#directory .event.on").each(function () { if ($(this).data("date") && $(this).data("date").trim().substring(5, 7) == month) { $(match).attr("tabindex", "0").addClass("found").attr('aria-disabled', false); return false; } }); }); } } function events_count() { $("#options [role='checkbox']").attr("aria-checked", false); $("#options [role='checkbox'].on").attr("aria-checked", true); var match = $("#directory .event.on:not(.hidden)").length; if (match === 0) { $("#info .count-plural").show(); } else if (match === 1) { $("#info .count-plural").hide(); } else { $("#info .count-plural").show(); } $("#info .count-found").html(match); $("#info .count-possible").html($("#directory .event").length); } function events_filter() { if ($("#options .button.on").length) { $("#info .button.clear").show(); $("#info .button.filter").addClass("on"); $("#directory .event").removeClass("on").removeClass("hidden").each(function () { var flow = []; var tags = $(this).find(".meta-tags p").text().replace(/, /g, ",").split(","); $("#options .buttons").each(function () { var mode = -1; $(this).find(".button.on").each(function () { mode = 0; if ($.inArray($(this).text(), tags) !== -1) { mode = 1; return false; } }); flow.push(mode); }); if ($.inArray(0, flow) === -1) { $(this).addClass("on"); } }); $("#applied span").text($("#options .button.on").map(function () { return $(this).text(); }).get().join(", ")); } else { $("#info .button.clear").hide(); $("#info .button.filter").removeClass("on"); $("#directory .event").addClass("on").removeClass("hidden"); $("#applied span").text("None"); } events_calendar(); events_count(); } function events_hash() { var hash = "#"; $("#options .button.on").each(function (index) { if (index) { hash += "+"; } hash += $(this).text().replace(/ /g, "_"); }); if (history.pushState) { if (hash === "#") { hash = "."; } history.pushState(null, null, hash); } else { window.location.hash = hash; } events_filter(); } function events_load() { if (window.location.hash) { var hash = window.location.hash.replace("#", "").replace(/_/g, " ").split("+"); for (var button in hash) { $("#options .button").filter(function () { return $(this).text() === hash[button]; }) .addClass("on"); } } events_filter(); events_sort(); } function events_month() { if ($("#calendar .month.on").length) { var month = $("#calendar .month.on").data("month"); $("#directory .event.on").removeClass("hidden").each(function () { if (!$(this).data("date") || $(this).data("date").trim().substring(5, 7) != month) { $(this).addClass("hidden"); } }); } else { $("#directory .event.on").removeClass("hidden"); } events_count(); setTimeout(function () { $("#info .message").focus(); }, 300); } function events_sort() { function date(sort, direction) { $(sort).sort(function (a, b) { if (direction === "asc") { return $(a).data("date") > $(b).data("date") ? 1 : -1; } else { return $(a).data("date") < $(b).data("date") ? 1 : -1; } }) .appendTo($("#directory")); } function name(sort, direction) { $(sort).sort(function (a, b) { if (direction === "asc") { return $(a).find("h3").text() > $(b).find("h3").text() ? 1 : -1; } else { return $(a).find("h3").text() < $(b).find("h3").text() ? 1 : -1; } }) .appendTo($("#directory")); } var direction = $("#options .dropdown .option.on").data("direction"); if ($("#options .dropdown .option.on").data("sort") === "date") { date($("#directory .event.pin[data-date]"), direction); name($("#directory .event.pin:not([data-date])"), direction); date($("#directory .event:not(.pin)[data-date]"), direction); name($("#directory .event:not(.pin):not([data-date])"), direction); } else { name($("#directory .event.pin"), direction); name($("#directory .event:not(.pin)"), direction); } } $(document).ready(function () { $(this).on("click", "#calendar .month.found", function () { $(this).toggleClass("on").siblings().removeClass("on"); events_month(); }); $(this).on("click", "#directory .event a[aria-disabled]", function () { return false; }); $(this).on("click", "#directory .event", function () { window.open($(this).find("a").attr("href"), "_blank"); }); $(this).on("click", "#info .button.clear", function () { if (history.pushState) { history.pushState(null, null, "."); } else { window.location.hash = events_hash; } $("#options .button").removeClass("on"); events_filter(); setTimeout(function () { $("#mainContent").focus(); }, 300); }); $(this).on("click", "#info .button.filter", function () { $("#options").stop().slideToggle(300); }); $(this).on("click", "#options .button", function () { $(this).toggleClass("on"); events_hash(); setTimeout(function () { $("#info .message").focus(); }, 300); }); $(this).on("click", "#options .dropdown .name", function () { $(this).parent().toggleClass("on").find(".options").stop().slideToggle(300); }); $(this).on("click", "#options .dropdown .option:not(.on)", function () { $(this).addClass("on").siblings().removeClass("on"); $(this).parent().siblings(".name").click().text($(this).text()); events_sort(); setTimeout(function () { $("#dateFilter").focus(); }, 300); }); $(this).on("keypress", "[tabindex]", function (event) { if (event.which === 13 || event.which === 32) { $(this).click(); } }); events_load(); });