Tweak Google Book Preview Display user/dbwells/tpac_google_books_tweak
authorDan Wells <dbw2@calvin.edu>
Mon, 25 Feb 2013 16:39:00 +0000 (11:39 -0500)
committerDan Wells <dbw2@calvin.edu>
Mon, 25 Feb 2013 16:55:19 +0000 (11:55 -0500)
This commit makes three changes to the Google Book preview link:

1) Move the button to the same spot on the page as the viewer.
This clarifies the relationship between the button and the viewer,
and makes it far less likely that the viewer will load off the
screen.

2) Make the button a toggle for turning the viewer on and off.

3) In conjunction with (2), add some additional text to the button
link to follow the toggling action.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/templates/opac/parts/ac_google_books.tt2
docs/RELEASE_NOTES_NEXT/tpac_google_books_preview.txt

index 8243fe0..e8119bf 100644 (file)
@@ -1,5 +1,6 @@
 <script type="text/javascript">
 var GBisbns = Array();
+var GBPreviewShowing = false;
 
 /**
  *
@@ -32,11 +33,13 @@ function GBPreviewCallback(GBPBookInfo) {
     GBPBadge.src = 'https://www.google.com/intl/[% ctx.locale.substr(0,2) %]/googlebooks/images/gbs_preview_button1.gif';
     GBPBadge.title = dojo.byId('rdetail_title').innerHTML;
     GBPBadge.style.border = 0;
-    GBPBadge.style.margin = '0.5em 0 0 0';
+    GBPBadge.style.verticalAlign = 'middle';
     GBPBadgelink = document.createElement('a');
-    GBPBadgelink.href = 'javascript:GBDisplayPreview();';
+    GBPBadgelink.id = 'gbptoggle';
     GBPBadgelink.appendChild( GBPBadge );
-    dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
+    GBPBadgelink.href = 'javascript:GBDisplayPreview();';
+    GBPBadgelink.appendChild( document.createTextNode(' [% l('Show Preview') %]') );
+    dojo.byId('canvas_main').insertBefore(GBPBadgelink, dojo.byId('rdetail_record_details'));
   }
 }
 
@@ -64,7 +67,24 @@ function GBPViewerLoadCallback() {
   var GBPViewer = new google.books.DefaultViewer(dojo.byId('rdetail_preview_div'));
   GBPViewer.load('ISBN:' + GBisbns[0]);
   GBPViewer.resize();
-  dojo.byId('gbpbadge').style.display = 'none';
+  var GBPBadgelink = dojo.byId('gbptoggle');
+  GBPBadgelink.href = 'javascript:GBShowHidePreview();';
+  GBShowHidePreview(GBPBadgelink);
+}
+
+function GBShowHidePreview(toggle) {
+  if (!toggle) {
+    toggle = dojo.byId('gbptoggle');
+  }
+  if (!GBPreviewShowing) {
+    dojo.byId('rdetail_preview_div').style.display = 'inherit';
+    toggle.lastChild.nodeValue = ' [% l('Hide Preview') %]';
+    GBPreviewShowing = true;
+  } else {
+    dojo.byId('rdetail_preview_div').style.display = 'none';
+    toggle.lastChild.nodeValue = ' [% l('Show Preview') %]';
+    GBPreviewShowing = false;
+  }
 }
 
 dojo.addOnLoad(function() {
index c565825..d5ec36a 100644 (file)
@@ -4,9 +4,9 @@ TPAC: Google Books preview
 Setting `ctx.google_books_preview` to `1` in the TPAC `config.tt2`
 configuration file will cause the TPAC to check to see, as part of the record
 details view, if Google Books has an online preview available. If it does,
-then a preview button will be displayed in the book cover image location.
-If the user then clicks the preview button, the preview will load below the
-title of the book in the record details page.
+then a preview button will be displayed below the list of copies. If the user
+then clicks the preview button, the preview will load below the button. At that
+point, the button will then will act as a toggle to turn the viewer on and off.
 
 By default, this functionality is disabled to protect the privacy of users
 who might not want to share their browsing behaviour with Google.