autofit: 'auto'
};
+ // This object/dictionary controls which optional features are enabled
+ // XXXmang in progress
+ this.features = {
+ // search
+ // read aloud
+ // open library entry
+ // table of contents
+ // embed/share ui
+ // info ui
+ };
+
return this;
};
// Enact other parts of initial params
this.updateFromParams(params);
+ // Start AJAX request for OL data
+ this.getOpenLibraryJSON(this.gotOpenLibraryRecord);
+
+}
+
+// XXXmang
+BookReader.prototype.gotOpenLibraryRecord = function(olObject) {
+ // console.log(olObject);
+ if (olObject) {
+ if (olObject['table_of_contents']) {
+ console.log('xxx updating table of contents');
+ br.updateTOC(olObject['table_of_contents']); // XXX
+ }
+ }
+}
+
+BookReader.prototype.updateTOC = function(tocEntries) {
+ this.removeChapters();
+ for (var i = 0; i < tocEntries.length; i++) {
+ this.addChapterFromEntry(tocEntries[i]);
+ }
+}
+
+/*
+ * Example table of contents entry - this format is defined by Open Library
+ * {
+ * "pagenum": "17",
+ * "level": 1,
+ * "label": "CHAPTER I",
+ * "type": {"key": "/type/toc_item"},
+ * "title": "THE COUNTRY AND THE MISSION"
+ * }
+ */
+BookReader.prototype.addChapterFromEntry = function(tocEntryObject) {
+ console.log(tocEntryObject);
+ var pageIndex = this.getPageIndex(tocEntryObject['pagenum']);
+ // Only add if we know where it is
+ if (pageIndex) {
+ this.addChapter(tocEntryObject['title'], tocEntryObject['pagenum'], pageIndex);
+ }
}
BookReader.prototype.setupKeyListeners = function() {
});
*/
+ // XXXmang testing
+ this.addSearchResult('hi there', '25', 22);
$("#pager").draggable({axis:'x',containment:'parent'});
}
$('<div class="chapter" style="left:' + percentThrough + ';"><div class="title">'
+ chapterTitle + '<span>|</span> ' + uiStringPage + ' ' + pageNumber + '</div></div>')
.appendTo('#BRnavpos')
+ .data({'self': this, 'pageIndex': pageIndex })
.bt({
contentSelector: '$(this).find(".title")',
trigger: 'hover',
}, function() {
$(this).removeClass('front');
}
- );
+ )
+ .bind('click', function() {
+ $(this).data('self').jumpToIndex($(this).data('pageIndex'));
+ });
}
BookReader.prototype.removeChapters = function() {
return this.getPageURI(index, reduce, rotate);
}
+
+/////// Functions that can/should be overriden by third-parties
+
+// If your book has a record on Open Library you get some nice things for free
+BookReader.prototype.getOpenLibraryJSON = function(callback) {
+ return null;
+}
+
+
// Library functions
BookReader.util = {
disableSelect: function(jObject) {
return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px'></iframe>";
}
+// getOpenLibraryJSON
+br.getOpenLibraryJSON = function(callback) {
+ // Try looking up by ocaid first, then by source_record
+
+ var jsonURL = 'http://openlibrary.org/query.json?type=/type/edition&*=&ocaid=' + br.bookId;
+ $.ajax({
+ url: jsonURL,
+ success: function(data) {
+ if (data && data.length > 0) {
+ callback(data[0]);
+ } else {
+ // try sourceid
+ console.log('XXXmang couldnt find via ocaid');
+ jsonURL = 'http://openlibrary.org/query.json?type=/type/edition&*=&source_records=ia:' + br.bookId;
+ $.ajax({
+ url: jsonURL,
+ success: function(data) {
+ if (data && data.length > 0) {
+ callback(data[0]);
+ }
+ },
+ dataType: 'jsonp'
+ });
+ }
+ },
+ dataType: 'jsonp'
+ });
+}
+
br.pageW = [
<?
$i=0;