summaryrefslogtreecommitdiff
path: root/templates/search.html
blob: 87ff510af5f63c6fedbd8df881f09921c7f38965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{% extends "_base.html" %}
{% block title %}
    {% if term: %}{{ term }}{% else %}Start a new Search{% endif %}
{% endblock %}
{% block searchValue %}{{ term }}{% endblock %}
{% block javascript %}
    <script>
        jQuery(document).ready(function() {
            // createa accordion for all books
            var acc = jQuery("div.book div.matches").accordion({active:false, autoHeight:false});
            // accordion change handler
            acc.bind('accordionchangestart', function(event, ui) {
              var docnum = ui.newContent.find("p.docnum").text();
              var term = ui.newContent.find("p.term").text();
              /* load excerpt */
              jQuery.get("{{ url_for("do_excerpt", docnum=-9999, term="TERM") }}".replace("-9999", docnum).replace("TERM", term),
                function(data) {
                    ui.newContent.children("div.excerpt").html(data);
                }
              );
              /* update image preview */
              var frontpage = jQuery(this).parent().parent().find("img.frontpage");
              var loader = jQuery(this).parent().parent().find("div.loader");
              frontpage.attr('src', "{{ url_for("do_page_image",docnum=-9999) }}".replace("-9999", docnum));
              frontpage.hide();
              loader.show()
              frontpage.load(function() {
                  loader.hide();
                  frontpage.show();
              });
            });
            acc.bind('accordionchange', function(event, ui) {
                /* align image preview to current match */
                var frontpage = jQuery(this).parent().parent().find("img.frontpage");
                var offset = ui.newHeader[0].offsetTop - frontpage.parent()[0].offsetTop;
                frontpage.parent().animate({paddingTop: offset});
            });
        });
    </script>
{% endblock %}
{% block content %}
    {% if books %}
        Matched {{ books.__len__() }} Book{% if books.__len__() > 1 %}s{% endif %}
        in {{ "%.0f"|format(time_taken*1000) }}ms
        {% for docnum, book in books.items() %}
            <h2 asd="foo">
                {{ book['filename'] }}
                {% if book['title'] %}
                    (<small>
                        {{ book['title'] }}
                    </small>)
                {% endif %}
                <a href="{{ url_for("do_book_file", docnum=docnum) }}" title="Download {{docnum}}"></a>
            </h2>
            <div class="book">
                <div class="c_frontpage">
                    <img class="frontpage" src="{{ url_for("do_book_frontpage", docnum=docnum) }}"/>
                    <div class="loader">
                        <img class="ajaxLoader" src="{{ url_for("static", filename="ajax-loader.gif") }}"/>
                        Loading..
                    </div>
                </div>
                <div class="description">
                    filename, creationtime, indexed-time, +any pdf metadata
                </div>
                <div class="c_matches">
                <div class="matches">
                    {% for match in book['matches'] %}
                        <h3>
                            <a href="#">Match at page {{ match[2] }}</a>
                        </h3>
                        <div class="match">
                            <p class="docnum" style="display:none;">{{ match[0] }}</p>
                            <p class="term" style="display:none;">{{ term}}</p>
                            <div class="toolbar">
                                <a href="{{ url_for("do_page_file", docnum=match[0]) }}">Download page as PDF</a>
                                -
                                <a href="{{ url_for("do_page_image", docnum=match[0], size=1500) }}">Download page as Image</a>
                            </div>
                            <div class="excerpt"></div>
                        </div>
                    {% endfor %}
                </div>
                </div>
                <br style="clear: both;"/>
            </div>
        {% endfor %}
    {% endif %}
{% endblock %}