1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

add annotator example

This commit is contained in:
fchasen 2016-02-10 21:55:26 -05:00
parent 3a21665e80
commit 98ce08091d

210
examples/annotator.html Normal file
View file

@ -0,0 +1,210 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>EPUB.js Annotator Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="../dist/epub.js"></script>
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/annotator/1.2.9/annotator.min.js"></script> -->
<style type="text/css">
body {
margin: 0;
background: #fafafa;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #333;
position: absolute;
height: 100%;
width: 100%;
display: flex;
-webkit-align-items: center;
-webkit-justify-content: center;
}
#viewer {
width: 900px;
/*width: 80%;*/
height: 600px;
background: white;
box-shadow: 0 0 4px #ccc;
border-radius: 5px;
padding: 20px 40px;
/*width: 100%;*/
/* height: 400px;*/
position: relative;
/* Center Content */
margin: 40px auto;
}
/*
#viewer > iframe {
overflow: scroll;
height: 400px;
-webkit-column-axis: horizontal;
-webkit-column-fill: auto;
-webkit-column-width: 400px;
-webkit-column-gap: 10px;
} */
#viewer iframe {
/*background: white;*/
/*box-shadow: 0 0 4px #ccc;*/
/*width: 590px;
margin: 10px auto;*/
}
#prev {
left: 40px;
}
#next {
right: 40px;
}
.arrow {
position: fixed;
top: 50%;
margin-top: -32px;
font-size: 64px;
color: #E2E2E2;
font-family: arial, sans-serif;
font-weight: bold;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.arrow:hover {
color: #777;
}
.arrow:active {
color: #000;
}
#toc {
display: block;
margin: 10px auto;
}
::selection {
background: yellow;
}
@media (min-width: 1000px) {
.epub-container:before {
position: absolute;
width: 1px;
border-right: 1px #000 solid;
height: 90%;
z-index: auto;
left: 50%;
margin-left: -1px;
top: 5%;
opacity: .15;
box-shadow: -2px 0 15px rgba(0, 0, 0, 1);
content: "";
}
}
</style>
</head>
<body>
<div id="viewer"></div>
<div id="prev" class="arrow"></div>
<div id="next" class="arrow"></div>
<script>
// Load the opf
// var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
var book = ePub("../books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", {
method: "paginate",
width: "100%",
height: 600,
ignoreClass: 'annotator-hl'
});
var displayed = rendition.display(3);
// Navigation loaded
book.loaded.navigation.then(function(toc){
// console.log(toc);
});
var next = document.getElementById("next");
next.addEventListener("click", function(){
rendition.next();
}, false);
var prev = document.getElementById("prev");
prev.addEventListener("click", function(){
rendition.prev();
}, false);
var keyListener = function(e){
// Left Key
if ((e.keyCode || e.which) == 37) {
rendition.prev();
}
// Right Key
if ((e.keyCode || e.which) == 39) {
rendition.next();
}
};
rendition.on("keyup", keyListener);
document.addEventListener("keyup", keyListener, false);
rendition.on("locationChanged", function(location){
// console.log(location);
});
rendition.hooks.render.register(function (view) {
var adder = [
['.annotator-adder, .annotator-outer', ['position', 'fixed']]
];
view.addScript('https://cdn.jsdelivr.net/jquery/3.0.0-beta1/jquery.min.js').
then(function () {
return view.addScript('https://cdn.jsdelivr.net/annotator/1.2.9/annotator-full.min.js');
}).
then(function () {
return view.addCss('https://cdn.jsdelivr.net/annotator/1.2.9/annotator.min.css');
}).
then(function () {
view.addStylesheetRules(adder);
view.window.Annotator.Util.mousePosition = function(event) {
var body = view.document.body;
// var offset = view.position();
return {
top: event.pageY,
left: event.pageX
};
};
var ann = new view.window.Annotator(view.document.body);
});
})
</script>
</body>
</html>