var FPR = FPR || {}; FPR.app = {}; FPR.app.init = (function($){ "use strict"; var Book, offline = false, sidebarWidth = 40, windowWidth; function init(bookURL){ var search = window.location.search.match(/book=(.*)/), bookURL = bookURL || (search ? search[1] : "moby-dick"); //-- Setup the browser prefixes FP.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 FP.Book("area"); //-- 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.listen("book:online", goOnline); Book.listen("book:offline", goOffline); //-- Start loading / parsing of the book. // This must be done AFTER adding listeners or hooks Book.start(bookURL); //-- Wait for Dom ready to handle jquery $(function() { controls(); }); } function meta(){ var title = Book.getTitle(), author = 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(){ var contents = Book.getTOC(), $toc = $("#toc"), $links, $items; $toc.empty(); //-- Recursively generate TOC levels $items = generateTocItems(contents); $toc.append($items); $links = $(".toc_link"); $links.on("click", function(e){ var $this = $(this), url = $this.data("url"); $(".openChapter").removeClass("openChapter"); $this.parent().addClass("openChapter"); //-- Provide the Book with the url to show // The Url must be found in the books manifest if(!Book.useHash){ Book.show(url); e.preventDefault(); } }); } function generateTocItems(contents){ var $container = $("