-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathApp.vue
201 lines (183 loc) · 4.57 KB
/
App.vue
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
<div
id="app"
:class="{ 'has-mouse': hasMouse }"
@touchstart="hasMouse = false"
>
<Ribbon
text="Fork me on GitHub"
url="https://github.com/ts1/flipbook-vue"
/>
<Flipbook
class="flipbook"
:pages="pages"
:pagesHiRes="pagesHiRes"
:startPage="pageNum"
v-slot="flipbook"
ref="flipbook"
@flip-left-start="onFlipLeftStart"
@flip-left-end="onFlipLeftEnd"
@flip-right-start="onFlipRightStart"
@flip-right-end="onFlipRightEnd"
@zoom-start="onZoomStart"
@zoom-end="onZoomEnd"
>
<div class="action-bar">
<left-icon
class="btn left"
:class="{ disabled: !flipbook.canFlipLeft }"
@click="flipbook.flipLeft"
/>
<plus-icon
class="btn plus"
:class="{ disabled: !flipbook.canZoomIn }"
@click="flipbook.zoomIn"
/>
<span class="page-num">
Page {{ flipbook.page }} of {{ flipbook.numPages }}
</span>
<minus-icon
class="btn minus"
:class="{ disabled: !flipbook.canZoomOut }"
@click="flipbook.zoomOut"
/>
<right-icon
class="btn right"
:class="{ disabled: !flipbook.canFlipRight }"
@click="flipbook.flipRight"
/>
</div>
</Flipbook>
<p class="credit">
Photos from
<a href="https://unsplash.com/" target="_blank">Unsplash</a>.
</p>
</div>
</template>
<script lang="coffee">
import 'vue-material-design-icons/styles.css'
import Ribbon from 'vue-ribbon'
import LeftIcon from 'vue-material-design-icons/ChevronLeftCircle'
import RightIcon from 'vue-material-design-icons/ChevronRightCircle'
import PlusIcon from 'vue-material-design-icons/PlusCircle'
import MinusIcon from 'vue-material-design-icons/MinusCircle'
import Flipbook from './Flipbook'
export default
name: 'app'
components: { Flipbook, LeftIcon, RightIcon, PlusIcon, MinusIcon, Ribbon }
data: ->
pages: [],
pagesHiRes: [],
hasMouse: true
pageNum: null
methods:
onFlipLeftStart: (page) -> console.log 'flip-left-start', page
onFlipLeftEnd: (page) ->
console.log 'flip-left-end', page
window.location.hash = '#' + page
onFlipRightStart: (page) -> console.log 'flip-right-start', page
onFlipRightEnd: (page) ->
console.log 'flip-right-end', page
window.location.hash = '#' + page
onZoomStart: (zoom) -> console.log 'zoom-start', zoom
onZoomEnd: (zoom) -> console.log 'zoom-end', zoom
setPageFromHash: ->
n = parseInt window.location.hash.slice(1), 10
@pageNum = n if isFinite n
mounted: ->
window.addEventListener 'keydown', (ev) =>
flipbook = @$refs.flipbook
return unless flipbook
flipbook.flipLeft() if ev.keyCode == 37 and flipbook.canFlipLeft
flipbook.flipRight() if ev.keyCode == 39 and flipbook.canFlipRight
# Simulate asynchronous pages initialization
setTimeout (=>
@pages = [
null
'images/1.jpg'
'images/2.jpg'
'images/3.jpg'
'images/4.jpg'
'images/5.jpg'
'images/6.jpg'
]
@pagesHiRes = [
null
'images-large/1.jpg'
'images-large/2.jpg'
'images-large/3.jpg'
'images-large/4.jpg'
'images-large/5.jpg'
'images-large/6.jpg'
]
), 1
window.addEventListener 'hashchange', @setPageFromHash
@setPageFromHash()
</script>
<style>
html, body {
margin: 0;
padding: 0;
}
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
background-color: #333;
color: #ccc;
overflow: hidden;
}
a {
color: inherit;
}
.action-bar {
width: 100%;
height: 30px;
padding: 10px 0;
display: flex;
justify-content: center;
align-items: center;
}
.action-bar .btn {
font-size: 30px;
color: #999;
}
.action-bar .btn svg {
bottom: 0;
}
.action-bar .btn:not(:first-child) {
margin-left: 10px;
}
.has-mouse .action-bar .btn:hover {
color: #ccc;
filter: drop-shadow(1px 1px 5px #000);
cursor: pointer;
}
.action-bar .btn:active {
filter: none !important;
}
.action-bar .btn.disabled {
color: #666;
pointer-events: none;
}
.action-bar .page-num {
font-size: 12px;
margin-left: 10px;
}
.flipbook .viewport {
width: 90vw;
height: calc(100vh - 50px - 40px);
}
.flipbook .bounding-box {
box-shadow: 0 0 20px #000;
}
.credit {
font-size: 12px;
line-height: 20px;
margin: 10px;
}
</style>