var EPUBJSR = EPUBJSR || {}; EPUBJSR.app = {}; EPUBJSR.app.init = (function($){ "use strict"; var Book, offline = false, sidebarWidth = 0, windowWidth; function init(bookURL){ var search = window.location.search.match(/book=(.*)/), bookURL = bookURL || (search ? search[1] : "moby-dick"); //-- Setup the browser prefixes // EPUBJS.core.crossBrowserColumnCss(); //-- Set up our sidebar windowWidth = $(window).width(); if(windowWidth > 550){ $("#main").width(windowWidth-sidebarWidth); }else{ $("#main").width(windowWidth); } //-- Create a new book object, // this will create an iframe in the el with the ID provided Book = new EPUBJS.Book({ bookPath: bookURL, restore : true }); //Book.single = true; //-- Add listeners to handle book events //-- Full list of event are at start of book.js // Book.listen("book:metadataReady", meta); // Book.listen("book:tocReady", toc); // Book.listen("book:bookReady", bookReady); // Book.listen("book:chapterReady", chapterChange); Book.on("book:online", goOnline); Book.on("book:offline", goOffline); Book.getMetadata().then(meta); Book.getToc().then(toc); Book.ready.all.then(bookReady); Book.renderTo("area"); //Book.registerHook("beforeChapterDisplay", EPUBJS.Hooks.transculsions.insert); //-- Start loading / parsing of the book. // This must be done AFTER adding listeners or hooks //Book.renderTo("area"); //-- Wait for Dom ready to handle jquery $(function() { controls(); }); return Book; } function meta(meta){ var title = meta.bookTitle,//Book.getTitle(), author = meta.creator, //Book.getCreator(), $title = $("#book-title"), $author = $("#chapter-title"), $dash = $("#title-seperator"); document.title = title+" – "+author; $title.html(title); $author.html(author); $dash.show(); } function toc(contents){ var $toc = $("#toc"), $links, $items; $toc.empty(); //-- Recursively generate TOC levels $items = generateTocItems(contents, 1); $toc.append($items); $links = $(".toc_link"); $links.on("click", function(e){ var $this = $(this), url = $this.data("url"); $(".openChapter").removeClass("openChapter"); $this.parents('li').addClass("openChapter"); //-- Provide the Book with the url to show // The Url must be found in the books manifest Book.goto(url); e.preventDefault(); }); } function loadSettings() { var userFont = ""; if (!localStorage.getItem("fontSize")) { userFont = "medium"; localStorage.setItem("fontSize", userFont); } else { userFont = localStorage.getItem("fontSize"); } var $settings = $("#settingsPanel"); $settings.append(""); var $settingsItem = $("
  • "); var $fontSizes = $("Extra Small
    " + "Small
    " + "Medium
    " + "Large
    " + "Extra Large"); $settingsItem.find("h3").text('Font Size').after($fontSizes); $settings.find("ul").append($settingsItem); var $fontSizeButtons = $('input[name="fontSize"]'); $fontSizeButtons.each(function() { if ($(this).attr("value") == userFont) { $(this).attr("checked", "checked"); } $(this).on("click", function() { localStorage.setItem("fontSize", $(this).attr("value")); //reload the page after selecting a new font Book.iframe.contentDocument.location.reload(true); }); }); //Single or double column /* var userLayout = ""; if (!localStorage.getItem("layout")) { userLayout = "medium"; localStorage.setItem("layout", userLayout); } else { userLayout = localStorage.getItem("layout"); } var $settings = $("#settingsPanel"); $settings.append(""); var $settingsItem = $("
  • "); var $layout = $("Single Column
    " + "Double Column
    "); $settingsItem.find("h3").text('Font Size').after($layout); $settings.find("ul").append($settingsItem); var $layoutButtons = $('input[name="layout"]'); $layoutButtons.each(function() { if ($(this).attr("value") == userLayout) { $(this).attr("checked", "checked"); } $(this).on("click", function() { localStorage.setItem("layout", $(this).attr("value")); //reload the page after selecting a new font Book.iframe.contentDocument.location.reload(true); }); }); //LineSpacing var userLineSpacing = ""; //Contrast var userContrast = ""; //Font Type var userFontType = ""; */ } function generateTocItems(contents, level){ var $container = $("