Merge remote-tracking branch 'epub_theme/Develop' into Develop

This commit is contained in:
Ozzie Isaacs 2024-07-07 10:22:32 +02:00
commit 60cc0c9395
2 changed files with 129 additions and 107 deletions

View File

@ -13,10 +13,9 @@ var reader;
bookmarks: calibre.bookmark ? [calibre.bookmark] : [] bookmarks: calibre.bookmark ? [calibre.bookmark] : []
}); });
reader.rendition.themes.register("lightTheme", "/static/css/epub_themes.css"); Object.keys(themes).forEach(function (theme) {
reader.rendition.themes.register("darkTheme", "/static/css/epub_themes.css"); reader.rendition.themes.register(theme, 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"));
@ -78,6 +77,10 @@ var reader;
alert(error); alert(error);
}); });
} }
// Default settings load
const theme = localStorage.getItem("calibre.reader.theme") ?? Object.keys(themes)[0];
selectTheme(theme);
})(); })();

View File

@ -1,33 +1,35 @@
<!DOCTYPE html> <!DOCTYPE html>
<html class="no-js"> <html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{_('epub Reader')}} | {{title}}</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
{% if g.google_site_verification|length > 0 %}
<meta name="google-site-verification" content="{{g.google_site_verification}}">
{% endif %}
<link rel="apple-touch-icon" sizes="140x140" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/libs/normalize.css') }}"> <head>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"> <meta charset="utf-8">
<link rel="stylesheet" href="{{ url_for('static', filename='css/popup.css') }}"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="{{ url_for('static', filename='css/reader.css') }}"> <title>{{_('epub Reader')}} | {{title}}</title>
</head> <meta name="description" content="">
<body> <meta name="viewport" content="width=device-width, user-scalable=no">
<div id="sidebar"> <meta name="apple-mobile-web-app-capable" content="yes">
{% if g.google_site_verification|length > 0 %}
<meta name="google-site-verification" content="{{g.google_site_verification}}">
{% endif %}
<link rel="apple-touch-icon" sizes="140x140" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/libs/normalize.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/reader.css') }}">
</head>
<body>
<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() }}">
<!--input id="searchBox" placeholder="search" type="search"--> <!--input id="searchBox" placeholder="search" type="search"-->
<!--a id="show-Search" class="show_view icon-search" data-view="Search">Search</a--> <!--a id="show-Search" class="show_view icon-search" data-view="Search">Search</a-->
<a id="show-Toc" class="show_view icon-list-1 active" data-view="Toc">TOC</a> <a id="show-Toc" class="show_view icon-list-1 active" data-view="Toc">TOC</a>
<a id="show-Bookmarks" class="show_view icon-bookmark" data-view="Bookmarks">Bookmarks</a> <a id="show-Bookmarks" class="show_view icon-bookmark" data-view="Bookmarks">Bookmarks</a>
<!--a id="show-Notes" class="show_view icon-edit" data-view="Notes">Notes</a--> <!--a id="show-Notes" class="show_view icon-edit" data-view="Notes">Notes</a-->
</div> </div>
<div id="tocView" class="view"> <div id="tocView" class="view">
@ -36,7 +38,7 @@
<ul id="searchResults"></ul> <ul id="searchResults"></ul>
</div--> </div-->
<div id="bookmarksView" class="view"> <div id="bookmarksView" class="view">
<ul id="bookmarks"></ul> <ul id="bookmarks"></ul>
</div> </div>
<!--div id="notesView" class="view"> <!--div id="notesView" class="view">
<div id="new-note"> <div id="new-note">
@ -45,23 +47,23 @@
</div> </div>
<ol id="notes"></ol> <ol id="notes"></ol>
</div--> </div-->
</div> </div>
<div id="main"> <div id="main">
<div id="titlebar"> <div id="titlebar">
<div id="opener"> <div id="opener">
<a id="slider" class="icon-menu">Menu</a> <a id="slider" class="icon-menu">Menu</a>
</div> </div>
<div id="metainfo"> <div id="metainfo">
<span id="book-title"></span> <span id="book-title"></span>
<span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span> <span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span id="chapter-title"></span> <span id="chapter-title"></span>
</div> </div>
<div id="title-controls"> <div id="title-controls">
<a id="bookmark" class="icon-bookmark-empty">Bookmark</a> <a id="bookmark" class="icon-bookmark-empty">Bookmark</a>
<a id="setting" class="icon-cog">Settings</a> <a id="setting" class="icon-cog">Settings</a>
<a id="fullscreen" class="icon-resize-full">Fullscreen</a> <a id="fullscreen" class="icon-resize-full">Fullscreen</a>
</div> </div>
</div> </div>
<div id="divider"></div> <div id="divider"></div>
@ -70,85 +72,102 @@
<div id="next" class="arrow"></div> <div id="next" class="arrow"></div>
<div id="loader"><img src="{{ url_for('static', filename='img/loader.gif') }}"></div> <div id="loader"><img src="{{ url_for('static', filename='img/loader.gif') }}"></div>
</div> </div>
<div class="modal md-effect-1" id="settings-modal"> <div class="modal md-effect-1" id="settings-modal">
<div class="md-content"> <div class="md-content">
<h3>{{_('Settings')}}</h3> <h3>{{_('Settings')}}</h3>
<div class="themes" id="themes"> <div class="form-group themes" id="themes">
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>
</div> <button type="button" id="sepiaTheme" class="sepiaTheme" onclick="selectTheme(this.id)"><span
<div> id="sepiaSelected"> </span>{{_('Sepia')}}</button>
<p> <button type="button" id="blackTheme" class="blackTheme" onclick="selectTheme(this.id)"><span
<input type="checkbox" id="sidebarReflow" name="sidebarReflow">{{_('Reflow text when sidebars are open.')}} id="blackSelected"> </span>{{_('Black')}}</button>
</p> </div>
</div> <div class="form-group">
<div class="fontSizeWrapper"> <p>
<input type="checkbox" id="sidebarReflow"
name="sidebarReflow">{{_('Reflow text when sidebars are open.')}}
</p>
</div>
<div class="form-group fontSizeWrapper">
<div class="slider"> <div class="slider">
<label for="fader">{{ _('Font Sizes') }}</label> <label for="fader">{{ _('Font Sizes') }}</label>
<input type="range" min="75" max="200" value="100" id="fontSizeFader" step="25"> <input type="range" min="75" max="200" value="100" id="fontSizeFader" step="25">
</div> </div>
</div> </div>
<div class="closer icon-cancel-circled"></div> <div class="closer icon-cancel-circled"></div>
</div> </div>
</div> </div>
<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 type="text/javascript"> <script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
window.calibre = { <script type="text/javascript">
filePath: "{{ url_for('static', filename='js/libs/') }}", window.calibre = {
cssPath: "{{ url_for('static', filename='css/') }}", filePath: "{{ url_for('static', filename='js/libs/') }}",
bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}", cssPath: "{{ url_for('static', filename='css/') }}",
bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}", bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}",
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}", bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}",
useBookmarks: "{{ current_user.is_authenticated | tojson }}" bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
}; useBookmarks: "{{ current_user.is_authenticated | tojson }}"
};
window.themes = {
"darkTheme": {
"bgColor": "#202124",
"css_path": "{{ url_for('static', filename='css/epub_themes.css') }}"
},
"lightTheme": {
"bgColor": "white",
"css_path": "{{ url_for('static', filename='css/epub_themes.css') }}"
},
"sepiaTheme": {
"bgColor": "#ece1ca",
"css_path": "{{ url_for('static', filename='css/epub_themes.css') }}"
},
"blackTheme": {
"bgColor": "black",
"css_path": "{{ url_for('static', filename='css/epub_themes.css') }}"
},
};
function selectTheme (id) {
var tickSpans = document.getElementById("themes").querySelectorAll("span");
function selectTheme(id) {
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 = "✓";
// Saving theme to local storage
localStorage.setItem("calibre.reader.theme", id);
// 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>