From 7007048833bddc16159fb7a19d3203c414662648 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 11 Oct 2014 23:30:45 -0500 Subject: [PATCH] Add dynamic tag support on main page. --- _layouts/base.html | 6 +----- index.html | 4 ++-- static/main.css | 17 +++++++++++++++-- static/main.js | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/_layouts/base.html b/_layouts/base.html index 84fef4b..a209a55 100644 --- a/_layouts/base.html +++ b/_layouts/base.html @@ -2,11 +2,7 @@ - {% if page.title == "Home" %} - Ben Kurtovic - {% else %} - {{ page.title }} - Ben Kurtovic - {% endif %} + {% if page.title != "Home" %}{{ page.title }} - {% endif %}Ben Kurtovic diff --git a/index.html b/index.html index d8905a2..0f8c284 100644 --- a/index.html +++ b/index.html @@ -121,12 +121,12 @@ title: Home
Tags: {% for tag in site.tags %} - {{tag[0]}} + {{tag[0]}} {% endfor %}
diff --git a/static/main.css b/static/main.css index 96de281..0b206ce 100644 --- a/static/main.css +++ b/static/main.css @@ -129,6 +129,19 @@ a.underlined:hover, a.underlined:active { text-decoration: none; } font-size: 14px; } +.tag { + background-color: #f2f2f2; + border: 1px solid #e8e8e8; + color: #888; + cursor: pointer; + padding: 0 3px; +} + +.tag-selected { + background-color: #ddd; + color: black; +} + #post-info { list-style-type: none; margin: 0; @@ -153,7 +166,7 @@ pre { } code { - background: #f2f2f2; + background-color: #f2f2f2; border: 1px solid #e8e8e8; padding: 0 3px; } @@ -164,7 +177,7 @@ pre code { } .highlight, .highlighttable { - background: #f2f2f2; + background-color: #f2f2f2; border: 1px solid #e8e8e8; font-size: 14px; line-height: 1.35em; diff --git a/static/main.js b/static/main.js index 3e7da0f..b57f899 100644 --- a/static/main.js +++ b/static/main.js @@ -1,4 +1,31 @@ -$(document).ready(function() { +function load_tag_filters() { + $(".tag").click(function() { + $(this).toggleClass("tag-selected"); + + var allowed = []; + $(".tag-selected").each(function() { + allowed.push($(this).text()) + }); + + var num_selected = $(".tag-selected").length; + if (num_selected == 0 || num_selected == $(".tag").length) + $("#post-list li").show(); + else { + $("#post-list li").hide(); + $("#post-list li").each(function() { + var tags = $(this).data("tags").split("|"); + for (var t in tags) { + if ($.inArray(tags[t], allowed) != -1) { + $(this).show(); + return; + } + } + }); + } + }); +} + +function load_paragraph_links() { $("#post").find("h1, h2, h3, h4, h5, h6").hover(function() { $(this).append($("") .attr("href", "#" + this.id) @@ -7,4 +34,9 @@ $(document).ready(function() { }, function() { $(this).find(".para-link").remove(); }); +} + +$(document).ready(function() { + load_tag_filters(); + load_paragraph_links(); });