diva.js 6.0.2 → 7.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clang-format +7 -0
- package/.github/workflows/npm-publish.yml +45 -0
- package/LICENSE +55 -0
- package/Makefile +75 -0
- package/README.md +15 -114
- package/elm.json +32 -0
- package/package.json +12 -59
- package/review/elm.json +52 -0
- package/review/src/ReviewConfig.elm +87 -0
- package/scripts/elm-esm.sh +40 -0
- package/scripts/minify-css.mjs +31 -0
- package/src/Filters.elm +1044 -0
- package/src/Main.elm +1217 -0
- package/src/Model.elm +213 -0
- package/src/Msg.elm +59 -0
- package/src/Utilities.elm +46 -0
- package/src/View/CollectionExplorer.elm +172 -0
- package/src/View/Helpers.elm +86 -0
- package/src/View/HtmlRenderer.elm +136 -0
- package/src/View/Icons.elm +159 -0
- package/src/View/ManifestInfoModal.elm +363 -0
- package/src/View/PageViewModal.elm +1046 -0
- package/src/View/Sidebar.elm +786 -0
- package/src/View/Toolbar.elm +189 -0
- package/src/View.elm +244 -0
- package/src/diva.ts +802 -0
- package/src/filters.ts +1843 -0
- package/src/styles/app.css +328 -0
- package/src/styles/collection.css +75 -0
- package/src/styles/modal.css +388 -0
- package/src/styles/sidebar.css +215 -0
- package/src/styles/theme.css +39 -0
- package/src/styles/toolbar.css +154 -0
- package/src/viewer-element.ts +1307 -0
- package/testing/index.html +52 -0
- package/testing/testing.html +231 -0
- package/tsconfig.json +12 -0
- package/AUTHORS +0 -22
- package/build/diva.css +0 -554
- package/build/diva.css.map +0 -1
- package/build/diva.js +0 -9
- package/build/diva.js.map +0 -1
- package/build/plugins/download.js +0 -2
- package/build/plugins/download.js.map +0 -1
- package/build/plugins/manipulation.js +0 -2
- package/build/plugins/manipulation.js.map +0 -1
- package/build/plugins/metadata.js +0 -2
- package/build/plugins/metadata.js.map +0 -1
- package/index.html +0 -28
- package/karma.conf.js +0 -87
- package/source/css/_mixins.scss +0 -43
- package/source/css/_variables.scss +0 -50
- package/source/css/_viewer.scss +0 -462
- package/source/css/diva.scss +0 -15
- package/source/css/plugins/_manipulation.scss +0 -228
- package/source/css/plugins/_metadata.scss +0 -31
- package/source/img/adjust.svg +0 -11
- package/source/img/book-view.svg +0 -6
- package/source/img/close.svg +0 -6
- package/source/img/download.svg +0 -6
- package/source/img/from-fullscreen.svg +0 -8
- package/source/img/grid-fewer.svg +0 -6
- package/source/img/grid-more.svg +0 -6
- package/source/img/grid-view.svg +0 -6
- package/source/img/link.svg +0 -6
- package/source/img/metadata.svg +0 -9
- package/source/img/page-view.svg +0 -6
- package/source/img/to-fullscreen.svg +0 -11
- package/source/img/zoom-in.svg +0 -6
- package/source/img/zoom-out.svg +0 -7
- package/source/js/composite-image.js +0 -174
- package/source/js/diva-global.js +0 -7
- package/source/js/diva.js +0 -1543
- package/source/js/document-handler.js +0 -180
- package/source/js/document-layout.js +0 -286
- package/source/js/exceptions.js +0 -26
- package/source/js/gesture-events.js +0 -190
- package/source/js/grid-handler.js +0 -122
- package/source/js/iiif-source-adapter.js +0 -63
- package/source/js/image-cache.js +0 -113
- package/source/js/image-manifest.js +0 -157
- package/source/js/image-request-handler.js +0 -76
- package/source/js/interpolate-animation.js +0 -122
- package/source/js/page-layouts/book-layout.js +0 -161
- package/source/js/page-layouts/grid-layout.js +0 -97
- package/source/js/page-layouts/index.js +0 -38
- package/source/js/page-layouts/page-dimensions.js +0 -9
- package/source/js/page-layouts/singles-layout.js +0 -27
- package/source/js/page-overlay-manager.js +0 -102
- package/source/js/page-tools-overlay.js +0 -95
- package/source/js/parse-iiif-manifest.js +0 -302
- package/source/js/plugins/_filters.js +0 -679
- package/source/js/plugins/download.js +0 -83
- package/source/js/plugins/manipulation.js +0 -837
- package/source/js/plugins/metadata.js +0 -190
- package/source/js/renderer.js +0 -584
- package/source/js/settings-view.js +0 -30
- package/source/js/tile-coverage-map.js +0 -25
- package/source/js/toolbar.js +0 -573
- package/source/js/utils/dragscroll.js +0 -106
- package/source/js/utils/elt.js +0 -94
- package/source/js/utils/events.js +0 -190
- package/source/js/utils/get-scrollbar-width.js +0 -29
- package/source/js/utils/hash-params.js +0 -86
- package/source/js/utils/parse-label-value.js +0 -34
- package/source/js/utils/vanilla.kinetic.js +0 -527
- package/source/js/validation-runner.js +0 -177
- package/source/js/viewer-core.js +0 -1514
- package/source/js/viewport.js +0 -143
- package/test/_setup.js +0 -13
- package/test/composite-image_test.js +0 -94
- package/test/diva_test.js +0 -43
- package/test/hash-params_test.js +0 -221
- package/test/image-cache_test.js +0 -106
- package/test/main.js +0 -6
- package/test/manifests/beromunsterManifest.json +0 -15514
- package/test/manifests/iiifv2.json +0 -11032
- package/test/manifests/iiifv2pages.json +0 -30437
- package/test/manifests/iiifv3.json +0 -10965
- package/test/navigation_test.js +0 -355
- package/test/parse-iiif-manifest_test.js +0 -68
- package/test/public_test.js +0 -881
- package/test/settings_test.js +0 -487
- package/test/utils/book-layout_test.js +0 -148
- package/test/utils/elt_test.js +0 -102
- package/test/utils/events_test.js +0 -245
- package/test/utils/hash-params_test.js +0 -79
- package/test/utils/parse-label-value_test.js +0 -45
- package/test/z_plugins_test.js +0 -180
- package/webpack.config.js +0 -58
- package/webpack.config.test.js +0 -45
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License (MIT)
|
|
3
|
-
Copyright (c) <2011> <Dave Taylor http://the-taylors.org>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is furnished
|
|
10
|
-
to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
|
22
|
-
Port to vanilla Javascript by Jacek Nowacki http://jacek-nowacki.net/
|
|
23
|
-
**/
|
|
24
|
-
|
|
25
|
-
(function() {
|
|
26
|
-
var _raf = window.requestAnimationFrame;
|
|
27
|
-
|
|
28
|
-
var _isTouch = 'ontouchend' in document;
|
|
29
|
-
|
|
30
|
-
// this is simple, no "deep" support
|
|
31
|
-
var _extend = function() {
|
|
32
|
-
for (var i=1; i<arguments.length; i++) {
|
|
33
|
-
for (var key in arguments[i]) {
|
|
34
|
-
if (arguments[i].hasOwnProperty(key)) {
|
|
35
|
-
arguments[0][key] = arguments[i][key];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return arguments[0];
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var VanillaKinetic = function(element, settings) {
|
|
43
|
-
this.settings = _extend({}, VanillaKinetic.DEFAULTS, settings);
|
|
44
|
-
this.el = element;
|
|
45
|
-
this.ACTIVE_CLASS = "kinetic-active";
|
|
46
|
-
|
|
47
|
-
this._initElements();
|
|
48
|
-
|
|
49
|
-
this.el._VanillaKinetic = this;
|
|
50
|
-
return this;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
VanillaKinetic.DEFAULTS = {
|
|
54
|
-
cursor: 'move',
|
|
55
|
-
decelerate: true,
|
|
56
|
-
triggerHardware: false,
|
|
57
|
-
threshold: 0,
|
|
58
|
-
y: true,
|
|
59
|
-
x: true,
|
|
60
|
-
slowdown: 0.9,
|
|
61
|
-
maxvelocity: 40,
|
|
62
|
-
throttleFPS: 60,
|
|
63
|
-
invert: false,
|
|
64
|
-
movingClass: {
|
|
65
|
-
up: 'kinetic-moving-up',
|
|
66
|
-
down: 'kinetic-moving-down',
|
|
67
|
-
left: 'kinetic-moving-left',
|
|
68
|
-
right: 'kinetic-moving-right'
|
|
69
|
-
},
|
|
70
|
-
deceleratingClass: {
|
|
71
|
-
up: 'kinetic-decelerating-up',
|
|
72
|
-
down: 'kinetic-decelerating-down',
|
|
73
|
-
left: 'kinetic-decelerating-left',
|
|
74
|
-
right: 'kinetic-decelerating-right'
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Public functions
|
|
79
|
-
VanillaKinetic.prototype.start = function(options) {
|
|
80
|
-
this.settings = _extend(this.settings, options);
|
|
81
|
-
this.velocity = options.velocity || this.velocity;
|
|
82
|
-
this.velocityY = options.velocityY || this.velocityY;
|
|
83
|
-
this.settings.decelerate = false;
|
|
84
|
-
this._move();
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
VanillaKinetic.prototype.end = function() {
|
|
88
|
-
this.settings.decelerate = true;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
VanillaKinetic.prototype.stop = function() {
|
|
92
|
-
this.velocity = 0;
|
|
93
|
-
this.velocityY = 0;
|
|
94
|
-
this.settings.decelerate = true;
|
|
95
|
-
if (typeof this.settings.stopped === 'function') {
|
|
96
|
-
this.settings.stopped.call(this);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
VanillaKinetic.prototype.detach = function() {
|
|
101
|
-
this._detachListeners();
|
|
102
|
-
this.el.classList.remove(this.ACTIVE_CLASS);
|
|
103
|
-
this.el.style.cursor = '';
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
VanillaKinetic.prototype.attach = function() {
|
|
107
|
-
if (this.el.classList.contains(this.ACTIVE_CLASS)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this._attachListeners();
|
|
111
|
-
this.el.classList.add(this.ACTIVE_CLASS);
|
|
112
|
-
this.el.style.cursor = this.settings.cursor;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// Internal functions
|
|
116
|
-
|
|
117
|
-
VanillaKinetic.prototype._initElements = function() {
|
|
118
|
-
this.el.classList.add(this.ACTIVE_CLASS);
|
|
119
|
-
|
|
120
|
-
_extend(this, {
|
|
121
|
-
xpos: null,
|
|
122
|
-
prevXPos: false,
|
|
123
|
-
ypos: null,
|
|
124
|
-
prevYPos: false,
|
|
125
|
-
mouseDown: false,
|
|
126
|
-
throttleTimeout: 1000 / this.settings.throttleFPS,
|
|
127
|
-
lastMove: null,
|
|
128
|
-
elementFocused: null
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
this.velocity = 0;
|
|
132
|
-
this.velocityY = 0;
|
|
133
|
-
|
|
134
|
-
var that = this;
|
|
135
|
-
this.documentResetHandler = function() {
|
|
136
|
-
that._resetMouse.apply(that);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// FIXME make sure to remove this
|
|
140
|
-
var html = document.documentElement;
|
|
141
|
-
html.addEventListener("mouseup", this.documentResetHandler, false);
|
|
142
|
-
html.addEventListener("click", this.documentResetHandler, false);
|
|
143
|
-
|
|
144
|
-
this._initEvents();
|
|
145
|
-
|
|
146
|
-
this.el.style.cursor = this.settings.cursor;
|
|
147
|
-
|
|
148
|
-
if (this.settings.triggerHardware) {
|
|
149
|
-
var prefixes = ['', '-ms-', '-webkit-', '-moz-'];
|
|
150
|
-
var styles = {
|
|
151
|
-
'transform': 'translate3d(0,0,0)',
|
|
152
|
-
'perspective': '1000', // TODO is this even valid? is this even needed?
|
|
153
|
-
'backface-visibility': 'hidden'
|
|
154
|
-
};
|
|
155
|
-
for (var i=0; i<prefixes.length; i++) {
|
|
156
|
-
var prefix = prefixes[i];
|
|
157
|
-
for (var key in styles) {
|
|
158
|
-
if (styles.hasOwnProperty(key)){
|
|
159
|
-
this.el.style[prefix+key] = styles[key];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
VanillaKinetic.prototype._initEvents = function() {
|
|
167
|
-
var self = this;
|
|
168
|
-
this.settings.events = {
|
|
169
|
-
touchStart: function(e) {
|
|
170
|
-
var touch;
|
|
171
|
-
if (self._useTarget(e.target, e)) {
|
|
172
|
-
touch = e.originalEvent.touches[0];
|
|
173
|
-
self.threshold = self._threshold(e.target, e);
|
|
174
|
-
self._start(touch.clientX, touch.clientY);
|
|
175
|
-
e.stopPropagation();
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
touchMove: function(e) {
|
|
179
|
-
var touch;
|
|
180
|
-
if (self.mouseDown) {
|
|
181
|
-
touch = e.originalEvent.touches[0];
|
|
182
|
-
self._inputmove(touch.clientX, touch.clientY);
|
|
183
|
-
if (e.preventDefault) {
|
|
184
|
-
e.preventDefault();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
inputDown: function(e) {
|
|
189
|
-
if (self._useTarget(e.target, e)) {
|
|
190
|
-
self.threshold = self._threshold(e.target, e);
|
|
191
|
-
self._start(e.clientX, e.clientY);
|
|
192
|
-
self.elementFocused = e.target;
|
|
193
|
-
if (e.target.nodeName === "IMG") {
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
}
|
|
196
|
-
e.stopPropagation();
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
inputEnd: function(e) {
|
|
200
|
-
if (self._useTarget(e.target, e)) {
|
|
201
|
-
self._end();
|
|
202
|
-
self.elementFocused = null;
|
|
203
|
-
if (e.preventDefault) {
|
|
204
|
-
e.preventDefault();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
inputMove: function(e) {
|
|
209
|
-
if (self.mouseDown) {
|
|
210
|
-
self._inputmove(e.clientX, e.clientY);
|
|
211
|
-
if (e.preventDefault) {
|
|
212
|
-
e.preventDefault();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
scroll: function(e) {
|
|
217
|
-
if (typeof self.settings.moved === 'function') {
|
|
218
|
-
self.settings.moved.call(self, self.settings);
|
|
219
|
-
}
|
|
220
|
-
if (e.preventDefault) {
|
|
221
|
-
e.preventDefault();
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
inputClick: function(e) {
|
|
225
|
-
if (Math.abs(self.velocity) > 0 || Math.abs(self.velocityY) > 0) {
|
|
226
|
-
e.preventDefault();
|
|
227
|
-
if (e.stopPropagation) {
|
|
228
|
-
e.stopPropagation();
|
|
229
|
-
}
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
dragStart: function(e) {
|
|
234
|
-
if (self._useTarget(e.target, e) && self.elementFocused) {
|
|
235
|
-
if (e.preventDefault) {
|
|
236
|
-
e.preventDefault();
|
|
237
|
-
}
|
|
238
|
-
if (e.stopPropagation) {
|
|
239
|
-
e.stopPropagation();
|
|
240
|
-
}
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
selectStart: function(e) {
|
|
245
|
-
if (typeof self.settings.selectStart === 'function') {
|
|
246
|
-
return self.settings.selectStart.apply(self, arguments);
|
|
247
|
-
}
|
|
248
|
-
else if (self._useTarget(e.target, e)) {
|
|
249
|
-
if (e.preventDefault) {
|
|
250
|
-
e.preventDefault();
|
|
251
|
-
}
|
|
252
|
-
if (e.stopPropagation) {
|
|
253
|
-
e.stopPropagation();
|
|
254
|
-
}
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
this._attachListeners();
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
VanillaKinetic.prototype._inputmove = function(clientX, clientY) {
|
|
264
|
-
if (!this.lastMove || new Date() > new Date(this.lastMove.getTime() + this.throttleTimeout)) {
|
|
265
|
-
this.lastMove = new Date();
|
|
266
|
-
|
|
267
|
-
if (this.mouseDown && (this.xpos || this.ypos)) {
|
|
268
|
-
var movedX = (clientX - this.xpos);
|
|
269
|
-
var movedY = (clientY - this.ypos);
|
|
270
|
-
if (this.settings.invert) {
|
|
271
|
-
movedX *= -1;
|
|
272
|
-
movedY *= -1;
|
|
273
|
-
}
|
|
274
|
-
if (this.threshold>0) {
|
|
275
|
-
var moved = Math.sqrt(movedX*movedX + movedY*movedY);
|
|
276
|
-
if (this.threshold>moved) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.threshold = 0;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
if (this.elementFocused) {
|
|
284
|
-
this.elementFocused.blur();
|
|
285
|
-
this.elementFocused = null;
|
|
286
|
-
this.el.focus();
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
this.settings.decelerate = false;
|
|
290
|
-
this.velocity = this.velocityY = 0;
|
|
291
|
-
|
|
292
|
-
var scrollLeft = this.scrollLeft();
|
|
293
|
-
var scrollTop = this.scrollTop();
|
|
294
|
-
|
|
295
|
-
this.scrollLeft(this.settings.x ? scrollLeft - movedX : scrollLeft);
|
|
296
|
-
this.scrollTop(this.settings.y ? scrollTop - movedY : scrollTop);
|
|
297
|
-
|
|
298
|
-
this.prevXPos = this.xpos;
|
|
299
|
-
this.prevYPos = this.ypos;
|
|
300
|
-
this.xpos = clientX;
|
|
301
|
-
this.ypos = clientY;
|
|
302
|
-
|
|
303
|
-
this._calculateVelocities();
|
|
304
|
-
this._setMoveClasses(this.settings.movingClass);
|
|
305
|
-
|
|
306
|
-
if (typeof this.settings.moved === 'function') {
|
|
307
|
-
this.settings.moved.call(this, this.settings);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
VanillaKinetic.prototype._calculateVelocities = function() {
|
|
314
|
-
this.velocity = this._capVelocity(this.prevXPos - this.xpos, this.settings.maxvelocity);
|
|
315
|
-
this.velocityY = this._capVelocity(this.prevYPos - this.ypos, this.settings.maxvelocity);
|
|
316
|
-
if (this.settings.invert) {
|
|
317
|
-
this.velocity *= -1;
|
|
318
|
-
this.velocityY *= -1;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
VanillaKinetic.prototype._end = function() {
|
|
323
|
-
if (this.xpos && this.prevXPos && this.settings.decelerate === false) {
|
|
324
|
-
this.settings.decelerate = true;
|
|
325
|
-
this._calculateVelocities();
|
|
326
|
-
this.xpos = this.prevXPos = this.mouseDown = false;
|
|
327
|
-
this._move();
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
VanillaKinetic.prototype._useTarget = function(target, event) {
|
|
332
|
-
if (typeof this.settings.filterTarget === 'function') {
|
|
333
|
-
return this.settings.filterTarget.call(this, target, event) !== false;
|
|
334
|
-
}
|
|
335
|
-
return true;
|
|
336
|
-
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
VanillaKinetic.prototype._threshold = function(target, event) {
|
|
340
|
-
if (typeof this.settings.threshold === 'function') {
|
|
341
|
-
return this.settings.threshold.call(this, target, event);
|
|
342
|
-
}
|
|
343
|
-
return this.settings.threshold;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
VanillaKinetic.prototype._start = function(clientX, clientY) {
|
|
347
|
-
this.mouseDown = true;
|
|
348
|
-
this.velocity = this.prevXPos = 0;
|
|
349
|
-
this.velocityY = this.prevYPos = 0;
|
|
350
|
-
this.xpos = clientX;
|
|
351
|
-
this.ypos = clientY;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
VanillaKinetic.prototype._resetMouse = function() {
|
|
355
|
-
this.xpos = false;
|
|
356
|
-
this.ypos = false;
|
|
357
|
-
this.mouseDown = false;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
VanillaKinetic.prototype._decelerateVelocity = function(velocity, slowdown) {
|
|
361
|
-
return Math.floor(Math.abs(velocity)) === 0 ? 0 // is velocity less than 1?
|
|
362
|
-
: velocity * slowdown; // reduce slowdown
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
VanillaKinetic.prototype._capVelocity = function(velocity, max) {
|
|
366
|
-
var newVelocity = velocity;
|
|
367
|
-
if (velocity > 0){
|
|
368
|
-
if (velocity > max){
|
|
369
|
-
newVelocity = max;
|
|
370
|
-
}
|
|
371
|
-
} else {
|
|
372
|
-
if (velocity < (0 - max)){
|
|
373
|
-
newVelocity = (0 - max);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return newVelocity;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
VanillaKinetic.prototype._setMoveClasses = function(classes) {
|
|
380
|
-
// The fix-me comment below is from original jQuery.kinetic project
|
|
381
|
-
// FIXME: consider if we want to apply PL #44, this should not remove
|
|
382
|
-
// classes we have not defined on the element!
|
|
383
|
-
var settings = this.settings;
|
|
384
|
-
var el = this.el;
|
|
385
|
-
|
|
386
|
-
el.classList.remove(settings.movingClass.up);
|
|
387
|
-
el.classList.remove(settings.movingClass.down);
|
|
388
|
-
el.classList.remove(settings.movingClass.left);
|
|
389
|
-
el.classList.remove(settings.movingClass.right);
|
|
390
|
-
el.classList.remove(settings.deceleratingClass.up);
|
|
391
|
-
el.classList.remove(settings.deceleratingClass.down);
|
|
392
|
-
el.classList.remove(settings.deceleratingClass.left);
|
|
393
|
-
el.classList.remove(settings.deceleratingClass.right);
|
|
394
|
-
|
|
395
|
-
if (this.velocity > 0){
|
|
396
|
-
el.classList.add(classes.right);
|
|
397
|
-
}
|
|
398
|
-
if (this.velocity < 0){
|
|
399
|
-
el.classList.add(classes.left);
|
|
400
|
-
}
|
|
401
|
-
if (this.velocityY > 0){
|
|
402
|
-
el.classList.add(classes.down);
|
|
403
|
-
}
|
|
404
|
-
if (this.velocityY < 0){
|
|
405
|
-
el.classList.add(classes.up);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
VanillaKinetic.prototype._move = function() {
|
|
410
|
-
var scroller = this._getScroller();
|
|
411
|
-
var self = this;
|
|
412
|
-
var settings = this.settings;
|
|
413
|
-
|
|
414
|
-
if (settings.x && scroller.scrollWidth > 0) {
|
|
415
|
-
this.scrollLeft(this.scrollLeft() + this.velocity);
|
|
416
|
-
if (Math.abs(this.velocity) > 0) {
|
|
417
|
-
this.velocity = settings.decelerate ?
|
|
418
|
-
self._decelerateVelocity(this.velocity, settings.slowdown) : this.velocity;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
this.velocity = 0;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (settings.y && scroller.scrollHeight > 0){
|
|
426
|
-
this.scrollTop(this.scrollTop() + this.velocityY);
|
|
427
|
-
if (Math.abs(this.velocityY) > 0){
|
|
428
|
-
this.velocityY = settings.decelerate ?
|
|
429
|
-
self._decelerateVelocity(this.velocityY, settings.slowdown) : this.velocityY;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
this.velocityY = 0;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
self._setMoveClasses(settings.deceleratingClass);
|
|
437
|
-
|
|
438
|
-
if (typeof settings.moved === 'function'){
|
|
439
|
-
settings.moved.call(this, settings);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (Math.abs(this.velocity) > 0 || Math.abs(this.velocityY) > 0){
|
|
443
|
-
if (!this.moving) {
|
|
444
|
-
this.moving = true;
|
|
445
|
-
// tick for next movement
|
|
446
|
-
_raf(function() {
|
|
447
|
-
self.moving = false;
|
|
448
|
-
self._move();
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
self.stop();
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
VanillaKinetic.prototype._getScroller = function() {
|
|
458
|
-
// FIXME we may want to normalize behaviour across browsers as in original jQuery.kinetic
|
|
459
|
-
// currently this won't work correctly on all brwosers when attached to html or body element
|
|
460
|
-
return this.el;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
VanillaKinetic.prototype.scrollLeft = function(left) {
|
|
464
|
-
var scroller = this._getScroller();
|
|
465
|
-
if (typeof left === 'number') {
|
|
466
|
-
scroller.scrollLeft = left;
|
|
467
|
-
this.settings.scrollLeft = left;
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
return scroller.scrollLeft;
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
VanillaKinetic.prototype.scrollTop = function(top) {
|
|
475
|
-
var scroller = this._getScroller();
|
|
476
|
-
if (typeof top === 'number') {
|
|
477
|
-
scroller.scrollTop = top;
|
|
478
|
-
this.settings.scrollTop = top;
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
return scroller.scrollTop;
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
VanillaKinetic.prototype._attachListeners = function() {
|
|
486
|
-
var el = this.el;
|
|
487
|
-
var settings = this.settings;
|
|
488
|
-
|
|
489
|
-
if (_isTouch) {
|
|
490
|
-
el.addEventListener('touchstart', settings.events.touchStart, false);
|
|
491
|
-
el.addEventListener('touchend', settings.events.inputEnd, false);
|
|
492
|
-
el.addEventListener('touchmove', settings.events.touchMove, false);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
el.addEventListener('mousedown', settings.events.inputDown, false);
|
|
496
|
-
el.addEventListener('mouseup', settings.events.inputEnd, false);
|
|
497
|
-
el.addEventListener('mousemove', settings.events.inputMove, false);
|
|
498
|
-
|
|
499
|
-
el.addEventListener('click', settings.events.inputClick, false);
|
|
500
|
-
el.addEventListener('scroll', settings.events.scroll, false);
|
|
501
|
-
el.addEventListener('selectstart', settings.events.selectStart, false);
|
|
502
|
-
el.addEventListener('dragstart', settings.events.dragStart, false);
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
VanillaKinetic.prototype._detachListeners = function() {
|
|
506
|
-
var el = this.el;
|
|
507
|
-
var settings = this.settings;
|
|
508
|
-
|
|
509
|
-
if (_isTouch) {
|
|
510
|
-
el.removeEventListener('touchstart', settings.events.touchStart, false);
|
|
511
|
-
el.removeEventListener('touchend', settings.events.inputEnd, false);
|
|
512
|
-
el.removeEventListener('touchmove', settings.events.touchMove, false);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
el.removeEventListener('mousedown', settings.events.inputDown, false);
|
|
516
|
-
el.removeEventListener('mouseup', settings.events.inputEnd, false);
|
|
517
|
-
el.removeEventListener('mousemove', settings.events.inputMove, false);
|
|
518
|
-
|
|
519
|
-
el.removeEventListener('click', settings.events.inputClick, false);
|
|
520
|
-
el.removeEventListener('scroll', settings.events.scroll, false);
|
|
521
|
-
el.removeEventListener('selectstart', settings.events.selectStart, false);
|
|
522
|
-
el.removeEventListener('dragstart', settings.events.dragStart, false);
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
window.VanillaKinetic = VanillaKinetic;
|
|
527
|
-
})();
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
export default class ValidationRunner
|
|
2
|
-
{
|
|
3
|
-
constructor (options)
|
|
4
|
-
{
|
|
5
|
-
this.whitelistedKeys = options.whitelistedKeys || [];
|
|
6
|
-
this.additionalProperties = options.additionalProperties || [];
|
|
7
|
-
this.validations = options.validations;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
isValid (key, value, settings)
|
|
11
|
-
{
|
|
12
|
-
// Get the validation index
|
|
13
|
-
let validationIndex = null;
|
|
14
|
-
|
|
15
|
-
this.validations.some((validation, index) =>
|
|
16
|
-
{
|
|
17
|
-
if (validation.key !== key)
|
|
18
|
-
{
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
validationIndex = index;
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (validationIndex === null)
|
|
27
|
-
{
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Run the validation
|
|
32
|
-
const dummyChanges = {};
|
|
33
|
-
dummyChanges[key] = value;
|
|
34
|
-
const proxier = createSettingsProxier(settings, dummyChanges, this);
|
|
35
|
-
|
|
36
|
-
return !this._runValidation(validationIndex, value, proxier);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
validate (settings)
|
|
40
|
-
{
|
|
41
|
-
this._validateOptions({}, settings);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getValidatedOptions (settings, options)
|
|
45
|
-
{
|
|
46
|
-
const cloned = Object.assign({}, options);
|
|
47
|
-
this._validateOptions(settings, cloned);
|
|
48
|
-
return cloned;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_validateOptions (settings, options)
|
|
52
|
-
{
|
|
53
|
-
const settingsProxier = createSettingsProxier(settings, options, this);
|
|
54
|
-
this._applyValidations(options, settingsProxier);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
_applyValidations (options, proxier)
|
|
58
|
-
{
|
|
59
|
-
this.validations.forEach((validation, index) =>
|
|
60
|
-
{
|
|
61
|
-
if (!options.hasOwnProperty(validation.key))
|
|
62
|
-
{
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const input = options[validation.key];
|
|
67
|
-
const corrected = this._runValidation(index, input, proxier);
|
|
68
|
-
|
|
69
|
-
if (corrected)
|
|
70
|
-
{
|
|
71
|
-
if (!corrected.warningSuppressed)
|
|
72
|
-
{
|
|
73
|
-
emitWarning(validation.key, input, corrected.value);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
options[validation.key] = corrected.value;
|
|
77
|
-
}
|
|
78
|
-
}, this);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
_runValidation (index, input, proxier)
|
|
82
|
-
{
|
|
83
|
-
const validation = this.validations[index];
|
|
84
|
-
|
|
85
|
-
proxier.index = index;
|
|
86
|
-
|
|
87
|
-
let warningSuppressed = false;
|
|
88
|
-
const config = {
|
|
89
|
-
suppressWarning: () =>
|
|
90
|
-
{
|
|
91
|
-
warningSuppressed = true;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const outputValue = validation.validate(input, proxier.proxy, config);
|
|
96
|
-
|
|
97
|
-
if (outputValue === undefined || outputValue === input)
|
|
98
|
-
{
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
value: outputValue,
|
|
104
|
-
warningSuppressed: warningSuppressed
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* The settings proxy wraps the settings object and ensures that
|
|
111
|
-
* only values which have previously been validated are accessed,
|
|
112
|
-
* throwing a TypeError otherwise.
|
|
113
|
-
*
|
|
114
|
-
* FIXME(wabain): Is it worth keeping this? When I wrote it I had
|
|
115
|
-
* multiple validation stages and it was a lot harder to keep track
|
|
116
|
-
* of everything, so this was more valuable.
|
|
117
|
-
*/
|
|
118
|
-
function createSettingsProxier (settings, options, runner)
|
|
119
|
-
{
|
|
120
|
-
const proxier = {
|
|
121
|
-
proxy: {},
|
|
122
|
-
index: null
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const lookup = lookupValue.bind(null, settings, options);
|
|
126
|
-
|
|
127
|
-
const properties = {};
|
|
128
|
-
|
|
129
|
-
runner.whitelistedKeys.forEach((whitelisted) =>
|
|
130
|
-
{
|
|
131
|
-
properties[whitelisted] = {
|
|
132
|
-
get: lookup.bind(null, whitelisted)
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
runner.additionalProperties.forEach((additional) =>
|
|
137
|
-
{
|
|
138
|
-
properties[additional.key] = {
|
|
139
|
-
get: additional.get
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
runner.validations.forEach( (validation, validationIndex) =>
|
|
144
|
-
{
|
|
145
|
-
properties[validation.key] = {
|
|
146
|
-
get: () =>
|
|
147
|
-
{
|
|
148
|
-
if (validationIndex < proxier.index)
|
|
149
|
-
{
|
|
150
|
-
return lookup(validation.key);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const currentKey = runner.validations[proxier.index].key;
|
|
154
|
-
throw new TypeError('Cannot access setting ' + validation.key + ' while validating ' + currentKey);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
Object.defineProperties(proxier.proxy, properties);
|
|
160
|
-
|
|
161
|
-
return proxier;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function emitWarning (key, original, corrected)
|
|
165
|
-
{
|
|
166
|
-
console.warn('Invalid value for ' + key + ': ' + original + '. Using ' + corrected + ' instead.');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function lookupValue (base, extension, key)
|
|
170
|
-
{
|
|
171
|
-
if (key in extension)
|
|
172
|
-
{
|
|
173
|
-
return extension[key];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return base[key];
|
|
177
|
-
}
|