Reader.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <template>
  2. <el-container>
  3. <el-header v-show="toolBarActive" height='50px'>
  4. <div class="header">
  5. <el-tooltip content="Загрузить книгу" :open-delay="1000" effect="light">
  6. <el-button ref="loader" class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')"><i class="el-icon-back"></i></el-button>
  7. </el-tooltip>
  8. <div>
  9. <el-tooltip content="Действие назад" :open-delay="1000" effect="light">
  10. <el-button ref="undoAction" class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')" ><i class="el-icon-arrow-left"></i></el-button>
  11. </el-tooltip>
  12. <el-tooltip content="Действие вперед" :open-delay="1000" effect="light">
  13. <el-button ref="redoAction" class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')" ><i class="el-icon-arrow-right"></i></el-button>
  14. </el-tooltip>
  15. <div class="space"></div>
  16. <el-tooltip content="На весь экран" :open-delay="1000" effect="light">
  17. <el-button ref="fullScreen" class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')"><i class="el-icon-rank"></i></el-button>
  18. </el-tooltip>
  19. <el-tooltip content="Плавный скроллинг" :open-delay="1000" effect="light">
  20. <el-button ref="scrolling" class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')"><i class="el-icon-sort"></i></el-button>
  21. </el-tooltip>
  22. <el-tooltip content="Прокрутка книги" :open-delay="1000" effect="light">
  23. <el-button ref="setPosition" class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')"><i class="el-icon-d-arrow-right"></i></el-button>
  24. </el-tooltip>
  25. <el-tooltip content="Найти в тексте" :open-delay="1000" effect="light">
  26. <el-button ref="search" class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')"><i class="el-icon-search"></i></el-button>
  27. </el-tooltip>
  28. <el-tooltip content="Скопировать текст со страницы" :open-delay="1000" effect="light">
  29. <el-button ref="copyText" class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')"><i class="el-icon-edit-outline"></i></el-button>
  30. </el-tooltip>
  31. <el-tooltip content="Принудительно обновить книгу в обход кеша" :open-delay="1000" effect="light">
  32. <el-button ref="refresh" class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')">
  33. <i class="el-icon-refresh" :class="{clear: !showRefreshIcon}"></i>
  34. </el-button>
  35. </el-tooltip>
  36. <div class="space"></div>
  37. <el-tooltip content="Открыть недавние" :open-delay="1000" effect="light">
  38. <el-button ref="history" class="tool-button" :class="buttonActiveClass('history')" @click="buttonClick('history')"><i class="el-icon-document"></i></el-button>
  39. </el-tooltip>
  40. </div>
  41. <el-tooltip content="Настроить" :open-delay="1000" effect="light">
  42. <el-button ref="settings" class="tool-button" :class="buttonActiveClass('settings')" @click="buttonClick('settings')"><i class="el-icon-setting"></i></el-button>
  43. </el-tooltip>
  44. </div>
  45. </el-header>
  46. <el-main>
  47. <keep-alive>
  48. <component ref="page" :is="activePage"
  49. @load-book="loadBook"
  50. @book-pos-changed="bookPosChanged"
  51. @tool-bar-toggle="toolBarToggle"
  52. @full-screen-toogle="fullScreenToggle"
  53. @stop-scrolling="stopScrolling"
  54. @scrolling-toggle="scrollingToggle"
  55. ></component>
  56. </keep-alive>
  57. <SetPositionPage v-if="setPositionActive" ref="setPositionPage" @set-position-toggle="setPositionToggle" @book-pos-changed="bookPosChanged"></SetPositionPage>
  58. <SearchPage v-show="searchActive" ref="searchPage"
  59. @search-toggle="searchToggle"
  60. @book-pos-changed="bookPosChanged"
  61. @start-text-search="startTextSearch"
  62. @stop-text-search="stopTextSearch">
  63. </SearchPage>
  64. <CopyTextPage v-if="copyTextActive" ref="copyTextPage" @copy-text-toggle="copyTextToggle"></CopyTextPage>
  65. <HistoryPage v-if="historyActive" ref="historyPage" @load-book="loadBook" @history-toggle="historyToggle"></HistoryPage>
  66. <SettingsPage v-if="settingsActive" ref="settingsPage" @settings-toggle="settingsToggle"></SettingsPage>
  67. </el-main>
  68. </el-container>
  69. </template>
  70. <script>
  71. //-----------------------------------------------------------------------------
  72. import Vue from 'vue';
  73. import Component from 'vue-class-component';
  74. import LoaderPage from './LoaderPage/LoaderPage.vue';
  75. import TextPage from './TextPage/TextPage.vue';
  76. import ProgressPage from './ProgressPage/ProgressPage.vue';
  77. import SetPositionPage from './SetPositionPage/SetPositionPage.vue';
  78. import SearchPage from './SearchPage/SearchPage.vue';
  79. import CopyTextPage from './CopyTextPage/CopyTextPage.vue';
  80. import HistoryPage from './HistoryPage/HistoryPage.vue';
  81. import SettingsPage from './SettingsPage/SettingsPage.vue';
  82. import bookManager from './share/bookManager';
  83. import readerApi from '../../api/reader';
  84. import _ from 'lodash';
  85. import {sleep} from '../../share/utils';
  86. export default @Component({
  87. components: {
  88. LoaderPage,
  89. TextPage,
  90. ProgressPage,
  91. SetPositionPage,
  92. SearchPage,
  93. CopyTextPage,
  94. HistoryPage,
  95. SettingsPage,
  96. },
  97. watch: {
  98. bookPos: function(newValue) {
  99. if (newValue !== undefined && this.activePage == 'TextPage') {
  100. const textPage = this.$refs.page;
  101. if (textPage.bookPos != newValue) {
  102. textPage.bookPos = newValue;
  103. }
  104. this.debouncedSetRecentBook(newValue);
  105. }
  106. },
  107. routeParamPos: function(newValue) {
  108. if (newValue !== undefined && newValue != this.bookPos) {
  109. this.bookPos = newValue;
  110. }
  111. },
  112. routeParamUrl: function(newValue) {
  113. if (newValue !== '' && newValue !== this.mostRecentBook().url) {
  114. this.loadBook({url: newValue, bookPos: this.routeParamPos});
  115. }
  116. },
  117. settings: function(newValue) {
  118. this.allowUrlParamBookPos = newValue.allowUrlParamBookPos;
  119. this.copyFullText = newValue.copyFullText;
  120. this.updateRoute();
  121. },
  122. },
  123. })
  124. class Reader extends Vue {
  125. loaderActive = false;
  126. progressActive = false;
  127. fullScreenActive = false;
  128. scrollingActive = false;
  129. setPositionActive = false;
  130. searchActive = false;
  131. copyTextActive = false;
  132. historyActive = false;
  133. settingsActive = false;
  134. bookPos = null;
  135. allowUrlParamBookPos = false;
  136. showRefreshIcon = true;
  137. mostRecentBookReactive = null;
  138. actionList = [];
  139. actionCur = -1;
  140. created() {
  141. this.loading = true;
  142. this.commit = this.$store.commit;
  143. this.dispatch = this.$store.dispatch;
  144. this.reader = this.$store.state.reader;
  145. this.$root.addKeyHook(this.keyHook);
  146. this.lastActivePage = false;
  147. this.debouncedUpdateRoute = _.debounce(() => {
  148. this.updateRoute();
  149. }, 1000);
  150. this.debouncedSetRecentBook = _.debounce(async(newValue) => {
  151. const recent = this.mostRecentBook();
  152. if (recent && recent.bookPos != newValue) {
  153. await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
  154. if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
  155. this.addAction(newValue);
  156. }
  157. }, 500);
  158. document.addEventListener('fullscreenchange', () => {
  159. this.fullScreenActive = (document.fullscreenElement !== null);
  160. });
  161. this.allowUrlParamBookPos = this.settings.allowUrlParamBookPos;
  162. this.copyFullText = this.settings.copyFullText;
  163. }
  164. mounted() {
  165. (async() => {
  166. await bookManager.init();
  167. if (this.$root.rootRoute == '/reader') {
  168. if (this.routeParamUrl) {
  169. this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos});
  170. } else if (this.mostRecentBook()) {
  171. this.loadBook({url: this.mostRecentBook().url});
  172. } else {
  173. this.loaderActive = true;
  174. }
  175. }
  176. this.loading = false;
  177. })();
  178. }
  179. get routeParamPos() {
  180. let result = undefined;
  181. const q = this.$route.query;
  182. if (q['__p']) {
  183. result = q['__p'];
  184. if (Array.isArray(result))
  185. result = result[0];
  186. }
  187. return (result ? parseInt(result, 10) || 0 : result);
  188. }
  189. updateRoute(isNewRoute) {
  190. const recent = this.mostRecentBook();
  191. const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
  192. const url = (recent ? `url=${recent.url}` : '');
  193. if (isNewRoute)
  194. this.$router.push(`/reader?${pos}${url}`);
  195. else
  196. this.$router.replace(`/reader?${pos}${url}`);
  197. }
  198. get routeParamUrl() {
  199. let result = '';
  200. const path = this.$route.fullPath;
  201. const i = path.indexOf('url=');
  202. if (i >= 0) {
  203. result = path.substr(i + 4);
  204. }
  205. return decodeURIComponent(result);
  206. }
  207. bookPosChanged(event) {
  208. if (event.bookPosSeen !== undefined)
  209. this.bookPosSeen = event.bookPosSeen;
  210. this.bookPos = event.bookPos;
  211. this.debouncedUpdateRoute();
  212. }
  213. get toolBarActive() {
  214. return this.reader.toolBarActive;
  215. }
  216. mostRecentBook() {
  217. const result = bookManager.mostRecentBook();
  218. this.mostRecentBookReactive = result;
  219. return result;
  220. }
  221. get settings() {
  222. return this.$store.state.reader.settings;
  223. }
  224. addAction(pos) {
  225. let a = this.actionList;
  226. if (!a.length || a[a.length - 1] != pos) {
  227. a.push(pos);
  228. if (a.length > 20)
  229. a.shift();
  230. this.actionCur = a.length - 1;
  231. }
  232. }
  233. toolBarToggle() {
  234. this.commit('reader/setToolBarActive', !this.toolBarActive);
  235. this.$root.$emit('resize');
  236. }
  237. fullScreenToggle() {
  238. this.fullScreenActive = !this.fullScreenActive;
  239. if (this.fullScreenActive) {
  240. const element = document.documentElement;
  241. if (element.requestFullscreen) {
  242. element.requestFullscreen();
  243. } else if (element.webkitrequestFullscreen) {
  244. element.webkitRequestFullscreen();
  245. } else if (element.mozRequestFullscreen) {
  246. element.mozRequestFullScreen();
  247. }
  248. } else {
  249. if (document.cancelFullScreen) {
  250. document.cancelFullScreen();
  251. } else if (document.mozCancelFullScreen) {
  252. document.mozCancelFullScreen();
  253. } else if (document.webkitCancelFullScreen) {
  254. document.webkitCancelFullScreen();
  255. }
  256. }
  257. }
  258. closeAllTextPages() {
  259. this.setPositionActive = false;
  260. this.copyTextActive = false;
  261. this.historyActive = false;
  262. this.settingsActive = false;
  263. this.stopScrolling();
  264. this.stopSearch();
  265. }
  266. loaderToggle() {
  267. this.loaderActive = !this.loaderActive;
  268. if (this.loaderActive) {
  269. this.closeAllTextPages();
  270. }
  271. }
  272. setPositionToggle() {
  273. this.setPositionActive = !this.setPositionActive;
  274. if (this.setPositionActive && this.activePage == 'TextPage' && this.mostRecentBook()) {
  275. this.closeAllTextPages();
  276. this.setPositionActive = true;
  277. this.$nextTick(() => {
  278. this.$refs.setPositionPage.sliderMax = this.mostRecentBook().textLength - 1;
  279. this.$refs.setPositionPage.sliderValue = this.mostRecentBook().bookPos;
  280. });
  281. } else {
  282. this.setPositionActive = false;
  283. }
  284. }
  285. stopScrolling() {
  286. if (this.scrollingActive)
  287. this.scrollingToggle();
  288. }
  289. scrollingToggle() {
  290. this.scrollingActive = !this.scrollingActive;
  291. if (this.activePage == 'TextPage') {
  292. const page = this.$refs.page;
  293. if (this.scrollingActive) {
  294. page.startTextScrolling();
  295. } else {
  296. page.stopTextScrolling();
  297. }
  298. }
  299. }
  300. stopSearch() {
  301. if (this.searchActive)
  302. this.searchToggle();
  303. }
  304. startTextSearch(opts) {
  305. if (this.activePage == 'TextPage')
  306. this.$refs.page.startSearch(opts.needle);
  307. }
  308. stopTextSearch() {
  309. if (this.activePage == 'TextPage')
  310. this.$refs.page.stopSearch();
  311. }
  312. searchToggle() {
  313. this.searchActive = !this.searchActive;
  314. const page = this.$refs.page;
  315. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  316. this.closeAllTextPages();
  317. this.searchActive = true;
  318. this.$nextTick(() => {
  319. this.$refs.searchPage.init(page.parsed);
  320. });
  321. } else {
  322. this.stopTextSearch();
  323. this.searchActive = false;
  324. }
  325. }
  326. copyTextToggle() {
  327. this.copyTextActive = !this.copyTextActive;
  328. const page = this.$refs.page;
  329. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  330. this.closeAllTextPages();
  331. this.copyTextActive = true;
  332. this.$nextTick(() => {
  333. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  334. });
  335. } else {
  336. this.copyTextActive = false;
  337. }
  338. }
  339. historyToggle() {
  340. this.historyActive = !this.historyActive;
  341. if (this.historyActive) {
  342. this.closeAllTextPages();
  343. this.historyActive = true;
  344. } else {
  345. this.historyActive = false;
  346. }
  347. }
  348. settingsToggle() {
  349. this.settingsActive = !this.settingsActive;
  350. if (this.settingsActive) {
  351. this.closeAllTextPages();
  352. this.settingsActive = true;
  353. } else {
  354. this.settingsActive = false;
  355. }
  356. }
  357. buttonClick(button) {
  358. switch (button) {
  359. case 'loader':
  360. this.loaderToggle();
  361. break;
  362. case 'undoAction':
  363. if (this.actionCur > 0) {
  364. this.actionCur--;
  365. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  366. }
  367. break;
  368. case 'redoAction':
  369. if (this.actionCur < this.actionList.length - 1) {
  370. this.actionCur++;
  371. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  372. }
  373. break;
  374. case 'fullScreen':
  375. this.fullScreenToggle();
  376. break;
  377. case 'setPosition':
  378. this.setPositionToggle();
  379. break;
  380. case 'scrolling':
  381. this.scrollingToggle();
  382. break;
  383. case 'search':
  384. this.searchToggle();
  385. break;
  386. case 'copyText':
  387. this.copyTextToggle();
  388. break;
  389. case 'history':
  390. this.historyToggle();
  391. break;
  392. case 'refresh':
  393. if (this.mostRecentBook()) {
  394. this.loadBook({url: this.mostRecentBook().url, force: true});
  395. }
  396. break;
  397. case 'settings':
  398. this.settingsToggle();
  399. break;
  400. }
  401. this.$refs[button].$el.blur();
  402. }
  403. buttonActiveClass(button) {
  404. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  405. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  406. let classResult = {};
  407. switch (button) {
  408. case 'loader':
  409. case 'fullScreen':
  410. case 'setPosition':
  411. case 'scrolling':
  412. case 'search':
  413. case 'copyText':
  414. case 'history':
  415. case 'settings':
  416. if (this[`${button}Active`])
  417. classResult = classActive;
  418. break;
  419. }
  420. switch (button) {
  421. case 'undoAction':
  422. if (this.actionCur <= 0)
  423. classResult = classDisabled;
  424. break;
  425. case 'redoAction':
  426. if (this.actionCur == this.actionList.length - 1)
  427. classResult = classDisabled;
  428. break;
  429. }
  430. if (this.activePage == 'LoaderPage' || !this.mostRecentBook()) {
  431. switch (button) {
  432. case 'undoAction':
  433. case 'redoAction':
  434. case 'setPosition':
  435. case 'scrolling':
  436. case 'search':
  437. case 'copyText':
  438. classResult = classDisabled;
  439. break;
  440. case 'history':
  441. case 'refresh':
  442. if (!this.mostRecentBook())
  443. classResult = classDisabled;
  444. break;
  445. }
  446. }
  447. return classResult;
  448. }
  449. get activePage() {
  450. let result = '';
  451. if (this.progressActive)
  452. result = 'ProgressPage';
  453. else if (this.loaderActive)
  454. result = 'LoaderPage';
  455. else if (this.mostRecentBookReactive)
  456. result = 'TextPage';
  457. if (!result && !this.loading) {
  458. this.loaderActive = true;
  459. result = 'LoaderPage';
  460. }
  461. if (result != 'TextPage') {
  462. this.$root.$emit('set-app-title');
  463. }
  464. if (this.lastActivePage != result && result == 'TextPage') {
  465. //акивируем страницу с текстом
  466. this.$nextTick(async() => {
  467. const last = this.mostRecentBookReactive;
  468. const isParsed = bookManager.hasBookParsed(last);
  469. if (!isParsed) {
  470. this.$root.$emit('set-app-title');
  471. return;
  472. }
  473. this.updateRoute();
  474. const textPage = this.$refs.page;
  475. if (textPage.showBook) {
  476. textPage.lastBook = last;
  477. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  478. textPage.showBook();
  479. }
  480. });
  481. }
  482. this.lastActivePage = result;
  483. return result;
  484. }
  485. loadBook(opts) {
  486. if (!opts) {
  487. this.mostRecentBook();
  488. return;
  489. }
  490. // уже просматривается сейчас
  491. const recent = this.mostRecentBook();
  492. if (!opts.force && recent && recent.url == opts.url && bookManager.hasBookParsed(recent)) {
  493. this.loaderActive = false;
  494. return;
  495. }
  496. this.progressActive = true;
  497. this.$nextTick(async() => {
  498. const progress = this.$refs.page;
  499. this.actionList = [];
  500. this.actionCur = -1;
  501. try {
  502. progress.show();
  503. progress.setState({state: 'parse'});
  504. // есть ли среди недавних
  505. const key = bookManager.keyFromUrl(opts.url);
  506. let wasOpened = await bookManager.getRecentBook({key});
  507. wasOpened = (wasOpened ? wasOpened : {});
  508. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  509. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  510. let book = null;
  511. if (!opts.force) {
  512. // пытаемся загрузить и распарсить книгу в менеджере из локального кеша
  513. const bookParsed = await bookManager.getBook({url: opts.url}, (prog) => {
  514. progress.setState({progress: prog});
  515. });
  516. // если есть в локальном кеше
  517. if (bookParsed) {
  518. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookManager.metaOnly(bookParsed)));
  519. this.mostRecentBook();
  520. this.addAction(bookPos);
  521. this.loaderActive = false;
  522. progress.hide(); this.progressActive = false;
  523. this.blinkCachedLoadMessage();
  524. return;
  525. }
  526. // иначе идем на сервер
  527. // пытаемся загрузить готовый файл с сервера
  528. if (wasOpened.path) {
  529. try {
  530. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  531. progress.setState(state);
  532. });
  533. book = Object.assign({}, wasOpened, {data: resp.data});
  534. } catch (e) {
  535. //молчим
  536. }
  537. }
  538. }
  539. progress.setState({totalSteps: 5});
  540. // не удалось, скачиваем книгу полностью с конвертацией
  541. let loadCached = true;
  542. if (!book) {
  543. book = await readerApi.loadBook(opts.url, (state) => {
  544. progress.setState(state);
  545. });
  546. loadCached = false;
  547. }
  548. // добавляем в bookManager
  549. progress.setState({state: 'parse', step: 5});
  550. const addedBook = await bookManager.addBook(book, (prog) => {
  551. progress.setState({progress: prog});
  552. });
  553. // добавляем в историю
  554. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookManager.metaOnly(addedBook)));
  555. this.mostRecentBook();
  556. this.addAction(bookPos);
  557. this.updateRoute(true);
  558. this.loaderActive = false;
  559. progress.hide(); this.progressActive = false;
  560. if (loadCached) {
  561. this.blinkCachedLoadMessage();
  562. } else
  563. this.stopBlink = true;
  564. } catch (e) {
  565. progress.hide(); this.progressActive = false;
  566. this.loaderActive = true;
  567. this.$alert(e.message, 'Ошибка', {type: 'error'});
  568. }
  569. });
  570. }
  571. blinkCachedLoadMessage() {
  572. this.blinkCount = 30;
  573. if (!this.inBlink) {
  574. this.inBlink = true;
  575. this.stopBlink = false;
  576. this.$nextTick(async() => {
  577. let page = this.$refs.page;
  578. while (this.blinkCount) {
  579. this.showRefreshIcon = !this.showRefreshIcon;
  580. if (page.blinkCachedLoadMessage)
  581. page.blinkCachedLoadMessage(this.showRefreshIcon);
  582. await sleep(500);
  583. if (this.stopBlink)
  584. break;
  585. this.blinkCount--;
  586. page = this.$refs.page;
  587. }
  588. this.showRefreshIcon = true;
  589. this.inBlink = false;
  590. if (page.blinkCachedLoadMessage)
  591. page.blinkCachedLoadMessage('finish');
  592. });
  593. }
  594. }
  595. keyHook(event) {
  596. if (this.$root.rootRoute == '/reader') {
  597. let handled = false;
  598. if (!handled && this.settingsActive)
  599. handled = this.$refs.settingsPage.keyHook(event);
  600. if (!handled && this.historyActive)
  601. handled = this.$refs.historyPage.keyHook(event);
  602. if (!handled && this.setPositionActive)
  603. handled = this.$refs.setPositionPage.keyHook(event);
  604. if (!handled && this.searchActive)
  605. handled = this.$refs.searchPage.keyHook(event);
  606. if (!handled && this.copyTextActive)
  607. handled = this.$refs.copyTextPage.keyHook(event);
  608. if (!handled && this.$refs.page && this.$refs.page.keyHook)
  609. handled = this.$refs.page.keyHook(event);
  610. if (!handled && event.type == 'keydown') {
  611. if (event.code == 'Escape')
  612. this.loaderToggle();
  613. if (this.activePage == 'TextPage') {
  614. switch (event.code) {
  615. case 'KeyP':
  616. this.setPositionToggle();
  617. break;
  618. case 'KeyF':
  619. if (event.ctrlKey) {
  620. this.searchToggle();
  621. event.preventDefault();
  622. event.stopPropagation();
  623. }
  624. break;
  625. case 'KeyC':
  626. if (event.ctrlKey) {
  627. this.copyTextToggle();
  628. event.preventDefault();
  629. event.stopPropagation();
  630. }
  631. break;
  632. case 'KeyZ':
  633. this.scrollingToggle();
  634. break;
  635. case 'KeyH':
  636. this.historyToggle();
  637. break;
  638. case 'KeyS':
  639. this.settingsToggle();
  640. break;
  641. }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. //-----------------------------------------------------------------------------
  648. </script>
  649. <style scoped>
  650. .el-container {
  651. padding: 0;
  652. margin: 0;
  653. height: 100%;
  654. }
  655. .el-header {
  656. padding-left: 5px;
  657. padding-right: 5px;
  658. background-color: #1B695F;
  659. color: #000;
  660. overflow-x: auto;
  661. overflow-y: hidden;
  662. }
  663. .header {
  664. display: flex;
  665. justify-content: space-between;
  666. min-width: 550px;
  667. }
  668. .el-main {
  669. position: relative;
  670. display: flex;
  671. padding: 0;
  672. margin: 0;
  673. background-color: #EBE2C9;
  674. color: #000;
  675. }
  676. .tool-button {
  677. margin: 0 2px 0 2px;
  678. padding: 0;
  679. color: #3E843E;
  680. background-color: #E6EDF4;
  681. margin-top: 5px;
  682. height: 38px;
  683. width: 38px;
  684. border: 0;
  685. box-shadow: 3px 3px 5px black;
  686. }
  687. .tool-button:hover {
  688. background-color: white;
  689. }
  690. .tool-button-active {
  691. box-shadow: 0 0 0;
  692. color: white;
  693. background-color: #8AB45F;
  694. position: relative;
  695. top: 1px;
  696. left: 1px;
  697. }
  698. .tool-button-active:hover {
  699. color: white;
  700. background-color: #81C581;
  701. }
  702. .tool-button-disabled {
  703. color: lightgray;
  704. background-color: gray;
  705. }
  706. .tool-button-disabled:hover {
  707. color: lightgray;
  708. background-color: gray;
  709. }
  710. i {
  711. font-size: 200%;
  712. }
  713. .space {
  714. width: 10px;
  715. display: inline-block;
  716. }
  717. .clear {
  718. color: rgba(0,0,0,0);
  719. }
  720. </style>