Skip to content

Commit

Permalink
Temp Fix for getting $ (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchasen committed Oct 15, 2013
1 parent 702a664 commit ef57555
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
Epub.js Reader
================================

![FuturePress Views](http://fchasen.com/futurepress/fp.png)

Epub.js is a JavaScript library for rendering ePub documents in the browser, across many devices.

Epub.js provides common ebook functions (such as persistence and pagination) without the need to develop a dedicated application or plugin.

Unlike an application, our HTML/JavaScript reader can be hosted anywhere and can be easily customized using JavaScript, such as changing the interface or adding annotation functionality.

[Try it while reading Moby Dick](http://epubjs-reader.appspot.com/)

Getting Started
Expand Down
34 changes: 20 additions & 14 deletions src/scripts/directives/epub-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ angular.module('Reader')

$rootScope.$on('$locationChangeSuccess', function(e, url){
var path;

// console.log("url", url, silent)
if(!silent) {
path = $location.path();

if(isDocument(path)) {
$scope.path = pathFromLocation();
// console.log("path", path)
} else {
$scope.cfi = decodeURIComponent(path);
}
Expand All @@ -76,7 +77,7 @@ angular.module('Reader')

$scope.currentCfi = e.cfi;


// console.debug("after chapter", $scope.currentCfi)
// if(!$scope.$$phase) {

// $scope.$apply(function(){
Expand All @@ -88,8 +89,9 @@ angular.module('Reader')
// $scope.$apply();
// }
// }

$scope.updateAnnotations();
if($scope.annotator) {
$scope.updateAnnotations();
}

gAnalytics.trackChapterChange(e)
gAnalytics.trackLinkFollows(e);
Expand All @@ -101,7 +103,7 @@ angular.module('Reader')
if($scope.currentCfi == hash) return;

$scope.currentCfi = hash;

// console.debug("after page", $scope.currentCfi)
$location.hash('');
$location.path($scope.currentCfi);

Expand All @@ -120,44 +122,48 @@ angular.module('Reader')

$scope.updateAnnotations = function() {
var annotatations = [],
annotator = $scope.book.render.iframe.contentWindow.Annotator,
_$, $annotations, width;

annotator = $scope.book.render.iframe.contentWindow.annotator,
//$scope.book.render.iframe.contentWindow.Annotator,
_$ = $scope.book.render.iframe.contentWindow.annotator.constructor.$,
$annotations, width;

if($scope.noUpdate) {
$scope.noUpdate = false;
return;
}


if(!annotator) {
if($scope.annotator) $scope.annotator.updateViewer([]);
return;
};

_$ = annotator.$;
//_$ = annotator.$;

$annotations = _$(".annotator-hl");
width = $scope.book.render.iframe.clientWidth;

//-- Find visible annotations

$annotations.each(function(){
var $this = _$(this),
left = this.getBoundingClientRect().left;

if(left >= 0 && left <= width) {
// console.debug("on screen", left);
annotatations.push($this.data('annotation'));
}

});
// console.debug("annotatations", $annotations, annotatations)
// console.debug("annotatations", annotatations)

//-- Update viewer
$scope.annotator.updateViewer(annotatations);

};

$scope.afterAnnotationsLoaded = function(annotator, annotatations) {
var _$ = $scope.book.render.iframe.contentWindow.Annotator.$;
var _$ = $scope.book.render.iframe.contentWindow.annotator.constructor.$;
//$scope.book.render.iframe.contentWindow.Annotator.$;

// Initialize annotation event tracking
gAnalytics.trackAnnotations();
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/directives/epub-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('Reader')
$scope.nextArrowState = "";
$scope.isReady = false;

var book = $scope.book = $rootScope.book = ePub({ restore: true, version: 0.1 });
var book = $scope.book = $rootScope.book = ePub({ restore: true, version: 0.12 });

$scope.metadata = book.getMetadata();
$scope.toc = book.getToc();
Expand Down
27 changes: 27 additions & 0 deletions src/scripts/libs/epubjs/swipes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
EPUBJS.Hooks.register("beforeChapterDisplay").swipeDetection = function(callback, renderer){

//-- Load jQuery into iframe header
EPUBJS.core.addScripts([ "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js",
"http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"],
function(){
//-- Create a script element, you could also load this from an external file like above
var script = renderer.doc.createElement("script");

//-- Listen for swipe events
script.text = '\
$(window).on("swipeleft", function() {\
alert("right");\
renderer.book.nextPage();\
});\
$(window).on("swiperight", function() {\
renderer.book.prevPage();\
});';

renderer.doc.head.appendChild(script);

}, renderer.doc.head);



if(callback) callback();
}
5 changes: 2 additions & 3 deletions src/styles/annotations.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.annotator-hl, .annotator-hl-active {
background: #feffd5 !important;
cursor: pointer;
.ui-loader {
display: none;
}

0 comments on commit ef57555

Please sign in to comment.