Remove trailing pipe on info modal
[bookreader.git] / BookReaderIA / datanode / BookReaderJSIA.php
index 55436a1..af5c795 100644 (file)
@@ -313,13 +313,16 @@ br.cleanupMetadata = function() {
 // getEmbedURL
 //________
 // Returns a URL for an embedded version of the current book
-br.getEmbedURL = function() {
+br.getEmbedURL = function(viewParams) {
     // We could generate a URL hash fragment here but for now we just leave at defaults
     var url = 'http://' + window.location.host + '/stream/'+this.bookId;
     if (this.subPrefix != this.bookId) { // Only include if needed
         url += '/' + this.subPrefix;
     }
     url += '?ui=embed';
+    if (viewParams) {
+        url += '#' + this.fragmentFromParams(viewParams);
+    }
     return url;
 }
 
@@ -327,7 +330,7 @@ br.getEmbedURL = function() {
 //________
 // Returns the embed code HTML fragment suitable for copy and paste
 br.getEmbedCode = function() {
-    return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px'></iframe>";
+    return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px' frameborder='0' ></iframe>";
 }
 
 // getOpenLibraryRecord
@@ -358,6 +361,51 @@ br.getOpenLibraryRecord = function(callback) {
     });
 }
 
+br.buildInfoDiv = function(jInfoDiv) {
+    // $$$ it might make more sense to have a URL on openlibrary.org that returns this info
+
+    var escapedTitle = BookReader.util.escapeHTML(this.bookTitle);
+    var domainRe = /(\w+\.(com|org))/;
+    var domain = domainRe.exec(this.bookUrl)[1];
+        
+    // $$$ cover looks weird before it loads
+    jInfoDiv.find('.BRfloatCover').append([
+                    '<div style="height: 140px; min-width: 80px; padding: 0; margin: 0;"><a href="', this.bookUrl, '"><img src="http://www.archive.org/download/', this.bookId, '/page/cover_t.jpg" alt="' + escapedTitle + '" height="140px" /></a></div>'].join('')
+    );
+
+    jInfoDiv.find('.BRfloatMeta').append([
+                    // $$$ description
+                    //'<p>Published ', this.bookPublished,
+                    //, <a href="Open Library Publisher Page">Publisher name</a>',
+                    //'</p>',
+                    //'<p>Written in <a href="Open Library Language page">Language</a></p>',
+                    '<h3>Other Formats</h3>',
+                    '<ul class="links">',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '.pdf">PDF</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_djvu.txt">Plain Text</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_daisy.zip">DAISY</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '.epub">ePub</a><span>|</span></li>',
+                        '<li><a href="https://www.amazon.com/gp/digital/fiona/web-to-kindle?clientid=IA&itemid=', this.bookId, '&docid=', this.subPrefix, '">Send to Kindle</a></li>',
+                    '</ul>',
+                    '<p class="moreInfo"><span></span>More information on <a href="'+ this.bookUrl + '">' + domain + '</a>  </p>'].join('\n'));
+                    
+    jInfoDiv.find('.BRfloatFoot').append([
+                '<span>|</span>',                
+                '<a href="http://openlibrary.org/contact" class="problem">Report a problem</a>',
+    ].join('\n'));
+                
+    if (domain == 'archive.org') {
+        jInfoDiv.find('.BRfloatMeta p.moreInfo span').css(
+            {'background': 'url(http://www.archive.org/favicon.ico) no-repeat', 'width': 22, 'height': 18 }
+        );
+    }
+    
+    jInfoDiv.find('.BRfloatTitle a').attr({'href': this.bookUrl, 'alt': this.bookTitle}).text(this.bookTitle);
+    var bookPath = (window.location + '').replace('#','%23');
+    jInfoDiv.find('a.problem').attr('href','http://openlibrary.org/contact?path=' + bookPath);
+
+}
+
 br.pageW =  [
             <?
             $i=0;
@@ -438,10 +486,17 @@ if ('' != $metaData->{'page-progression'}) {
   echo "br.pageProgression = 'lr';\n";
 }
 
-if ('browserlending' == $metaData->{'collection'}) {
+$useOLAuth = false;
+foreach ($metaData->xpath('//collection') as $collection) {
+    if('browserlending' == $collection) {
+        $useOLAuth = true;
+    }
+}
+
+if ($useOLAuth) {
     echo "br.olAuth = true;\n";
 } else {
-    echo "br.olAuth = false; //" . $metaData->{'collection'} ."\n";
+    echo "br.olAuth = false;\n";
 }
 
 # Special cases
@@ -465,23 +520,14 @@ if (typeof(brConfig) != 'undefined') {
             br.reduce = brConfig['reduce'];
         }
     } else if (brConfig['mode'] == 2) {
-        br.mode = 2;
-      
-<?
-        //$$$mang hack to override request for 2up for books with attribution page
-        //   as first page until we can display that page in 2up
-        $needle = 'goog';
-        if (strrpos($id, $needle) === strlen($id)-strlen($needle)) {
-            print "// override for books with attribution page\n";
-            print "br.mode = 1;\n";
-        }
-?>
+        br.mode = 2;      
     }
 } // brConfig
 
 
 function OLAuth() {
-    this.authUrl = 'http://home.us.archive.org/~rkumar/olauth.php?id=' + br.bookId;
+    this.authUrl = 'http://openlibrary.org/ia_auth/' + br.bookId;
+    this.olConnect = false;
     return this;
 }
 
@@ -490,7 +536,7 @@ OLAuth.prototype.init = function() {
     htmlStr    +=  '<p>Please wait...</p>';
 
     this.showPopup("#ddd", "#000", htmlStr);
-    $.ajax({url:this.authUrl, dataType:'jsonp', jsonpCallback:'initCallback'});
+    $.ajax({url:this.authUrl + '?rand='+Math.random(), dataType:'jsonp', jsonpCallback:'olAuth.initCallback'});
 }
 
 OLAuth.prototype.showPopup = function(bgColor, textColor, msg) {
@@ -524,6 +570,7 @@ OLAuth.prototype.initCallback = function(obj) {
     
     //user is authenticated
     this.setCookie(obj.token);
+    this.olConnect = true;
     this.startPolling();    
     br.init();
 }
@@ -534,6 +581,7 @@ OLAuth.prototype.callback = function(obj) {
         clearInterval(this.poller);
         this.ttsPoller = null;
     } else {
+        this.olConnect = true;
         this.setCookie(obj.token);
     }
 }
@@ -551,7 +599,15 @@ OLAuth.prototype.setCookie = function(value) {
 OLAuth.prototype.startPolling = function () {    
     var self = this;
     this.poller=setInterval(function(){
-        $.ajax({url:self.authUrl, dataType:'jsonp', jsonpCallback:'callback'});
+        if (!self.olConnect) {
+          self.showPopup("#f00", "#fff", 'Cound not connect to Open Library for authentication. Please check to see if you are still connected to the Internet, and then reload this web page.');
+          clearInterval(self.poller);
+          self.ttsPoller = null;        
+        } else {
+          self.olConnect = false;
+          //be sure to add random param to authUrl to avoid stale cache
+          $.ajax({url:self.authUrl+'?rand='+Math.random(), dataType:'jsonp', jsonpCallback:'olAuth.callback'});
+        }
     },300000);   
 }