/upstream/templates/search/snippets.tmpl
Type: /type/template
body: value: $def with (find_matches, ia)

$ q = query_param('q')

<div id="contentHead">
    <div class="small sansserif grey" style="margin-bottom:5px;">
        <a href="/search/inside">Search Inside</a> / 
        <a href="/search/inside?q=$q">$q</a>
    </div>
    <h1>
        $ia
    </h1>
</div>

<div id="contentBody">

$ result = find_matches(ia, q)
$ scale = 2
$ xpadding = 50
$ ypadding = 50
$ par_num = 0
$ box_num = 0

$for match in result['matches']:
    $ text = match['text']

    $for par in match['par']:
        $ par_num = par_num + 1
        $ page = par['page']
        <p class="lightgreen small sansserif">On leaf number $page:</p>

        $ t = (par['t'] / scale) - ypadding
        $ r = (par['r'] / scale) + xpadding
        $ b = (par['b'] / scale) + ypadding
        $ l = (par['l'] / scale) - xpadding
        $ width = r - l
        $ height = b - t
        $ halfWidth = par['page_width'] * .5
        <div class="clipOut" id="clipout$par_num" style="position:relative;width:$(width)px;height:$(height)px;max-width:918px;overflow:hidden;padding-bottom:10px;">
            <div class="clipIn" id="clipin$par_num" style="position:absolute;clip:rect($(t)px $(r)px $(b)px $(l)px);top:-$(t)px;left:-$(l)px;">
                <a href="http://www.archive.org/stream/$ia#page/n$(page-1)/search/$q">
                $if ia.endswith('goog'):
                    <img src="http://www.archive.org/download/$ia/page/leaf$(page)_s$(scale).jpg" class="clipImg" width="$halfWidth"/></a>
                $else:
                    <img src="http://www.archive.org/download/$ia/page/leaf$(page)_s$(scale).jpg" class="clipImg"/></a>
                $for box in par['boxes']:
                    $if 'r' not in box:
                        $continue
                    $ box_num = box_num + 1
                    <div class="snipHL" id="highlight$box_num" style="width:$((box['r']-box['l'])/scale)px;height:$((box['b']-box['t'])/scale)px;left:$((box['l']/scale))px;top:$((box['t']/scale))px;"></div>
            </div>
        </div>
</div>
title: Snippets in Situ
plugin: upstream