[open-ils-commits] [GIT] Evergreen ILS branch master updated. dde1d0e14ef7d13eb66797208ff34917df926d44

Evergreen Git git at git.evergreen-ils.org
Thu Feb 21 17:50:15 EST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  dde1d0e14ef7d13eb66797208ff34917df926d44 (commit)
       via  6c4c15cf710cae0bb7af2ff79fb768bb4347a54c (commit)
      from  8cfad95dac348c1ae32477c3e9c3832adaeaaa8e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dde1d0e14ef7d13eb66797208ff34917df926d44
Author: Dan Scott <dscott at laurentian.ca>
Date:   Wed Feb 20 11:37:08 2013 -0500

    TPAC: Make Google Books Preview depend on Dojo
    
    It would be possible, but painful, to do all of this in raw JavaScript,
    so make the preview functionality depend on Dojo. Also, split out the
    relevant JavaScript into its own file. Also, don't search for a preview
    if no ISBNs have been gathered; I'm sure Google is never going to return
    a result for ISBN:undefined.
    
    You can test this functionality in the sample record set using ISBN
    4431287752.
    
    Thanks to Ben Shum for the review comments!
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Ben Shum <bshum at biblio.org>

diff --git a/Open-ILS/src/templates/opac/parts/ac_google_books.tt2 b/Open-ILS/src/templates/opac/parts/ac_google_books.tt2
new file mode 100644
index 0000000..8243fe0
--- /dev/null
+++ b/Open-ILS/src/templates/opac/parts/ac_google_books.tt2
@@ -0,0 +1,97 @@
+<script type="text/javascript">
+var GBisbns = Array();
+
+/**
+ *
+ * @param {DOM object} isbn The form element containing the input parameters "isbns"
+ */
+function searchForGBPreview( isbn ) {
+  dojo.require("dojo.io.script");
+  dojo.io.script.get({"url": "https://www.google.com/jsapi"});
+  dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
+}
+
+/**
+ * This function is the call-back function for the JSON scripts which 
+ * executes a Google book search response.
+ *
+ * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
+ */
+function GBPreviewCallback(GBPBookInfo) {
+  if (GBPBookInfo.totalItems < 1) return;
+
+  var accessInfo = GBPBookInfo.items[0].accessInfo;
+  if ( !accessInfo ) {
+    return;
+  }
+
+  if ( accessInfo.embeddable ) {
+    /* Add a button below the book cover image to load the preview. */
+    var GBPBadge = document.createElement( 'img' );
+    GBPBadge.id = 'gbpbadge';
+    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';
+    GBPBadgelink = document.createElement('a');
+    GBPBadgelink.href = 'javascript:GBDisplayPreview();';
+    GBPBadgelink.appendChild( GBPBadge );
+    dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
+  }
+}
+
+/**
+ *  This is called when the user clicks on the 'Preview' link.  We assume
+ *  a preview is available from Google if this link was made visible.
+ */
+function GBDisplayPreview() {
+  var GBPreviewPane = document.createElement('div');
+  GBPreviewPane.id = 'rdetail_preview_div';
+  GBPreviewPane.style.height = '800px';
+  GBPreviewPane.style.width = '600px';
+  GBPreviewPane.style.display = 'block';
+  var GBClear = document.createElement('div');
+  GBClear.style.padding = '1em';
+  dojo.byId('canvas_main').insertBefore(GBPreviewPane, dojo.byId('rdetail_record_details'));
+  dojo.byId('canvas_main').insertBefore(GBClear, dojo.byId('rdetail_record_details'));
+  if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
+     google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
+     GBPreviewPane.setAttribute('loaded', 'true');
+  }
+}
+
+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';
+}
+
+dojo.addOnLoad(function() {
+  var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
+  for (var i = 0; i < spans.length; i++) {
+    var prop = spans[i].getAttribute('itemprop');
+    if (!prop) {
+      continue;
+    }
+    var isbn = spans[i].textContent || spans[i].innerText;
+    if (!isbn) {
+      continue;
+    }
+    isbn = isbn.toString().replace(/^\s+/,"");
+    var idx = isbn.indexOf(" ");
+    if (idx > -1) {
+      isbn = isbn.substring(0, idx);
+    }
+    isbn = isbn.toString().replace(/-/g,"");
+    if (!isbn) {
+      continue;
+    }
+    GBisbns.push(isbn);
+  }
+
+  if (GBisbns.length) {
+      searchForGBPreview(GBisbns[0]);
+  }
+});
+</script>
diff --git a/Open-ILS/src/templates/opac/parts/acjs.tt2 b/Open-ILS/src/templates/opac/parts/acjs.tt2
index 33ab4b7..438daf5 100644
--- a/Open-ILS/src/templates/opac/parts/acjs.tt2
+++ b/Open-ILS/src/templates/opac/parts/acjs.tt2
@@ -52,100 +52,3 @@
         END; # IF ident
     %]
 </script>
