summaryrefslogtreecommitdiff
path: root/lib/epub.js/examples/hypothesis-continuous.html
blob: 8ed8f75cea7f4c3bda404e73b046a72b1e34616d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>EPUB.js Continuous Example</title>

  <script src="../dist/epub.js"></script>
  <!-- <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> -->
  <script src="//hypothes.is/embed.js"></script>

  <style type="text/css">
    body {
      margin: 0 auto;
      background: #fafafa;
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: #333;
      height: 100%;
      width: 100%;
      max-width: 1200px;
    }

    .epub-container {
      min-width: 320px;
      margin: 0 auto;
    }

      /*.epub-container > div {
        padding: 0 20% 0 20%;
      }*/

    .epub-container .epub-view > iframe {
        background: white;
        box-shadow: 0 0 4px #ccc;
        margin: 10px;
        padding: 20px;
    }


    #prev {
      left: 40px;
    }

    #next {
      right: 40px;
    }

    .arrow {
      position: fixed;
      top: 50%;
      margin-top: -32px;
      font-size: 64px;
      color: #E2E2E2;
      font-family: arial, sans-serif;
      font-weight: bold;
      cursor: pointer;
      -webkit-user-select: none;
      -moz-user-select: none;
      user-select: none;
    }

    .arrow:hover {
      color: #777;
    }

    .arrow:active {
      color: #000;
    }

    #toc {
      display: block;
      margin: 10px auto;
    }

  </style>
</head>
<body>
  <div id="viewer"></div>

  <script>
    // var currentSectionIndex = 8;
    // Load the opf
    var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
    var rendition = book.renderTo(document.body, { method: "continuous", flow: "scrolled-continuous", width: "60%" });
    var displayed = rendition.display();


    displayed.then(function(renderer){
      // -- do stuff
    });

    // Navigation loaded
    book.loaded.navigation.then(function(toc){
      // console.log(toc);
    });

    book.rendition.hooks.content.register(function(view) {
      return view.addScript("//hypothes.is/embed.js").then(function() {
        view.window.hypothesisConfig = function () {

      		return {
      			constructor: this.Annotator.Guest,
              	app: 'https://hypothes.is/app.html'
      		};
      	};

        // view.window.hypothesisInstall();
      });
    });

    book.rendition.hooks.render.register(function(view) {
    	var getVisibleAnnotations = function ($) {
    		var height = document.documentElement.clientHeight;
    		return $('.annotator-hl').map(function() {
    			var $this = $(this),
              pos = view.position().top,
              top = pos + this.getBoundingClientRect().top;
    			if (top >= 0 && top <= height) {
    				return $this.data('annotation');
    			}
    		}).get();
    	};
      book.rendition.on("scroll", function() {
        var annotator = view.window.annotator;
        var annotations;
        if(annotator && annotator.constructor.$) {
          annotations = getVisibleAnnotations(annotator.constructor.$);
          annotator.showAnnotations(annotations);
        }
      });
    });

  </script>

</body>
</html>