1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | |
---|
18 | function expandFacet(p) { |
---|
19 | p.find(".facetvalues").show(200); |
---|
20 | p.addClass("expandedfacet"); |
---|
21 | p.removeClass("collapsedfacet"); |
---|
22 | p.find(".filterform input").focus(); |
---|
23 | } |
---|
24 | |
---|
25 | function collapseFacet(p) { |
---|
26 | p.find(".facetvalues").hide(200); |
---|
27 | p.addClass("collapsedfacet"); |
---|
28 | p.removeClass("expandedfacet"); |
---|
29 | } |
---|
30 | |
---|
31 | $(document).ready(function() { |
---|
32 | /* facet collapse/expand */ |
---|
33 | $("a.expandfacet, a#showvalues").click(function(event) { |
---|
34 | event.preventDefault(); |
---|
35 | var p = $(this).parents(".collapsedfacet"); |
---|
36 | expandFacet(p); |
---|
37 | }); |
---|
38 | $("a.collapsefacet").click(function(event) { |
---|
39 | event.preventDefault(); |
---|
40 | var p = $(this).parents(".expandedfacet"); |
---|
41 | collapseFacet(p); |
---|
42 | }); |
---|
43 | |
---|
44 | $(".facet h1 a").click(function(event) { |
---|
45 | event.preventDefault(); |
---|
46 | if ($(this).parents(".expandedfacet").length === 1) { |
---|
47 | var p = $(this).parents(".expandedfacet"); |
---|
48 | collapseFacet(p); |
---|
49 | } else { |
---|
50 | var p = $(this).parents(".collapsedfacet"); |
---|
51 | expandFacet(p); |
---|
52 | } |
---|
53 | }); |
---|
54 | |
---|
55 | /* facet filter */ |
---|
56 | // $(".filterform").hide(); |
---|
57 | // |
---|
58 | // $("a.filtertoggle").click(function(event) { |
---|
59 | // // toggle link clicked, show or hide filter box and focus on input |
---|
60 | // event.preventDefault(); |
---|
61 | // var form = $(this).parent(".facet").find(".filterform"); |
---|
62 | // form.siblings(".facetvalues").find("li").show(); |
---|
63 | // expandFacet($(this).parent(".collapsedfacet")); |
---|
64 | // form.toggle(100, function(event) { |
---|
65 | // var input = form.children("input"); |
---|
66 | // input.val(''); |
---|
67 | // input.focus(); |
---|
68 | // }); |
---|
69 | // }); |
---|
70 | |
---|
71 | var filterHandler = function(event) { |
---|
72 | // filter text entered, update result list |
---|
73 | var links = $(this).parents(".filterform").siblings(".facetvalues").find("li"); |
---|
74 | var match = $(this).val().toUpperCase(); |
---|
75 | if (match.length === 0) { |
---|
76 | links.show(); |
---|
77 | } else { |
---|
78 | // hide all results |
---|
79 | links.hide(); |
---|
80 | // show all matching results |
---|
81 | links.filter(function(index) { |
---|
82 | // case insensitive match |
---|
83 | return links[index].textContent.toUpperCase().indexOf(match) >= 0; |
---|
84 | }).show(); |
---|
85 | } |
---|
86 | }; |
---|
87 | |
---|
88 | $(".filterform input").on('input', filterHandler); |
---|
89 | |
---|
90 | /* Facet values popup */ |
---|
91 | |
---|
92 | $(".more-link").click(function(event) { |
---|
93 | event.preventDefault(); |
---|
94 | $("#facetvalues").toggle(); |
---|
95 | var name = $(this).parents(".facet").find("h1").text(); |
---|
96 | $("#facetvalues h2").text(name); |
---|
97 | $(window).scrollTop($('#facetvalues').position().top); |
---|
98 | }); |
---|
99 | |
---|
100 | $("#facetvalues a").click(function(event) { |
---|
101 | event.preventDefault(); |
---|
102 | $("#facetvalues").toggle(); |
---|
103 | }); |
---|
104 | }); |
---|