/upstream/templates/lib/covers.tmpl
Type: /type/template
body: value: $def with (page, all_borrow=False)

<script type="text/javascript">
<!--
page.displayCovers = function(pagenum) {
    page.loadPage(pagenum, function(data) {
        \$("#coversCarousel").empty().html(page.renderCovers(data));
    });
};

function loadCoverCarousels(carousel, state) {
    if (!page.coverCarousel) {
        page.coverCarousel = carousel;
        page.coverCarousel.size(page.getPageCount());
    }
    var index = carousel.first;
    page.pos = (index-1)*12;

    if (window.set_hash) {
         var _p = (index == 1) ? null : index;
        set_hash({"page": _p});
    }

    if (carousel.has(index)) {
        return;
    }
    carousel.add(index, "<h3>Loading books...</h3>");
    page.loadPage(index-1, function(data) {
        carousel.add(index, page.renderCovers(data));
    });
}

\$().ready(function() {
    page.renderCovers = render_page;
    page.displayCovers(0);
});

\$().ready(carousels);
\$().ready(function() {
    carouselSetup(loadCoverCarousels);
    \$('.jcarousel-next').attr('title','View the next editions').append('<h4 class="shift"><a href="#" onclick="return false;">View the next editions</a></h4>');
    \$('.jcarousel-prev').attr('title','View the previous editions').append('<h4 class="shift"><a href="#" onclick="return false;">View the previous editions</a></h4>');
});
//-->
</script>

$code:
    def get_authors(work):
		return ", ".join(a.name for a in work.authors)
		
<script type="text/javascript">
<!--
function get_authors(work) {
	var authors = [];
	for (var i=0; i < work.authors.length; i++) {
		authors.push(work.authors[i].name);
	}
	return authors.join(", ");
}
//-->
</script>

$ inlibrary = "inlibrary" in ctx.features and bool(get_library())
<script> var inlibrary = $:json_encode(inlibrary); </script>

<script> var all_borrow = $:json_encode(all_borrow); </script>

$code:
    def contains(array, value):
	    return value in array
	    
<script type="text/javascript">
    function contains(array, value) {
        return \$.inArray(value, array) >= 0;	
    }
</script>

$jsdef render_page(page):
    $for w in page.works:
        <div class="coverMagic">
            $if w.cover_id:
                <div class="SRPCover">
                    <a href="$w.key" title="$truncate(w.title, 40) by $truncate(get_authors(w), 40), $w.edition_count editions"><img src="http://covers.openlibrary.org/b/id/$w.cover_id-M.jpg" alt="$w.title" class="cover"/></a>                
                </div>
            $else:
                <a href="$w.key" title="$truncate(w.title, 40) by $truncate(get_authors(w), 40), $w.edition_count editions">
                    <div class="SRPCoverBlank" style="display:block;">
                        <div class="innerBorder">
                            <div class="BookTitle">$truncate(w.title, 40)
                                <div class="Author">$truncate(get_authors(w), 40)</div>
                            </div>
                        </div>
                    </div>
                </a>
                
            $ borrowable = all_borrow or contains(w.subject, 'Lending library') or (inlibrary and contains(w.subject, 'In library'))
            $if w.ia and w.lending_edition and borrowable:
                <div class="coverEbook"><a href="/books/$w.lending_edition/x/borrow" title="$_('Borrow this book')"><img src="/images/icons/icon_borrow-avail.png" border="0" width="32" height="33" alt="$_('Borrow this book')"/></a></div>
            $if not all_borrow and w.ia and w.public_scan:
                <div class="coverEbook"><a href="http://www.archive.org/stream/$w.ia" title="$_('Read online')"><img src="/images/icons/icon_ebook-avail.png" border="0" width="32" height="33" alt="$_('Read online')"/></a></div>
                <!-- Protected DAISY flag is not set at the Work level (yet)
                if w.is_daisy_encrypted():
                    <div class="coverEbook"><a href="key('/daisy')" title="$_('Download a protected DAISY')"><img src="/images/icons/icon_pdaisy-avail.png" border="0" width="32" height="33" alt="$_('Download a protected DAISY')"/></a></div>
                -->
                <!-- OverDrive availability is not set at the Work level (yet)
                 overdrive = "http://search.overdrive.com/SearchResults.aspx?ReserveID={XXX}"
                 overdrive_id = None
                if w.get('identifiers', None) and w.identifiers.get('overdrive', None):
                     overdrive_id = w.identifiers.overdrive[0]
                if overdrive_id:
                    <div class="coverEbook"><a href="overdrive.replace('XXX', overdrive_id)" title="_('Borrow this book')"><img src="/images/icons/icon_borrow-avail.png" border="0" width="32" height="33" alt="_('Borrow this book')"/></a></div>
                -->
            $if not all_borrow and not w.public_scan and w.printdisabled and not w.overdrive and not borrowable:
                <div class="coverEbook"><a href="$w.key" title="$_('Download a protected DAISY')"><img src="/images/icons/icon_pdaisy-avail.png" border="0" width="32" height="33" alt="$_('Download a protected DAISY')"/></a></div>
            $if not all_borrow and w.overdrive and not w.public_scan and not borrowable:
                <div class="coverEbook"><a href="http://search.overdrive.com/SearchResults.aspx?ReserveID={$(w.overdrive)}" title="$_('Borrow this book')"><img src="/images/icons/icon_borrow-avail.png" border="0" width="32" height="33" alt="$_('Borrow this book')"/></a></div>
        </div>

<div id="contentLists" class="results">
    <div class="covers" id="resultsCovers">
        <ul id="coversCarousel" class="jcarousel-skin-OL">
            <li>$:render_page(page)</li>
        </ul>
        <div id="coversLoading" class="hidden"><h3>Loading books...</h3></div>
        <div id="coversNone" class="hidden"><h2>$:_('Open Library is unaware of any <span class="bookType">editions</span> about <span class="bookSubject">this subject</span> <span class="clickdata"></span> <a href="javascript:;" class="resetSelection">Zoom out again</a>?')</h2></div>
    </div>
</div>

<div class="clearfix"></div>
plugin: upstream
title: Bookcovers Carousel/List View
m: edit