From 37758541580ea85a68f23382f36a71375adc75a7 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Thu, 16 Dec 2010 22:34:13 -0500 Subject: [PATCH] Bug 5522 - allow google preview to open in a new window If the OPACURLOpenInNewWindow system is set, then google preview links will obey it. Signed-off-by: Nicole Engard Signed-off-by: Chris Cormack --- .../opac-tmpl/prog/en/js/google-jackets.js | 65 ++++++++++--------- .../prog/en/modules/opac-detail.tmpl | 2 +- opac/opac-detail.pl | 8 +++ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/koha-tmpl/opac-tmpl/prog/en/js/google-jackets.js b/koha-tmpl/opac-tmpl/prog/en/js/google-jackets.js index 45a4bb853a..70b1b84337 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/google-jackets.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/google-jackets.js @@ -17,13 +17,14 @@ KOHA.Google = { * The result is asynchronously returned by Google and catched by * gbsCallBack(). */ - GetCoverFromIsbn: function() { + GetCoverFromIsbn: function(newWindow) { var bibkeys = []; $("div [id^=gbs-thumbnail]").each(function(i) { bibkeys.push($(this).attr("class")); // id=isbn }); bibkeys = bibkeys.join(','); var scriptElement = document.createElement("script"); + this.openInNewWindow=newWindow; scriptElement.setAttribute("id", "jsonScript"); scriptElement.setAttribute("src", "http://books.google.com/books?bibkeys=" + escape(bibkeys) + @@ -38,33 +39,37 @@ KOHA.Google = { * and link to preview if div id is gbs-thumbnail-preview */ gbsCallBack: function(booksInfo) { - for (id in booksInfo) { - var book = booksInfo[id]; - $("."+book.bib_key).each(function() { - var a = document.createElement("a"); - a.href = book.info_url; - if (typeof(book.thumbnail_url) != "undefined") { - var img = document.createElement("img"); - img.src = book.thumbnail_url; - $(this).append(img); - var re = /^gbs-thumbnail-preview/; - if ( re.exec($(this).attr("id")) ) { - $(this).append( - '
' + - '
' - ); - } - } else { - var message = document.createElement("span"); - $(message).attr("class","no-image"); - $(message).html(NO_GOOGLE_JACKET); - $(this).append(message); - } - }); - } - } + var target = ''; + if (this.openInNewWindow) { + target = 'target="_blank" '; + } + for (id in booksInfo) { + var book = booksInfo[id]; + $("."+book.bib_key).each(function() { + var a = document.createElement("a"); + a.href = book.info_url; + if (typeof(book.thumbnail_url) != "undefined") { + var img = document.createElement("img"); + img.src = book.thumbnail_url; + $(this).append(img); + var re = /^gbs-thumbnail-preview/; + if ( re.exec($(this).attr("id")) ) { + $(this).append( + '
' + + '
' + ); + } + } else { + var message = document.createElement("span"); + $(message).attr("class","no-image"); + $(message).html(NO_GOOGLE_JACKET); + $(this).append(message); + } + }); + } + } }; diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index e83ea3ac7f..8725f91190 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -22,7 +22,7 @@ widgets : ['zebra'], sortList: [[0,0]] }); - KOHA.Google.GetCoverFromIsbn(); + KOHA.Google.GetCoverFromIsbn(); $(".tagbutton").click(KOHA.Tags.add_tag_button); $("a.print").parent().after("
  • "+_("Add to Your Cart")+"<\/a><\/li>"); }); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index cf5edf702e..309f01d6cf 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -582,6 +582,14 @@ if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->pref 'sort'=>'-weight', limit=>$tag_quantity})); } +if (C4::Context->preference("OPACURLOpenInNewWindow")) { + # These values are going to be read by Javascript, at least in the case + # of the google covers + $template->param(covernewwindow => 'true'); +} else { + $template->param(covernewwindow => 'false'); +} + #Search for title in links my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); -- 2.39.5