|
16 | 16 | * Copyright (c) 2013 @fat
|
17 | 17 | * The MIT License. Copyright © 2016 Nishanth Shanmugham.
|
18 | 18 | */
|
19 |
| -!(function() { |
| 19 | +!(function () { |
20 | 20 | 'use strict'
|
21 | 21 | function t(t, e) {
|
22 | 22 | if (!(t instanceof e)) throw new TypeError('Cannot call a class as a function')
|
23 | 23 | }
|
24 |
| - var e = (function() { |
| 24 | + var e = (function () { |
25 | 25 | function t(t, e) {
|
26 | 26 | for (var n = 0; n < e.length; n++) {
|
27 | 27 | var i = e[n]
|
|
31 | 31 | Object.defineProperty(t, i.key, i)
|
32 | 32 | }
|
33 | 33 | }
|
34 |
| - return function(e, n, i) { |
| 34 | + return function (e, n, i) { |
35 | 35 | return n && t(e.prototype, n), i && t(e, i), e
|
36 | 36 | }
|
37 | 37 | })()
|
38 |
| - !(function(t) { |
| 38 | + !(function (t) { |
39 | 39 | function e(i) {
|
40 | 40 | if (n[i]) return n[i].exports
|
41 | 41 | var o = (n[i] = { i: i, l: !1, exports: {} })
|
|
45 | 45 | return (
|
46 | 46 | (e.m = t),
|
47 | 47 | (e.c = n),
|
48 |
| - (e.i = function(t) { |
| 48 | + (e.i = function (t) { |
49 | 49 | return t
|
50 | 50 | }),
|
51 |
| - (e.d = function(t, n, i) { |
| 51 | + (e.d = function (t, n, i) { |
52 | 52 | e.o(t, n) || Object.defineProperty(t, n, { configurable: !1, enumerable: !0, get: i })
|
53 | 53 | }),
|
54 |
| - (e.n = function(t) { |
| 54 | + (e.n = function (t) { |
55 | 55 | var n =
|
56 | 56 | t && t.__esModule
|
57 |
| - ? function() { |
| 57 | + ? function () { |
58 | 58 | return t.default
|
59 | 59 | }
|
60 |
| - : function() { |
| 60 | + : function () { |
61 | 61 | return t
|
62 | 62 | }
|
63 | 63 | return e.d(n, 'a', n), n
|
64 | 64 | }),
|
65 |
| - (e.o = function(t, e) { |
| 65 | + (e.o = function (t, e) { |
66 | 66 | return Object.prototype.hasOwnProperty.call(t, e)
|
67 | 67 | }),
|
68 | 68 | (e.p = ''),
|
69 | 69 | e((e.s = 3))
|
70 | 70 | )
|
71 | 71 | })([
|
72 |
| - function(t, e, n) { |
73 |
| - n.d(e, 'a', function() { |
| 72 | + function (t, e, n) { |
| 73 | + n.d(e, 'a', function () { |
74 | 74 | return i
|
75 | 75 | }),
|
76 |
| - n.d(e, 'b', function() { |
| 76 | + n.d(e, 'b', function () { |
77 | 77 | return o
|
78 | 78 | }),
|
79 |
| - n.d(e, 'c', function() { |
| 79 | + n.d(e, 'c', function () { |
80 | 80 | return r
|
81 | 81 | }),
|
82 |
| - n.d(e, 'd', function() { |
| 82 | + n.d(e, 'd', function () { |
83 | 83 | return a
|
84 | 84 | })
|
85 |
| - var i = function() { |
| 85 | + var i = function () { |
86 | 86 | return document.documentElement.clientWidth
|
87 | 87 | },
|
88 |
| - o = function() { |
| 88 | + o = function () { |
89 | 89 | return document.documentElement.clientHeight
|
90 | 90 | },
|
91 |
| - r = function(t) { |
| 91 | + r = function (t) { |
92 | 92 | var e = t.getBoundingClientRect(),
|
93 | 93 | n = document.documentElement,
|
94 | 94 | i = window
|
95 | 95 | return {
|
96 | 96 | top: e.top + i.pageYOffset - n.clientTop,
|
97 |
| - left: e.left + i.pageXOffset - n.clientLeft |
| 97 | + left: e.left + i.pageXOffset - n.clientLeft, |
98 | 98 | }
|
99 | 99 | },
|
100 |
| - a = function(t, e, n) { |
| 100 | + a = function (t, e, n) { |
101 | 101 | var i = function t(i) {
|
102 | 102 | i.target.removeEventListener(e, t), n()
|
103 | 103 | }
|
104 | 104 | t.addEventListener(e, i)
|
105 | 105 | }
|
106 | 106 | },
|
107 |
| - function(t, e, n) { |
| 107 | + function (t, e, n) { |
108 | 108 | var i = n(2),
|
109 | 109 | o = n(0)
|
110 |
| - n.d(e, 'a', function() { |
| 110 | + n.d(e, 'a', function () { |
111 | 111 | return w
|
112 | 112 | })
|
113 | 113 | var r = null,
|
114 | 114 | a = 80,
|
115 | 115 | s = -1,
|
116 | 116 | u = -1,
|
117 |
| - c = function(t) { |
| 117 | + c = function (t) { |
118 | 118 | t.addEventListener('click', l)
|
119 | 119 | },
|
120 |
| - l = function(t) { |
| 120 | + l = function (t) { |
121 | 121 | return document.body.classList.contains('zoom-overlay-open')
|
122 | 122 | ? void 0
|
123 | 123 | : t.metaKey || t.ctrlKey
|
|
127 | 127 | (d(!0), (r = new i.a(t.target, a)), r.zoom(), m())
|
128 | 128 | )
|
129 | 129 | },
|
130 |
| - d = function(t) { |
| 130 | + d = function (t) { |
131 | 131 | null != r && (t ? r.dispose() : r.close(), f(), (r = null))
|
132 | 132 | },
|
133 |
| - m = function() { |
| 133 | + m = function () { |
134 | 134 | document.addEventListener('scroll', h),
|
135 | 135 | document.addEventListener('keyup', v),
|
136 | 136 | document.addEventListener('touchstart', p),
|
137 | 137 | document.addEventListener('click', y, !0)
|
138 | 138 | },
|
139 |
| - f = function() { |
| 139 | + f = function () { |
140 | 140 | document.removeEventListener('scroll', h),
|
141 | 141 | document.removeEventListener('keyup', v),
|
142 | 142 | document.removeEventListener('touchstart', p),
|
143 | 143 | document.removeEventListener('click', y, !0)
|
144 | 144 | },
|
145 |
| - h = function() { |
| 145 | + h = function () { |
146 | 146 | ;-1 == s && (s = window.pageYOffset)
|
147 | 147 | var t = Math.abs(s - window.pageYOffset)
|
148 | 148 | t >= 40 && d()
|
149 | 149 | },
|
150 |
| - v = function(t) { |
| 150 | + v = function (t) { |
151 | 151 | 27 == t.keyCode && d()
|
152 | 152 | },
|
153 |
| - p = function(t) { |
| 153 | + p = function (t) { |
154 | 154 | var e = t.touches[0]
|
155 | 155 | null != e && ((u = e.pageY), t.target.addEventListener('touchmove', g))
|
156 | 156 | },
|
|
160 | 160 | Math.abs(n.pageY - u) > 10 &&
|
161 | 161 | (d(), e.target.removeEventListener('touchmove', t))
|
162 | 162 | },
|
163 |
| - y = function() { |
| 163 | + y = function () { |
164 | 164 | d()
|
165 | 165 | },
|
166 | 166 | w = Object.create(null)
|
167 | 167 | w.setup = c
|
168 | 168 | },
|
169 |
| - function(n, i, o) { |
| 169 | + function (n, i, o) { |
170 | 170 | var r = o(0),
|
171 | 171 | a = function e(n, i) {
|
172 | 172 | t(this, e), (this.w = n), (this.h = i)
|
173 | 173 | },
|
174 |
| - s = (function() { |
| 174 | + s = (function () { |
175 | 175 | function n(e, i) {
|
176 | 176 | t(this, n),
|
177 | 177 | (this.img = e),
|
|
184 | 184 | e(n, [
|
185 | 185 | {
|
186 | 186 | key: 'forceRepaint',
|
187 |
| - value: function() { |
| 187 | + value: function () { |
188 | 188 | this.img.offsetWidth
|
189 |
| - } |
| 189 | + }, |
190 | 190 | },
|
191 | 191 | {
|
192 | 192 | key: 'zoom',
|
193 |
| - value: function() { |
| 193 | + value: function () { |
194 | 194 | var t = new a(this.img.naturalWidth, this.img.naturalHeight)
|
195 | 195 | ;(this.wrap = document.createElement('div')),
|
196 | 196 | this.wrap.classList.add('zoom-img-wrap'),
|
|
206 | 206 | this.forceRepaint(),
|
207 | 207 | this.animate(e),
|
208 | 208 | document.body.classList.add('zoom-overlay-open')
|
209 |
| - } |
| 209 | + }, |
210 | 210 | },
|
211 | 211 | {
|
212 | 212 | key: 'calculateScale',
|
213 |
| - value: function(t) { |
| 213 | + value: function (t) { |
214 | 214 | var e = t.w / this.img.width,
|
215 | 215 | n = o.i(r.a)() - this.offset,
|
216 | 216 | i = o.i(r.b)() - this.offset,
|
217 | 217 | a = t.w / t.h,
|
218 | 218 | s = n / i
|
219 | 219 | return t.w < n && t.h < i ? e : s > a ? (i / t.h) * e : (n / t.w) * e
|
220 |
| - } |
| 220 | + }, |
221 | 221 | },
|
222 | 222 | {
|
223 | 223 | key: 'animate',
|
224 |
| - value: function(t) { |
| 224 | + value: function (t) { |
225 | 225 | var e = o.i(r.c)(this.img),
|
226 | 226 | n = window.pageYOffset,
|
227 | 227 | i = o.i(r.a)() / 2,
|
|
234 | 234 | m = 'scale(' + t + ')',
|
235 | 235 | f = 'translate3d(' + c + 'px, ' + l + 'px, ' + d + 'px)'
|
236 | 236 | ;(this.img.style.transform = m), (this.wrap.style.transform = f)
|
237 |
| - } |
| 237 | + }, |
238 | 238 | },
|
239 | 239 | {
|
240 | 240 | key: 'dispose',
|
241 |
| - value: function() { |
| 241 | + value: function () { |
242 | 242 | null != this.wrap &&
|
243 | 243 | null != this.wrap.parentNode &&
|
244 | 244 | (this.img.classList.remove('zoom-img'),
|
|
247 | 247 | this.wrap.parentNode.removeChild(this.wrap),
|
248 | 248 | document.body.removeChild(this.overlay),
|
249 | 249 | document.body.classList.remove('zoom-overlay-transitioning'))
|
250 |
| - } |
| 250 | + }, |
251 | 251 | },
|
252 | 252 | {
|
253 | 253 | key: 'close',
|
254 |
| - value: function() { |
| 254 | + value: function () { |
255 | 255 | var t = this
|
256 | 256 | document.body.classList.add('zoom-overlay-transitioning'),
|
257 | 257 | (this.img.style.transform = this.preservedTransform),
|
258 | 258 | 0 === this.img.style.length && this.img.removeAttribute('style'),
|
259 | 259 | (this.wrap.style.transform = 'none'),
|
260 |
| - o.i(r.d)(this.img, 'transitionend', function() { |
| 260 | + o.i(r.d)(this.img, 'transitionend', function () { |
261 | 261 | t.dispose(), document.body.classList.remove('zoom-overlay-open')
|
262 | 262 | })
|
263 |
| - } |
264 |
| - } |
| 263 | + }, |
| 264 | + }, |
265 | 265 | ]),
|
266 | 266 | n
|
267 | 267 | )
|
268 | 268 | })()
|
269 | 269 | i.a = s
|
270 | 270 | },
|
271 |
| - function(t, e, n) { |
| 271 | + function (t, e, n) { |
272 | 272 | Object.defineProperty(e, '__esModule', { value: !0 })
|
273 | 273 | var i = n(1)
|
274 |
| - document.addEventListener('DOMContentLoaded', function() { |
| 274 | + document.addEventListener('DOMContentLoaded', function () { |
275 | 275 | for (var t = document.querySelectorAll("img[data-action='zoom']"), e = 0; e < t.length; e++)
|
276 | 276 | i.a.setup(t[e])
|
277 | 277 | })
|
278 |
| - } |
| 278 | + }, |
279 | 279 | ])
|
280 | 280 | })()
|
0 commit comments