diff --git a/js/catalog-search.js b/js/catalog-search.js new file mode 100644 index 00000000..ac7ef57a --- /dev/null +++ b/js/catalog-search.js @@ -0,0 +1,50 @@ +/* + * catalog-search.js + * https://github.com/mgrabovsky/lainchan/blob/catalog-search/js/catalog-search.js + * + * Released under the MIT license + * Copyright (c) 2015 Matěj Grabovský + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/catalog-search.js'; + */ + +(function() { + +var catalogSearch = function() { + var $controls = $('.controls'), + $threads = $('.threads .thread'), + $searchLabel = $(''), + $searchBox = $(''); + + $controls.append($searchLabel) + .append($searchBox); + + $searchBox.keyup(function() { + var $found = searchThreads($threads, this.value); + $threads.hide(); + $found.show(); + }); + + var m = location.hash.match(/[#&]s=([^&]+)/); + if(m) { + $searchBox.val(decodeURIComponent(m[1])).keyup(); + } +}; + +// Filter threads by their content, given a regex. Can be extended to load data +// remotely and filter by multiple fields +var searchThreads = function($threads, query) { + var re = new RegExp(query, 'mi'); + return $threads.filter(function() { + return re.test($('.replies', this).text()); + }); +}; + +// Only load in the catalog +if (active_page == 'catalog') { + onready(catalogSearch); +} + +}()); diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index 45239c5b..12b3cd98 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -18,74 +18,77 @@
{{ settings.subtitle }}
- - - {% trans 'Sort by' %}: - - - {% trans 'Image size' %}: - -
-
+ +
+ +
- {{ post.body }} - - - - {% endfor %} - - -
- + {% endfilter %}