mirror of
https://github.com/janeczku/calibre-web
synced 2024-09-29 23:40:47 +00:00
Fixed theme related todos
This commit is contained in:
parent
3aa75ef4a7
commit
bca9d80290
@ -1,8 +1,8 @@
|
|||||||
/* global $, calibre, EPUBJS, ePubReader */
|
/* global $, calibre, EPUBJS, ePubReader */
|
||||||
|
|
||||||
var reader;
|
let reader;
|
||||||
|
|
||||||
(function() {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
EPUBJS.filePath = calibre.filePath;
|
EPUBJS.filePath = calibre.filePath;
|
||||||
@ -10,13 +10,12 @@ var reader;
|
|||||||
|
|
||||||
reader = ePubReader(calibre.bookUrl, {
|
reader = ePubReader(calibre.bookUrl, {
|
||||||
restore: true,
|
restore: true,
|
||||||
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
|
bookmarks: calibre.bookmark ? [calibre.bookmark] : [],
|
||||||
});
|
});
|
||||||
|
|
||||||
reader.rendition.themes.register("lightTheme", "/static/css/epub_themes.css");
|
Object.keys(window.themes).forEach(function (theme) {
|
||||||
reader.rendition.themes.register("darkTheme", "/static/css/epub_themes.css");
|
reader.rendition.themes.register(theme, window.themes[theme].css_path);
|
||||||
reader.rendition.themes.register("sepiaTheme", "/static/css/epub_themes.css");
|
});
|
||||||
reader.rendition.themes.register("blackTheme", "/static/css/epub_themes.css");
|
|
||||||
|
|
||||||
if (calibre.useBookmarks) {
|
if (calibre.useBookmarks) {
|
||||||
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
|
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
|
||||||
@ -27,16 +26,16 @@ var reader;
|
|||||||
|
|
||||||
// Enable swipe support
|
// Enable swipe support
|
||||||
// I have no idea why swiperRight/swiperLeft from plugins is not working, events just don't get fired
|
// I have no idea why swiperRight/swiperLeft from plugins is not working, events just don't get fired
|
||||||
var touchStart = 0;
|
let touchStart = 0;
|
||||||
var touchEnd = 0;
|
let touchEnd = 0;
|
||||||
|
|
||||||
reader.rendition.on('touchstart', function(event) {
|
reader.rendition.on("touchstart", function (event) {
|
||||||
touchStart = event.changedTouches[0].screenX;
|
touchStart = event.changedTouches[0].screenX;
|
||||||
});
|
});
|
||||||
reader.rendition.on('touchend', function(event) {
|
reader.rendition.on("touchend", function (event) {
|
||||||
touchEnd = event.changedTouches[0].screenX;
|
touchEnd = event.changedTouches[0].screenX;
|
||||||
if (touchStart < touchEnd) {
|
if (touchStart < touchEnd) {
|
||||||
if(reader.book.package.metadata.direction === "rtl") {
|
if (reader.book.package.metadata.direction === "rtl") {
|
||||||
reader.rendition.next();
|
reader.rendition.next();
|
||||||
} else {
|
} else {
|
||||||
reader.rendition.prev();
|
reader.rendition.prev();
|
||||||
@ -44,7 +43,7 @@ var reader;
|
|||||||
// Swiped Right
|
// Swiped Right
|
||||||
}
|
}
|
||||||
if (touchStart > touchEnd) {
|
if (touchStart > touchEnd) {
|
||||||
if(reader.book.package.metadata.direction === "rtl") {
|
if (reader.book.package.metadata.direction === "rtl") {
|
||||||
reader.rendition.prev();
|
reader.rendition.prev();
|
||||||
} else {
|
} else {
|
||||||
reader.rendition.next();
|
reader.rendition.next();
|
||||||
@ -60,24 +59,26 @@ var reader;
|
|||||||
function updateBookmark(action, location) {
|
function updateBookmark(action, location) {
|
||||||
// Remove other bookmarks (there can only be one)
|
// Remove other bookmarks (there can only be one)
|
||||||
if (action === "add") {
|
if (action === "add") {
|
||||||
this.settings.bookmarks.filter(function (bookmark) {
|
this.settings.bookmarks
|
||||||
|
.filter(function (bookmark) {
|
||||||
return bookmark && bookmark !== location;
|
return bookmark && bookmark !== location;
|
||||||
}).map(function (bookmark) {
|
})
|
||||||
|
.map(
|
||||||
|
function (bookmark) {
|
||||||
this.removeBookmark(bookmark);
|
this.removeBookmark(bookmark);
|
||||||
}.bind(this));
|
}.bind(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var csrftoken = $("input[name='csrf_token']").val();
|
const csrftoken = $("input[name='csrf_token']").val();
|
||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
$.ajax(calibre.bookmarkUrl, {
|
$.ajax(calibre.bookmarkUrl, {
|
||||||
method: "post",
|
method: "post",
|
||||||
data: { bookmark: location || "" },
|
data: { bookmark: location || "" },
|
||||||
headers: { "X-CSRFToken": csrftoken }
|
headers: { "X-CSRFToken": csrftoken },
|
||||||
}).fail(function (xhr, status, error) {
|
}).fail(function (xhr, status, error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="no-js">
|
<html class="no-js">
|
||||||
<head>
|
|
||||||
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
<title>{{_('epub Reader')}} | {{title}}</title>
|
<title>{{_('epub Reader')}} | {{title}}</title>
|
||||||
@ -17,8 +18,9 @@
|
|||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/popup.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/popup.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/reader.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/reader.css') }}">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
|
||||||
|
<body>
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
<div id="panels">
|
<div id="panels">
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
@ -78,14 +80,19 @@
|
|||||||
Choose a theme below: <br />
|
Choose a theme below: <br />
|
||||||
|
|
||||||
<!-- Hardcoded a tick in the light theme button because it is the "default" theme. Need to find a way to do this dynamically on startup-->
|
<!-- Hardcoded a tick in the light theme button because it is the "default" theme. Need to find a way to do this dynamically on startup-->
|
||||||
<button type="button" id="lightTheme" class="lightTheme" onclick="selectTheme(this.id)"><span id="lightSelected">✓</span>{{_('Light')}}</button>
|
<button type="button" id="lightTheme" class="lightTheme" onclick="selectTheme(this.id)"><span
|
||||||
<button type="button" id="darkTheme" class="darkTheme" onclick="selectTheme(this.id)"><span id="darkSelected"> </span>{{_('Dark')}}</button>
|
id="lightSelected">✓</span>{{_('Light')}}</button>
|
||||||
<button type="button" id="sepiaTheme" class="sepiaTheme" onclick="selectTheme(this.id)"><span id="sepiaSelected"> </span>{{_('Sepia')}}</button>
|
<button type="button" id="darkTheme" class="darkTheme" onclick="selectTheme(this.id)"><span
|
||||||
<button type="button" id="blackTheme" class="blackTheme" onclick="selectTheme(this.id)"><span id="blackSelected"> </span>{{_('Black')}}</button>
|
id="darkSelected"> </span>{{_('Dark')}}</button>
|
||||||
|
<button type="button" id="sepiaTheme" class="sepiaTheme" onclick="selectTheme(this.id)"><span
|
||||||
|
id="sepiaSelected"> </span>{{_('Sepia')}}</button>
|
||||||
|
<button type="button" id="blackTheme" class="blackTheme" onclick="selectTheme(this.id)"><span
|
||||||
|
id="blackSelected"> </span>{{_('Black')}}</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
<input type="checkbox" id="sidebarReflow" name="sidebarReflow">{{_('Reflow text when sidebars are open.')}}
|
<input type="checkbox" id="sidebarReflow"
|
||||||
|
name="sidebarReflow">{{_('Reflow text when sidebars are open.')}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="fontSizeWrapper">
|
<div class="fontSizeWrapper">
|
||||||
@ -100,7 +107,8 @@
|
|||||||
<div class="overlay"></div>
|
<div class="overlay"></div>
|
||||||
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/compress/jszip_epub.min.js') }}">
|
<script src="{{ url_for('static', filename='js/compress/jszip_epub.min.js') }}">
|
||||||
</script> <script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
</script>
|
||||||
|
<script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.calibre = {
|
window.calibre = {
|
||||||
filePath: "{{ url_for('static', filename='js/libs/') }}",
|
filePath: "{{ url_for('static', filename='js/libs/') }}",
|
||||||
@ -108,16 +116,35 @@
|
|||||||
bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}",
|
bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}",
|
||||||
bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}",
|
bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}",
|
||||||
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
||||||
useBookmarks: "{{ current_user.is_authenticated | tojson }}"
|
useBookmarks: "{{ current_user.is_authenticated | tojson }}",
|
||||||
};
|
};
|
||||||
|
|
||||||
function selectTheme(id) {
|
window.themes = {
|
||||||
tickSpans = document.getElementById("themes").querySelectorAll("span");
|
"darkTheme": {
|
||||||
|
"bgColor": "#202124",
|
||||||
|
"css_path": "/static/css/epub_themes.css"
|
||||||
|
},
|
||||||
|
"lightTheme": {
|
||||||
|
"bgColor": "white",
|
||||||
|
"css_path": "/static/css/epub_themes.css"
|
||||||
|
},
|
||||||
|
"sepiaTheme": {
|
||||||
|
"bgColor": "#ece1ca",
|
||||||
|
"css_path": "/static/css/epub_themes.css"
|
||||||
|
},
|
||||||
|
"blackTheme": {
|
||||||
|
"bgColor": "black",
|
||||||
|
"css_path": "/static/css/epub_themes.css"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function selectTheme (id) {
|
||||||
|
const tickSpans = document.getElementById("themes").querySelectorAll("span");
|
||||||
|
|
||||||
// Remove tick mark from all theme buttons
|
// Remove tick mark from all theme buttons
|
||||||
for(var i = 0; i < tickSpans.length; i++) {
|
tickSpans.forEach(function (tickSpan) {
|
||||||
document.getElementById(tickSpans[i].id).textContent = "";
|
document.getElementById(tickSpan.id).textContent = "";
|
||||||
}
|
});
|
||||||
|
|
||||||
// Add tick mark to the button corresponding to the currently selected theme
|
// Add tick mark to the button corresponding to the currently selected theme
|
||||||
document.getElementById(id).querySelector("span").textContent = "✓";
|
document.getElementById(id).querySelector("span").textContent = "✓";
|
||||||
@ -125,30 +152,19 @@
|
|||||||
// Apply theme to epubjs iframe
|
// Apply theme to epubjs iframe
|
||||||
reader.rendition.themes.select(id);
|
reader.rendition.themes.select(id);
|
||||||
|
|
||||||
// Apply theme to rest of the page. TODO - Do this smarter
|
// Apply theme to rest of the page.
|
||||||
if (id == "darkTheme") {
|
document.getElementById("main").style.backgroundColor = themes[id]["bgColor"];
|
||||||
document.getElementById("main").style.backgroundColor = "#202124";
|
|
||||||
}
|
|
||||||
else if (id == "lightTheme") {
|
|
||||||
document.getElementById("main").style.backgroundColor = "white";
|
|
||||||
}
|
|
||||||
else if (id == "sepiaTheme") {
|
|
||||||
document.getElementById("main").style.backgroundColor = "#ece1ca";
|
|
||||||
}
|
|
||||||
else if (id == "blackTheme") {
|
|
||||||
document.getElementById("main").style.backgroundColor = "black";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// font size settings logic
|
// font size settings logic
|
||||||
let fontSizeFader = document.getElementById('fontSizeFader');
|
let fontSizeFader = document.getElementById('fontSizeFader');
|
||||||
fontSizeFader.addEventListener ("change", function () {
|
fontSizeFader.addEventListener("change", function () {
|
||||||
reader.rendition.themes.fontSize(`${this.value}%`)
|
reader.rendition.themes.fontSize(`${this.value}%`);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/reader.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/reader.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/reading/epub.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/reading/epub.js') }}"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user