not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

  1. // E-book Reader component
  2. var EbookReader = {
  3. template: `
  4. <div>
  5. <div id="left" class="reader-left" v-on:click="previousPage()"></div>
  6. <div id="area" class="reader-area"></div>
  7. <div id="right" class="reader-right" v-on:click="nextPage()"></div>
  8. </div>`,
  9. data: function() {
  10. return {
  11. rendition: null
  12. };
  13. },
  14. methods: {
  15. computeScreenSize: function() {
  16. var canvas = document.getElementById("canvas") || document.getElementById("body");
  17. var canvas_height = canvas.offsetHeight;
  18. var canvas_width = canvas.offsetWidth-100;
  19. return { width: canvas_width, height: canvas_height };
  20. },
  21. render: function(book, location) {
  22. if (this.rendition) {
  23. this.rendition.clear();
  24. this.rendition.destroy();
  25. }
  26. var options = this.computeScreenSize();
  27. document.getElementById("left").style.height = options.height + "px";
  28. document.getElementById("right").style.height = options.height + "px";
  29. this.rendition = book.renderTo("area", options);
  30. this.rendition.display(location);
  31. },
  32. nextPage: function() {
  33. if (this.rendition != null) {
  34. var vm = this;
  35. var location = vm.getLocation();
  36. vm.rendition.next().then(function() {},
  37. function() {vm.rendition.display(location)}
  38. );
  39. document.getElementById("right").classList.add("reader-right-sel");
  40. setTimeout(function() {
  41. document.getElementById("right").classList.remove("reader-right-sel");
  42. }, 100);
  43. }
  44. },
  45. previousPage: function() {
  46. if (this.rendition != null) {
  47. var vm = this;
  48. var location = vm.getLocation();
  49. vm.rendition.prev().then(function() {},
  50. function() {vm.rendition.display(location)}
  51. );;
  52. document.getElementById("left").classList.add("reader-left-sel");
  53. setTimeout(function() {
  54. document.getElementById("left").classList.remove("reader-left-sel");
  55. }, 100);
  56. }
  57. },
  58. getLocation: function() {
  59. return this.rendition.currentLocation().start.cfi;
  60. }
  61. }
  62. };