<div dir="ltr"><div><div><div>Hello all!<br><br>A while back (a few years, I think!) I wrote and posted to this mailing list a set of php scripts that provided a new books display. When we recently upgraded our koha instance (shifting to Plack in the process!), I decided to rewrite this new books display in perl.<br>

<br></div><div>And I thought I'd put it up here in case anyone was interested in it.<br><br></div>Perl's not my language of choice - so if there are any improvements to be made, please let me know.<br><br></div>To use it, simply install the <a href="http://newbooksdisplay.pl">newbooksdisplay.pl</a> in the opac cgi-bin directory, and add the following snippet to the OpacMain systempreferences:<br>

<br><h2 style="align="center">Newest books in the library</h2><br><div id="newbooks"></div><br><script type="text/javascript"><br>$("#newbooks").load("/cgi-bin/koha/<a href="http://newbooksdisplay.pl">newbooksdisplay.pl</a>", function() {<br>

<br>KOHA.Google.GetCoverFromIsbn();<br><br>});<br><br></script><br><br><br></div>I've also modified the google-jackets.js to produce a nice artificial cover if none is available from google books (currently only if the correct HTML5 data tags are supplied, as in the newbooksdisplay)<br>

<br><br><pre style>if (typeof KOHA == "undefined" || !KOHA) {<br>    var KOHA = {};<br>}<br><br>/**<br> * A namespace for Google related functions.<br> */<br>KOHA.Google = {<br><br><br>    /**<br>     * Search all:<br>

     *    <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div><br>     * or<br>     *    <div title="biblionumber" id="isbn" class="gbs-thumbnail-preview"></div><br>

     * and run a search with all collected isbns to Google Book Search.<br>     * The result is asynchronously returned by Google and catched by<br>     * gbsCallBack().<br>     */<br>    GetCoverFromIsbn: function(newWindow) {<br>

        var bibkeys = [];<br>        $("div [id^=gbs-thumbnail]").each(function(i) {<br>            bibkeys.push($(this).attr("class").split(' ')[0]); // id=isbn<br>        });<br>        bibkeys = bibkeys.join(',');<br>

        var scriptElement = document.createElement("script");<br>        this.openInNewWindow=newWindow;<br>        scriptElement.setAttribute("id", "jsonScript");<br>        scriptElement.setAttribute("src",<br>

            "<a href="http://books.google.com/books?bibkeys=">http://books.google.com/books?bibkeys=</a>" + escape(bibkeys) +<br>            "&jscmd=viewapi&callback=KOHA.Google.gbsCallBack");<br>

        scriptElement.setAttribute("type", "text/javascript");<br>        document.documentElement.firstChild.appendChild(scriptElement);<br><br>    },<br><br>    /**<br>     * Add cover pages <div<br>

     * and link to preview if div id is gbs-thumbnail-preview<br>     */<br>    gbsCallBack: function(booksInfo) {<br>         var target = '';<br>         if (this.openInNewWindow) {<br>            target = 'target="_blank" ';<br>

         }<br>         for (id in booksInfo) {<br>             var book = booksInfo[id];<br>             $("."+book.bib_key).each(function() {<br>            var gbsre = /^gbs-thumbnail/;<br>         if ( gbsre.exec($(this).attr("id")) ) {<br>

                         var a = document.createElement("a");<br>                        a.href = book.info_url;<br>                       if (typeof(book.thumbnail_url) != "undefined") {<br>                        var img = document.createElement("img");<br>

                             img.setAttribute("class","thumbnail");<br>                            img.src = book.thumbnail_url+"&zoom=1";<br>                         $(this).append(img);<br>                          var re = /^gbs-thumbnail-preview/;<br>

                             if ( re.exec($(this).attr("id")) ) {<br>                            $(this).append(<br>                                   '<div style="margin-bottom:5px; margin-top:-5px;font-size:9px">' +<br>

                                     '<a '+target+'href="' +<br>                               book.info_url +<br>                               '"><img src="' +<br>                              '<a href="http://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif">http://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif</a>' +<br>

                                     '"></a></div>'<br>                                    );<br>                            }<br>                         } else if ($(this).attr('data-title')) {<br>                                     var fakeCoverDiv = document.createElement("div");<br>

                                        $(fakeCoverDiv).attr("class", "fakeCover");<br>                                       $(this).append(fakeCoverDiv);<br>                                 var auSpan = document.createElement("span");<br>                                        $(auSpan).attr("class", "author");<br>

                                        $(auSpan).html($(this).attr("data-author"));<br>                                        $(fakeCoverDiv).append(auSpan);<br>                                        var tiSpan = document.createElement("span");<br>                                        $(tiSpan).attr("class", "title");<br>

                                        $(tiSpan).html($(this).attr("data-title"));<br>                                        $(fakeCoverDiv).append(tiSpan);<br>                         } else {<br>                                  var message = document.createElement("span");<br>

                                     $(message).attr("class","no-image");<br>                              $(message).html(NO_GOOGLE_JACKET);<br>                                    $(this).append(message);<br>                  }<br>            }<br>

             });<br>         }<br>     }<br>};<br></pre><br></div>