From 43fdef5e5328cd550657c8507b6b265aca602a05 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 3 Oct 2021 09:31:24 +0200 Subject: [PATCH] Improved textreader --- .../djvu_html5 => css/libs}/Djvu_html5.css | 0 cps/static/css/text.css | 44 ++++++ cps/static/js/reading/txt_reader.js | 86 +++++++++++ cps/templates/readtxt.html | 139 ++---------------- 4 files changed, 143 insertions(+), 126 deletions(-) rename cps/static/{js/libs/djvu_html5 => css/libs}/Djvu_html5.css (100%) create mode 100644 cps/static/css/text.css create mode 100644 cps/static/js/reading/txt_reader.js diff --git a/cps/static/js/libs/djvu_html5/Djvu_html5.css b/cps/static/css/libs/Djvu_html5.css similarity index 100% rename from cps/static/js/libs/djvu_html5/Djvu_html5.css rename to cps/static/css/libs/Djvu_html5.css diff --git a/cps/static/css/text.css b/cps/static/css/text.css new file mode 100644 index 00000000..74204680 --- /dev/null +++ b/cps/static/css/text.css @@ -0,0 +1,44 @@ +body { + background: white; +} + +#readmain { + position: absolute; + width: 100%; + height: 100%; +} + +#area { + width: 80%; + height: 80%; + margin: 5% auto; + max-width: 1250px; +} + +#area iframe { + border: none; +} + +xmp, pre, plaintext { + display: block; + font-family: -moz-fixed; + white-space: pre; + margin: 1em 0; +} + +#area{ + overflow:hidden; +} + +pre { + white-space: pre-wrap; + word-wrap: break-word; + font-family: -moz-fixed; + column-count:2; + -webkit-columns:2; + -moz-columns:2; + column-gap:20px; + -moz-column-gap:20px; + -webkit-column-gap:20px; + position:relative; +} diff --git a/cps/static/js/reading/txt_reader.js b/cps/static/js/reading/txt_reader.js new file mode 100644 index 00000000..9cfb51f5 --- /dev/null +++ b/cps/static/js/reading/txt_reader.js @@ -0,0 +1,86 @@ +/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) + * Copyright (C) 2021 Ozzieisaacs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +$(document).ready(function() { + //to int + $("#area").width($("#area").width()); + $("#content").width($("#content").width()); + //bind text + $("#content").load($("#readmain").data('load'), function(textStr) { + $(this).height($(this).parent().height()*0.95); + $(this).text(textStr); + }); + //keybind + $(document).keydown(function(event){ + if(event.keyCode == 37){ + prevPage(); + } + if(event.keyCode == 39){ + nextPage(); + } + }); + //click + $( "#left" ).click(function() { + prevPage(); + }); + $( "#right" ).click(function() { + nextPage(); + }); + $("#readmain").swipe( { + swipeRight:function() { + prevPage(); + }, + swipeLeft:function() { + nextPage(); + }, + }); + + //bind mouse + $(window).bind('DOMMouseScroll mousewheel', function(event) { + var delta = 0; + if (event.originalEvent.wheelDelta) { + delta = event.originalEvent.wheelDelta; + } else if (event.originalEvent.detail) { + delta = event.originalEvent.detail*-1; + } + if (delta >= 0) { + prevPage(); + } else { + nextPage(); + } + }); + + //page animate + var origwidth = $("#content")[0].getBoundingClientRect().width; + var gap = 20; + function prevPage() { + if($("#content").offset().left > 0) { + return; + } + leftoff = $("#content").offset().left; + leftoff = leftoff+origwidth+gap; + $("#content").offset({left:leftoff}); + } + function nextPage() { + leftoff = $("#content").offset().left; + leftoff = leftoff-origwidth-gap; + if (leftoff + $("#content")[0].scrollWidth < 0) { + return; + } + $("#content").offset({left:leftoff}); + } +}); diff --git a/cps/templates/readtxt.html b/cps/templates/readtxt.html index ea294948..b157fe95 100644 --- a/cps/templates/readtxt.html +++ b/cps/templates/readtxt.html @@ -5,139 +5,26 @@ {{_('txt Reader')}} | {{title}} - + - + + + + + - - - - - - + -
-
-
- -
- - +
+
+
+ +