This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
86 lines (67 loc) · 2.44 KB
/
extension.js
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
/*
* @overview EPUB viewer for tagspaces
* @copyright Copyright (c) 2015 Borislav Sapundzhiev <[email protected]>
* @license Licensed under MIT license
* See https://opensource.org/licenses/MIT
*/
define(function(require, exports, module) {
"use strict";
var extensionID = "viewerEPUB"; // ID should be equal to the directory name where the ext. is located
var extensionSupportedFileTypes = ["epub"];
console.log("Loading " + extensionID);
var TSCORE = require("tscore");
var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;
var reader = require("ext/viewerEPUB/epubreader");
require([
'css!' + extensionDirectory + '/extension.css',
], function() {});
function initViewerUI(elementID, renderID) {
var $prev = $("<div class='viewerEPUBNaviButton'>‹</div>").click(reader.prevPage);
var $next = $("<div class='viewerEPUBNaviButton'>›</div>").click(reader.nextPage);
var $area = $("<div>")
.attr('id', renderID)
.addClass("flexMaxWidth")
.addClass("flexLayoutVertical")
.css({"margin": "5% auto"});
var $main = $("<div>")
.attr('id', 'viewerEPUBMain')
.addClass("flexLayout")
.css({"width": "100%"})
.append($prev)
.append($area)
.append($next);
$('#' + elementID).append($main);
}
function init(filePath, elementID) {
console.log("Initalization EPUB Viewer...");
var renderID = getRandomID("epub");
initViewerUI(elementID, renderID);
if (TSCORE.isElectron || TSCORE.isChromeExt) {
filePath = "file://" + filePath;
}
reader.loadBook(filePath, renderID);
}
function viewerMode() {
console.log("viewerMode not supported on this extension");
}
function setContent() {
console.log("setContent not supported on this extension");
}
function getContent() {
console.log("getContent not supported on this extension");
}
function getRandomID(prefix, length) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = length || 8;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return prefix ? prefix + "-" + randomstring : randomstring;
}
exports.init = init;
exports.getContent = getContent;
exports.setContent = setContent;
exports.viewerMode = viewerMode;
});