Explorar el Código

Add functions for filtering by title and post type

Lucas Stadler %!s(int64=9) %!d(string=hace) años
padre
commit
1e24d655b6
Se han modificado 1 ficheros con 30 adiciones y 0 borrados
  1. 30 0
      go/blog/blog.go

+ 30 - 0
go/blog/blog.go

@ -322,6 +322,22 @@ func main() {
322 322
		document.title = baseTitle + " (Posts tagged '" + tag + "')";
323 323
	}
324 324
325
	function filterTitle(match) {
326
		var match = match.toLowerCase();
327
		var articles = document.querySelectorAll("article");
328
		for (var i = 0; i < articles.length; i++) {
329
			var article = articles[i];
330
			var title = article.querySelector("header h1");
331
			if (title && title.textContent.toLowerCase().match(match)) {
332
				article.classList.remove("does-not-match");
333
			} else {
334
				article.classList.add("does-not-match");
335
			}
336
		}
337
338
		document.title = baseTitle + " (Posts matching '" + match + "')";
339
	}
340
325 341
	function filterId(id) {
326 342
		var articles = document.querySelectorAll("article");
327 343
		for (var i = 0; i < articles.length; i++) {
@ -336,6 +352,20 @@ func main() {
336 352
		document.title = baseTitle + " (Only post id '" + id + "')";
337 353
	}
338 354
355
	function filterType(type) {
356
		var articles = document.querySelectorAll("article");
357
		for (var i = 0; i < articles.length; i++) {
358
			var article = articles[i];
359
			if (article.classList.contains(type)) {
360
				article.classList.remove("does-not-match");
361
			} else {
362
				article.classList.add("does-not-match");
363
			}
364
		}
365
366
		document.title = baseTitle + " (Only " + type + " posts)";
367
	}
368
339 369
	function clearFilter() {
340 370
		var articles = document.querySelectorAll("article.does-not-match");
341 371
		for (var i = 0; i < articles.length; i++) {