Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
161 lines (150 loc) · 4.89 KB
/
Copy pathindex.html
File metadata and controls
161 lines (150 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<title></title>
<style type="text/css">
html, body {
height: 100%;
margin:0;padding:0;
}
#reader {
width: 580px;
margin: auto;
min-height: 100%;
box-shadow: gray 0 0 10px;
padding: 10px;
}
#prevPage,
#nextPage {
position: fixed;
height: 100%;;
background-color: #eee;
color: transparent;
width; 40px;
}
#nextPage { right: 0; }
#prevPage { left: 0; }
</style>
<style id="pagestyles" type="text/css">
</style>
</head>
<body>
<a href="#" id="prevPage">next page</a>
<a href="#" id="nextPage">next page</a>
<div id="reader"></div>
<script src="js/zip/WebContent/zip.js" type="text/javascript"></script>
<script src="js/zip/WebContent/zip-fs.js" type="text/javascript"></script>
<script src="js/dataview/DataView.js" type="text/javascript"></script>
<script src="js/book.js" type="text/javascript"></script>
<script src="js/book.reader.js" type="text/javascript"></script>
<script type="text/javascript">
zip.workerScriptsPath = "js/zip/WebContent/";
var db = document.body; //('dropbox');
var noopHandler = function(evt) {
evt.stopPropagation();
evt.preventDefault();
}
db.addEventListener('dragenter', noopHandler, false);
db.addEventListener('dragexit', noopHandler, false);
db.addEventListener('dragover', noopHandler, false);
db.addEventListener('drop', function(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files;
if(files.length > 0) {
var file =files[0];
if(file.type == 'application/epub+zip') {
startReader(file);
} else {
console.log('wrong file type');
}
}
}, false);
function startReader(file) {
var fs = new zip.fs.FS();
fs.getContent = function(path, cb, type) {
if(!type) type = 'text';
var ele = this.find(path);
if(ele) {
ele.getBlob(function(text) {
var fr = new FileReader();
fr.onload = function(text) {
cb(text.target.result);
};
if(type == 'text') {
fr.readAsText(text);
}
else if(type == 'uri') {
fr.readAsDataURL(text);
} else {
fr.readAsBinaryString(text);
}
});
} else {
console.log(path, ' not found');
cb(null);
}
};
fs.getXML = function(path, cb, type) {
if(!type) type = 'text';
this.getContent(path, function(text){
if(text !== null) {
var parser = new DOMParser(),
doc = parser.parseFromString(text, 'application/xml');
cb(doc);
} else { cb(null) }
}, type);
};
fs.importBlob(file,
function()
{
var myBook = new mit.book.Book(fs);
var reader = new mit.book.Reader(document.getElementById('reader'));
//fs.find('META-INF/container.xml').getText(
fs.getXML('META-INF/container.xml', function(doc) {
var roots = doc.getElementsByTagName('rootfile');
if(roots.length) {
var rootPath = roots[0].getAttribute("full-path");
var relPath = rootPath.split('/').slice(0, -1).join('/');
myBook.baseUrl = relPath;
fs.getXML(rootPath, function(doc) {
var items = doc.getElementsByTagName('manifest')[0].childNodes;
var spine = doc.getElementsByTagName('spine')[0].childNodes;
// create a index of all items
for(var i=0;i<items.length;i++) {
if(items[i].tagName && items[i].tagName == 'item') {
var item = items[i];
var id = item.getAttribute('id'),
url = relPath + '/' + item.getAttribute('href'),
type = item.getAttribute('media-type');
myBook.addItem(id, url, type);
}
}
// build the spine
var page = 0;
for(var i=0;i<spine.length;i++) {
if(spine[i].tagName && spine[i].tagName == 'itemref') {
myBook.setPage(page++, spine[i].getAttribute('idref'));
}
}
reader.setBook(myBook);
document.getElementById('nextPage').addEventListener('click', function(evt) {
evt.preventDefault();
reader.nextPage();
}, false);
});
} else {
console.log("no root file");
}
});
},
function()
{
console.log('ERR', arguments);
}
)
}
</script>
</body>
</html>