Просмотр исходного кода

Add functions for filtering by title and post type

Lucas Stadler лет назад: 9
Родитель
Сommit
1e24d655b6
1 измененных файлов с 30 добавлено и 0 удалено
  1. 30 0
      go/blog/blog.go

+ 30 - 0
go/blog/blog.go

322
		document.title = baseTitle + " (Posts tagged '" + tag + "')";
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
	function filterId(id) {
341
	function filterId(id) {
326
		var articles = document.querySelectorAll("article");
342
		var articles = document.querySelectorAll("article");
327
		for (var i = 0; i < articles.length; i++) {
343
		for (var i = 0; i < articles.length; i++) {
336
		document.title = baseTitle + " (Only post id '" + id + "')";
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
	function clearFilter() {
369
	function clearFilter() {
340
		var articles = document.querySelectorAll("article.does-not-match");
370
		var articles = document.querySelectorAll("article.does-not-match");
341
		for (var i = 0; i < articles.length; i++) {
371
		for (var i = 0; i < articles.length; i++) {