-[%- IF ctx.google_books_preview -%]
-<script type="text/javascript">
-var GBisbns = Array();
-
-/**
- *
- * @param {DOM object} isbn The form element containing the input parameters "isbns"
- */
-function searchForGBPreview( isbn ) {
-  dojo.require("dojo.io.script");
-  dojo.io.script.get({"url": "https://www.google.com/jsapi"});
-  dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
-}
-
-/**
- * This function is the call-back function for the JSON scripts which 
- * executes a Google book search response.
- *
- * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
- */
-function GBPreviewCallback(GBPBookInfo) {
-  if (GBPBookInfo.totalItems < 1) return;
-
-  var accessInfo = GBPBookInfo.items[0].accessInfo;
-  if ( !accessInfo ) {
-    return;
-  }
-
-  if ( accessInfo.embeddable ) {
-    /* Add a button below the book cover image to load the preview. */
-    var GBPBadge = document.createElement( 'img' );
-    GBPBadge.id = 'gbpbadge';
-    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';
-    GBPBadgelink = document.createElement('a');
-    GBPBadgelink.href = 'javascript:GBDisplayPreview();';
-    GBPBadgelink.appendChild( GBPBadge );
-    dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
-  }
-}
-
-/**
- *  This is called when the user clicks on the 'Preview' link.  We assume
- *  a preview is available from Google if this link was made visible.
- */
-function GBDisplayPreview() {
-  var GBPreviewPane = document.createElement('div');
-  GBPreviewPane.id = 'rdetail_preview_div';
-  GBPreviewPane.style.height = '800px';
-  GBPreviewPane.style.width = '600px';
-  GBPreviewPane.style.display = 'block';
-  var GBClear = document.createElement('div');
-  GBClear.style.padding = '1em';
-  dojo.byId('canvas_main').insertBefore(GBPreviewPane, dojo.byId('rdetail_record_details'));
-  dojo.byId('canvas_main').insertBefore(GBClear, dojo.byId('rdetail_record_details'));
-  if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
-     google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
-     GBPreviewPane.setAttribute('loaded', 'true');
-  }
-}
-
-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';
-}
-
-dojo.addOnLoad(function() {
-  var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
-  for (var i = 0; i < spans.length; i++) {
-    var prop = spans[i].getAttribute('itemprop');
-    if (!prop) {
-      continue;
-    }
-    var isbn = spans[i].textContent || spans[i].innerText;
-    if (!isbn) {
-      continue;
-    }
-    isbn = isbn.toString().replace(/^\s+/,"");
-    var idx = isbn.indexOf(" ");
-    if (idx > -1) {
-      isbn = isbn.substring(0, idx);
-    }
-    isbn = isbn.toString().replace(/-/g,"");
-    if (!isbn) {
-      continue;
-    }
-    GBisbns.push(isbn);
-  }
-
-  searchForGBPreview(GBisbns[0]);
-});
-</script>
-[%- END %]
diff --git a/Open-ILS/src/templates/opac/parts/header.tt2 b/Open-ILS/src/templates/opac/parts/header.tt2
index e069b6e..4397e81 100644
--- a/Open-ILS/src/templates/opac/parts/header.tt2
+++ b/Open-ILS/src/templates/opac/parts/header.tt2
@@ -96,4 +96,8 @@
     IF use_autosuggest.enabled == "t";
         want_dojo = 1;
     END;
+
+    IF ctx.google_books_preview;
+        want_dojo = 1;
+    END;
 %]
diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2
index d6cacbe..07dfa9a 100644
--- a/Open-ILS/src/templates/opac/parts/js.tt2
+++ b/Open-ILS/src/templates/opac/parts/js.tt2
@@ -81,5 +81,6 @@
 [% END; # use_autosuggest %]
 
 [% INCLUDE "opac/parts/acjs.tt2" IF ctx.page == 'record' %]
+[% INCLUDE "opac/parts/ac_google_books.tt2" IF ctx.page == 'record' %]
 
 [%- END; # want_dojo -%]

commit 6c4c15cf710cae0bb7af2ff79fb768bb4347a54c
Author: Dan Scott <dscott at laurentian.ca>
Date:   Tue Feb 5 12:25:24 2013 -0500

    TPAC: Google Books preview loader
    
    Refinements should include checking more than just the first ISBN for
    embeddability and passing more identifiers to the preview loader.
    Roughly equivalent to what JSPAC had though.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Ben Shum <bshum at biblio.org>

diff --git a/Open-ILS/src/templates/opac/parts/acjs.tt2 b/Open-ILS/src/templates/opac/parts/acjs.tt2
index fe15569..33ab4b7 100644
--- a/Open-ILS/src/templates/opac/parts/acjs.tt2
+++ b/Open-ILS/src/templates/opac/parts/acjs.tt2
@@ -52,4 +52,100 @@
         END; # IF ident
     %]
 </script>
+[%- IF ctx.google_books_preview -%]
+<script type="text/javascript">
+var GBisbns = Array();
+
+/**
+ *
+ * @param {DOM object} isbn The form element containing the input parameters "isbns"
+ */
+function searchForGBPreview( isbn ) {
+  dojo.require("dojo.io.script");
+  dojo.io.script.get({"url": "https://www.google.com/jsapi"});
+  dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
+}
+
+/**
+ * This function is the call-back function for the JSON scripts which 
+ * executes a Google book search response.
+ *
+ * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
+ */
+function GBPreviewCallback(GBPBookInfo) {
+  if (GBPBookInfo.totalItems < 1) return;
+
+  var accessInfo = GBPBookInfo.items[0].accessInfo;
+  if ( !accessInfo ) {
+    return;
+  }
+
+  if ( accessInfo.embeddable ) {
+    /* Add a button below the book cover image to load the preview. */
+    var GBPBadge = document.createElement( 'img' );
+    GBPBadge.id = 'gbpbadge';
+    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';
+    GBPBadgelink = document.createElement('a');
+    GBPBadgelink.href = 'javascript:GBDisplayPreview();';
+    GBPBadgelink.appendChild( GBPBadge );
+    dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
+  }
+}
+
+/**
+ *  This is called when the user clicks on the 'Preview' link.  We assume
+ *  a preview is available from Google if this link was made visible.
+ */
+function GBDisplayPreview() {
+  var GBPreviewPane = document.createElement('div');
+  GBPreviewPane.id = 'rdetail_preview_div';
+  GBPreviewPane.style.height = '800px';
+  GBPreviewPane.style.width = '600px';
+  GBPreviewPane.style.display = 'block';
+  var GBClear = document.createElement('div');
+  GBClear.style.padding = '1em';
+  dojo.byId('canvas_main').insertBefore(GBPreviewPane, dojo.byId('rdetail_record_details'));
+  dojo.byId('canvas_main').insertBefore(GBClear, dojo.byId('rdetail_record_details'));
+  if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
+     google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
+     GBPreviewPane.setAttribute('loaded', 'true');
+  }
+}
+
+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';
+}
 
+dojo.addOnLoad(function() {
+  var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
+  for (var i = 0; i < spans.length; i++) {
+    var prop = spans[i].getAttribute('itemprop');
+    if (!prop) {
+      continue;
+    }
+    var isbn = spans[i].textContent || spans[i].innerText;
+    if (!isbn) {
+      continue;
+    }
+    isbn = isbn.toString().replace(/^\s+/,"");
+    var idx = isbn.indexOf(" ");
+    if (idx > -1) {
+      isbn = isbn.substring(0, idx);
+    }
+    isbn = isbn.toString().replace(/-/g,"");
+    if (!isbn) {
+      continue;
+    }
+    GBisbns.push(isbn);
+  }
+
+  searchForGBPreview(GBisbns[0]);
+});
+</script>
+[%- END %]
diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2
index b0fee8f..e334975 100644
--- a/Open-ILS/src/templates/opac/parts/config.tt2
+++ b/Open-ILS/src/templates/opac/parts/config.tt2
@@ -128,4 +128,9 @@ search.basic_config = {
     none_label => l("All Formats"),
 };
 
+##############################################################################
+# Show Google Book Previews
+# Set to 1 or 'true' to enable
+ctx.google_books_preview = 0;
+
 %]
diff --git a/docs/RELEASE_NOTES_NEXT/tpac_google_books_preview.txt b/docs/RELEASE_NOTES_NEXT/tpac_google_books_preview.txt
new file mode 100644
index 0000000..c565825
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/tpac_google_books_preview.txt
@@ -0,0 +1,12 @@
+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.
+
+By default, this functionality is disabled to protect the privacy of users
+who might not want to share their browsing behaviour with Google.

-----------------------------------------------------------------------

Summary of changes:
 .../src/templates/opac/parts/ac_google_books.tt2   |   97 ++++++++++++++++++++
 Open-ILS/src/templates/opac/parts/acjs.tt2         |    1 -
 Open-ILS/src/templates/opac/parts/config.tt2       |    5 +
 Open-ILS/src/templates/opac/parts/header.tt2       |    4 +
 Open-ILS/src/templates/opac/parts/js.tt2           |    1 +
 .../tpac_google_books_preview.txt                  |   12 +++
 6 files changed, 119 insertions(+), 1 deletions(-)
 create mode 100644 Open-ILS/src/templates/opac/parts/ac_google_books.tt2
 create mode 100644 docs/RELEASE_NOTES_NEXT/tpac_google_books_preview.txt


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list