From 39789220a8b7879bfc98024daf1b469e9e302f5d Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 18 Apr 2016 19:42:55 +1200 Subject: [PATCH] remove theme-specific code from the globally-applied site.js file --- static/site.js | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/static/site.js b/static/site.js index 5cfa896..783a4ae 100644 --- a/static/site.js +++ b/static/site.js @@ -1,6 +1,10 @@ (function() { "use strict"; + // + // Tag support + // + var show_all = function() { var tr = document.querySelectorAll(".projtable tr"); for (var i = 0, e = tr.length; i !== e; ++i) { @@ -39,6 +43,18 @@ }; }; + window.addEventListener('load', function() { + var taglinks = document.querySelectorAll(".tag-link"); + for (var i = 0, e = taglinks.length; i !== e; ++i) { + var tag = taglinks[i].getAttribute("data-tag"); + taglinks[i].addEventListener('click', get_show_tag(tag)); + } + }); + + // + // Sort support (theme opt-in) + // + var sort_rows = function(cb) { var tr = document.querySelectorAll(".projtable tr"); var items = []; @@ -56,42 +72,29 @@ } }; - var sort_update = function() { - var cb; - switch(document.getElementById('sortorder').value) { + var sort_update = function(sort_by) { + switch(sort_by) { case 'a': default: { - cb = function(el) { + sort_rows(function(el) { return el.getAttribute('data-sort-ct'); - }; + }); } break; case 'b': { - cb = function(el) { + sort_rows(function(el) { return el.getAttribute('data-sort-mt'); - } + }); } break; case 'c': { - cb = function(el) { + sort_rows(function(el) { return el.getAttribute('data-sort-al'); - } + }); } break; }; - sort_rows(cb); }; - window.addEventListener('load', function() { - var taglinks = document.querySelectorAll(".tag-link"); - for (var i = 0, e = taglinks.length; i !== e; ++i) { - var tag = taglinks[i].getAttribute("data-tag"); - taglinks[i].addEventListener('click', get_show_tag(tag)); - } - - var so = document.getElementById('sortorder'); - if (so) { - so.addEventListener('change', sort_update); - sort_update(); - } - }); + window.sortUpdate = sort_update; + })();