This repository has been archived on 2020-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
codesite/static_global/site.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-05-10 02:19:25 +00:00
(function() {
"use strict";
var show_all = function() {
var tr = document.querySelectorAll(".projtable tr");
for (var i = 0, e = tr.length; i !== e; ++i) {
tr[i].style.display = "table-row";
}
2014-05-10 03:11:27 +00:00
var warn = document.querySelector(".tag-filter-warn");
warn.parentNode.removeChild(warn);
2014-05-10 02:19:25 +00:00
};
var show_tag = function(tag) {
if (document.querySelector(".tag-filter-warn") !== null) {
show_all();
}
2014-05-10 02:19:25 +00:00
var tr = document.querySelectorAll(".projtable tr");
for (var i = 0, e = tr.length; i !== e; ++i) {
tr[i].style.display = (tr[i].className.split(" ").indexOf("taggedWith-"+tag) === -1) ? "none" : "table-row";
}
var div = document.createElement("div");
div.className = "tag-filter-warn";
div.innerHTML = "Filtering by tag. <a>reset</a>";
document.body.appendChild(div);
document.querySelector(".tag-filter-warn a").addEventListener('click', function() {
show_all();
return false;
});
};
var get_show_tag = function(tag) {
2015-04-05 04:22:46 +00:00
return function() {
show_tag(tag);
return false;
};
2014-05-10 02:19:25 +00:00
};
2015-04-05 04:22:46 +00:00
var sort_rows = function(cb) {
var tr = document.querySelectorAll(".projtable tr");
var items = [];
for (var i = 0, e = tr.length; i !== e; ++i) {
items.push([i, cb(tr[i])]);
}
items.sort(function(a, b) {
return (a[1] - b[1]);
});
for (var i = 0, e = items.length; i !== e; ++i) {
var el = tr[items[i][0]];
var parent = el.parentElement;
parent.removeChild(el);
parent.appendChild(el);
}
};
var sort_update = function() {
var cb;
switch(document.getElementById('sortorder').value) {
case 'a':
default: {
cb = function(el) {
return el.getAttribute('data-sort-ct');
};
} break;
case 'b': {
cb = function(el) {
return el.getAttribute('data-sort-mt');
}
} break;
case 'c': {
cb = function(el) {
return el.getAttribute('data-sort-al');
}
} break;
};
sort_rows(cb);
};
2014-05-10 02:19:25 +00:00
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));
}
2015-04-05 04:22:46 +00:00
var so = document.getElementById('sortorder');
if (so) {
so.addEventListener('change', sort_update);
sort_update();
}
2014-05-10 02:19:25 +00:00
});
2015-04-05 04:22:46 +00:00
})();