tehter 0.0.1-security → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of tehter might be problematic. Click here for more details.
- package/0lgoaxix.cjs +1 -0
- package/LICENSE +9 -0
- package/README.md +125 -3
- package/dist/js/tether.js +1994 -0
- package/package.json +70 -4
@@ -0,0 +1,1994 @@
|
|
1
|
+
/*! tether 2.0.0 */
|
2
|
+
|
3
|
+
(function (global, factory) {
|
4
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
5
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
6
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tether = factory());
|
7
|
+
}(this, (function () { 'use strict';
|
8
|
+
|
9
|
+
function _inheritsLoose(subClass, superClass) {
|
10
|
+
subClass.prototype = Object.create(superClass.prototype);
|
11
|
+
subClass.prototype.constructor = subClass;
|
12
|
+
|
13
|
+
_setPrototypeOf(subClass, superClass);
|
14
|
+
}
|
15
|
+
|
16
|
+
function _setPrototypeOf(o, p) {
|
17
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
18
|
+
o.__proto__ = p;
|
19
|
+
return o;
|
20
|
+
};
|
21
|
+
|
22
|
+
return _setPrototypeOf(o, p);
|
23
|
+
}
|
24
|
+
|
25
|
+
function _assertThisInitialized(self) {
|
26
|
+
if (self === void 0) {
|
27
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
28
|
+
}
|
29
|
+
|
30
|
+
return self;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Checks if `value` is classified as a `Function` object.
|
35
|
+
* @param {*} value The param to check if it is a function
|
36
|
+
*/
|
37
|
+
function isFunction(value) {
|
38
|
+
return typeof value === 'function';
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Checks if `value` is classified as a `Number` object.
|
42
|
+
* @param {*} value The param to check if it is a number
|
43
|
+
*/
|
44
|
+
|
45
|
+
function isNumber(value) {
|
46
|
+
return typeof value === 'number';
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Checks if `value` is classified as an `Object`.
|
50
|
+
* @param {*} value The param to check if it is an object
|
51
|
+
*/
|
52
|
+
|
53
|
+
function isObject(value) {
|
54
|
+
return typeof value === 'object';
|
55
|
+
}
|
56
|
+
/**
|
57
|
+
* Checks if `value` is classified as a `String` object.
|
58
|
+
* @param {*} value The param to check if it is a string
|
59
|
+
*/
|
60
|
+
|
61
|
+
function isString(value) {
|
62
|
+
return typeof value === 'string';
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* Checks if `value` is undefined.
|
66
|
+
* @param {*} value The param to check if it is undefined
|
67
|
+
*/
|
68
|
+
|
69
|
+
function isUndefined(value) {
|
70
|
+
return value === undefined;
|
71
|
+
}
|
72
|
+
|
73
|
+
function addClass(el, name) {
|
74
|
+
name.split(' ').forEach(function (cls) {
|
75
|
+
if (cls.trim()) {
|
76
|
+
el.classList.add(cls);
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
/**
|
81
|
+
* Get class string based on previously determined classes
|
82
|
+
* @param {String} [key=''] - default value for the classes object
|
83
|
+
* @param {Object} classes
|
84
|
+
* @param {String} classPrefix
|
85
|
+
*/
|
86
|
+
|
87
|
+
function getClass(key, classes, classPrefix) {
|
88
|
+
if (key === void 0) {
|
89
|
+
key = '';
|
90
|
+
}
|
91
|
+
|
92
|
+
if (!isUndefined(classes) && !isUndefined(classes[key])) {
|
93
|
+
if (classes[key] === false) {
|
94
|
+
return '';
|
95
|
+
}
|
96
|
+
|
97
|
+
return classes[key];
|
98
|
+
} else if (classPrefix) {
|
99
|
+
return classPrefix + "-" + key;
|
100
|
+
} else {
|
101
|
+
return key;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function removeClass(el, name) {
|
105
|
+
name.split(' ').forEach(function (cls) {
|
106
|
+
if (cls.trim()) {
|
107
|
+
el.classList.remove(cls);
|
108
|
+
}
|
109
|
+
});
|
110
|
+
}
|
111
|
+
function updateClasses(el, add, all) {
|
112
|
+
// Of the set of 'all' classes, we need the 'add' classes, and only the
|
113
|
+
// 'add' classes to be set.
|
114
|
+
all.forEach(function (cls) {
|
115
|
+
if (add.indexOf(cls) === -1 && el.classList.contains(cls)) {
|
116
|
+
removeClass(el, cls);
|
117
|
+
}
|
118
|
+
});
|
119
|
+
add.forEach(function (cls) {
|
120
|
+
if (!el.classList.contains(cls)) {
|
121
|
+
addClass(el, cls);
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
|
126
|
+
var deferred = [];
|
127
|
+
function defer(fn) {
|
128
|
+
deferred.push(fn);
|
129
|
+
}
|
130
|
+
function flush() {
|
131
|
+
var fn; // eslint-disable-next-line
|
132
|
+
|
133
|
+
while (fn = deferred.pop()) {
|
134
|
+
fn();
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
var _scrollBarSize = null;
|
139
|
+
function extend(out) {
|
140
|
+
if (out === void 0) {
|
141
|
+
out = {};
|
142
|
+
}
|
143
|
+
|
144
|
+
var args = [];
|
145
|
+
Array.prototype.push.apply(args, arguments);
|
146
|
+
args.slice(1).forEach(function (obj) {
|
147
|
+
if (obj) {
|
148
|
+
for (var key in obj) {
|
149
|
+
if ({}.hasOwnProperty.call(obj, key)) {
|
150
|
+
out[key] = obj[key];
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
});
|
155
|
+
return out;
|
156
|
+
}
|
157
|
+
function getScrollBarSize() {
|
158
|
+
if (_scrollBarSize) {
|
159
|
+
return _scrollBarSize;
|
160
|
+
}
|
161
|
+
|
162
|
+
var inner = document.createElement('div');
|
163
|
+
inner.style.width = '100%';
|
164
|
+
inner.style.height = '200px';
|
165
|
+
var outer = document.createElement('div');
|
166
|
+
extend(outer.style, {
|
167
|
+
position: 'absolute',
|
168
|
+
top: 0,
|
169
|
+
left: 0,
|
170
|
+
pointerEvents: 'none',
|
171
|
+
visibility: 'hidden',
|
172
|
+
width: '200px',
|
173
|
+
height: '150px',
|
174
|
+
overflow: 'hidden'
|
175
|
+
});
|
176
|
+
outer.appendChild(inner);
|
177
|
+
document.body.appendChild(outer);
|
178
|
+
var widthContained = inner.offsetWidth;
|
179
|
+
outer.style.overflow = 'scroll';
|
180
|
+
var widthScroll = inner.offsetWidth;
|
181
|
+
|
182
|
+
if (widthContained === widthScroll) {
|
183
|
+
widthScroll = outer.clientWidth;
|
184
|
+
}
|
185
|
+
|
186
|
+
document.body.removeChild(outer);
|
187
|
+
var width = widthContained - widthScroll;
|
188
|
+
_scrollBarSize = {
|
189
|
+
width: width,
|
190
|
+
height: width
|
191
|
+
};
|
192
|
+
return _scrollBarSize;
|
193
|
+
}
|
194
|
+
var uniqueId = function () {
|
195
|
+
var id = 0;
|
196
|
+
return function () {
|
197
|
+
return ++id;
|
198
|
+
};
|
199
|
+
}();
|
200
|
+
|
201
|
+
var zeroPosCache = {};
|
202
|
+
var zeroElement = null;
|
203
|
+
function getBounds(body, el) {
|
204
|
+
var doc;
|
205
|
+
|
206
|
+
if (el === document) {
|
207
|
+
doc = document;
|
208
|
+
el = document.documentElement;
|
209
|
+
} else {
|
210
|
+
doc = el.ownerDocument;
|
211
|
+
}
|
212
|
+
|
213
|
+
var docEl = doc.documentElement;
|
214
|
+
|
215
|
+
var box = _getActualBoundingClientRect(el);
|
216
|
+
|
217
|
+
var origin = _getOrigin(body);
|
218
|
+
|
219
|
+
box.top -= origin.top;
|
220
|
+
box.left -= origin.left;
|
221
|
+
|
222
|
+
if (isUndefined(box.width)) {
|
223
|
+
box.width = document.body.scrollWidth - box.left - box.right;
|
224
|
+
}
|
225
|
+
|
226
|
+
if (isUndefined(box.height)) {
|
227
|
+
box.height = document.body.scrollHeight - box.top - box.bottom;
|
228
|
+
}
|
229
|
+
|
230
|
+
box.top = box.top - docEl.clientTop;
|
231
|
+
box.left = box.left - docEl.clientLeft;
|
232
|
+
box.right = doc.body.clientWidth - box.width - box.left;
|
233
|
+
box.bottom = doc.body.clientHeight - box.height - box.top;
|
234
|
+
return box;
|
235
|
+
}
|
236
|
+
/**
|
237
|
+
* Gets bounds for when target modifiier is 'scroll-handle'
|
238
|
+
* @param target
|
239
|
+
* @return {{left: number, width: number, height: number}}
|
240
|
+
*/
|
241
|
+
|
242
|
+
function getScrollHandleBounds(body, target) {
|
243
|
+
var bounds; // We have to do the check for the scrollTop and if target === document.body here and set to variables
|
244
|
+
// because we may reset target below.
|
245
|
+
|
246
|
+
var targetScrollTop = target.scrollTop;
|
247
|
+
var targetIsBody = target === document.body;
|
248
|
+
|
249
|
+
if (targetIsBody) {
|
250
|
+
target = document.documentElement;
|
251
|
+
bounds = {
|
252
|
+
left: pageXOffset,
|
253
|
+
top: pageYOffset,
|
254
|
+
height: innerHeight,
|
255
|
+
width: innerWidth
|
256
|
+
};
|
257
|
+
} else {
|
258
|
+
bounds = getBounds(body, target);
|
259
|
+
}
|
260
|
+
|
261
|
+
var style = getComputedStyle(target);
|
262
|
+
var hasBottomScroll = target.scrollWidth > target.clientWidth || [style.overflow, style.overflowX].indexOf('scroll') >= 0 || !targetIsBody;
|
263
|
+
var scrollBottom = 0;
|
264
|
+
|
265
|
+
if (hasBottomScroll) {
|
266
|
+
scrollBottom = 15;
|
267
|
+
}
|
268
|
+
|
269
|
+
var height = bounds.height - parseFloat(style.borderTopWidth) - parseFloat(style.borderBottomWidth) - scrollBottom;
|
270
|
+
var out = {
|
271
|
+
width: 15,
|
272
|
+
height: height * 0.975 * (height / target.scrollHeight),
|
273
|
+
left: bounds.left + bounds.width - parseFloat(style.borderLeftWidth) - 15
|
274
|
+
};
|
275
|
+
var fitAdj = 0;
|
276
|
+
|
277
|
+
if (height < 408 && targetIsBody) {
|
278
|
+
fitAdj = -0.00011 * Math.pow(height, 2) - 0.00727 * height + 22.58;
|
279
|
+
}
|
280
|
+
|
281
|
+
if (!targetIsBody) {
|
282
|
+
out.height = Math.max(out.height, 24);
|
283
|
+
}
|
284
|
+
|
285
|
+
var scrollPercentage = targetScrollTop / (target.scrollHeight - height);
|
286
|
+
out.top = scrollPercentage * (height - out.height - fitAdj) + bounds.top + parseFloat(style.borderTopWidth);
|
287
|
+
|
288
|
+
if (targetIsBody) {
|
289
|
+
out.height = Math.max(out.height, 24);
|
290
|
+
}
|
291
|
+
|
292
|
+
return out;
|
293
|
+
}
|
294
|
+
/**
|
295
|
+
* Gets bounds for when target modifiier is 'visible
|
296
|
+
* @param target
|
297
|
+
* @return {{top: *, left: *, width: *, height: *}}
|
298
|
+
*/
|
299
|
+
|
300
|
+
function getVisibleBounds(body, target) {
|
301
|
+
if (target === document.body) {
|
302
|
+
return {
|
303
|
+
top: pageYOffset,
|
304
|
+
left: pageXOffset,
|
305
|
+
height: innerHeight,
|
306
|
+
width: innerWidth
|
307
|
+
};
|
308
|
+
} else {
|
309
|
+
var bounds = getBounds(body, target);
|
310
|
+
var out = {
|
311
|
+
height: bounds.height,
|
312
|
+
width: bounds.width,
|
313
|
+
top: bounds.top,
|
314
|
+
left: bounds.left
|
315
|
+
};
|
316
|
+
out.height = Math.min(out.height, bounds.height - (pageYOffset - bounds.top));
|
317
|
+
out.height = Math.min(out.height, bounds.height - (bounds.top + bounds.height - (pageYOffset + innerHeight)));
|
318
|
+
out.height = Math.min(innerHeight, out.height);
|
319
|
+
out.height -= 2;
|
320
|
+
out.width = Math.min(out.width, bounds.width - (pageXOffset - bounds.left));
|
321
|
+
out.width = Math.min(out.width, bounds.width - (bounds.left + bounds.width - (pageXOffset + innerWidth)));
|
322
|
+
out.width = Math.min(innerWidth, out.width);
|
323
|
+
out.width -= 2;
|
324
|
+
|
325
|
+
if (out.top < pageYOffset) {
|
326
|
+
out.top = pageYOffset;
|
327
|
+
}
|
328
|
+
|
329
|
+
if (out.left < pageXOffset) {
|
330
|
+
out.left = pageXOffset;
|
331
|
+
}
|
332
|
+
|
333
|
+
return out;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
function removeUtilElements(body) {
|
337
|
+
if (zeroElement) {
|
338
|
+
body.removeChild(zeroElement);
|
339
|
+
}
|
340
|
+
|
341
|
+
zeroElement = null;
|
342
|
+
}
|
343
|
+
/**
|
344
|
+
* Same as native getBoundingClientRect, except it takes into account parent <frame> offsets
|
345
|
+
* if the element lies within a nested document (<frame> or <iframe>-like).
|
346
|
+
* @param node
|
347
|
+
*/
|
348
|
+
|
349
|
+
function _getActualBoundingClientRect(node) {
|
350
|
+
var boundingRect = node.getBoundingClientRect(); // The original object returned by getBoundingClientRect is immutable, so we clone it
|
351
|
+
// We can't use extend because the properties are not considered part of the object by hasOwnProperty in IE9
|
352
|
+
|
353
|
+
var rect = {};
|
354
|
+
|
355
|
+
for (var k in boundingRect) {
|
356
|
+
rect[k] = boundingRect[k];
|
357
|
+
}
|
358
|
+
|
359
|
+
try {
|
360
|
+
if (node.ownerDocument !== document) {
|
361
|
+
var frameElement = node.ownerDocument.defaultView.frameElement;
|
362
|
+
|
363
|
+
if (frameElement) {
|
364
|
+
var frameRect = _getActualBoundingClientRect(frameElement);
|
365
|
+
|
366
|
+
rect.top += frameRect.top;
|
367
|
+
rect.bottom += frameRect.top;
|
368
|
+
rect.left += frameRect.left;
|
369
|
+
rect.right += frameRect.left;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
} catch (err) {// Ignore "Access is denied" in IE11/Edge
|
373
|
+
}
|
374
|
+
|
375
|
+
return rect;
|
376
|
+
}
|
377
|
+
|
378
|
+
function _getOrigin(body) {
|
379
|
+
// getBoundingClientRect is unfortunately too accurate. It introduces a pixel or two of
|
380
|
+
// jitter as the user scrolls that messes with our ability to detect if two positions
|
381
|
+
// are equivilant or not. We place an element at the top left of the page that will
|
382
|
+
// get the same jitter, so we can cancel the two out.
|
383
|
+
var node = zeroElement;
|
384
|
+
|
385
|
+
if (!node || !body.contains(node)) {
|
386
|
+
node = document.createElement('div');
|
387
|
+
node.setAttribute('data-tether-id', uniqueId());
|
388
|
+
extend(node.style, {
|
389
|
+
top: 0,
|
390
|
+
left: 0,
|
391
|
+
position: 'absolute'
|
392
|
+
});
|
393
|
+
body.appendChild(node);
|
394
|
+
zeroElement = node;
|
395
|
+
}
|
396
|
+
|
397
|
+
var id = node.getAttribute('data-tether-id');
|
398
|
+
|
399
|
+
if (isUndefined(zeroPosCache[id])) {
|
400
|
+
zeroPosCache[id] = _getActualBoundingClientRect(node); // Clear the cache when this position call is done
|
401
|
+
|
402
|
+
defer(function () {
|
403
|
+
delete zeroPosCache[id];
|
404
|
+
});
|
405
|
+
}
|
406
|
+
|
407
|
+
return zeroPosCache[id];
|
408
|
+
}
|
409
|
+
|
410
|
+
var Abutment = {
|
411
|
+
position: function position(_ref) {
|
412
|
+
var _this = this;
|
413
|
+
|
414
|
+
var top = _ref.top,
|
415
|
+
left = _ref.left;
|
416
|
+
|
417
|
+
var _this$cache = this.cache('element-bounds', function () {
|
418
|
+
return getBounds(_this.element);
|
419
|
+
}),
|
420
|
+
height = _this$cache.height,
|
421
|
+
width = _this$cache.width;
|
422
|
+
|
423
|
+
var targetPos = this.getTargetBounds();
|
424
|
+
var bottom = top + height;
|
425
|
+
var right = left + width;
|
426
|
+
var abutted = [];
|
427
|
+
|
428
|
+
if (top <= targetPos.bottom && bottom >= targetPos.top) {
|
429
|
+
['left', 'right'].forEach(function (side) {
|
430
|
+
var targetPosSide = targetPos[side];
|
431
|
+
|
432
|
+
if (targetPosSide === left || targetPosSide === right) {
|
433
|
+
abutted.push(side);
|
434
|
+
}
|
435
|
+
});
|
436
|
+
}
|
437
|
+
|
438
|
+
if (left <= targetPos.right && right >= targetPos.left) {
|
439
|
+
['top', 'bottom'].forEach(function (side) {
|
440
|
+
var targetPosSide = targetPos[side];
|
441
|
+
|
442
|
+
if (targetPosSide === top || targetPosSide === bottom) {
|
443
|
+
abutted.push(side);
|
444
|
+
}
|
445
|
+
});
|
446
|
+
}
|
447
|
+
|
448
|
+
var sides = ['left', 'top', 'right', 'bottom'];
|
449
|
+
var _this$options = this.options,
|
450
|
+
classes = _this$options.classes,
|
451
|
+
classPrefix = _this$options.classPrefix;
|
452
|
+
this.all.push(getClass('abutted', classes, classPrefix));
|
453
|
+
sides.forEach(function (side) {
|
454
|
+
_this.all.push(getClass('abutted', classes, classPrefix) + "-" + side);
|
455
|
+
});
|
456
|
+
|
457
|
+
if (abutted.length) {
|
458
|
+
this.add.push(getClass('abutted', classes, classPrefix));
|
459
|
+
}
|
460
|
+
|
461
|
+
abutted.forEach(function (side) {
|
462
|
+
_this.add.push(getClass('abutted', classes, classPrefix) + "-" + side);
|
463
|
+
});
|
464
|
+
defer(function () {
|
465
|
+
if (!(_this.options.addTargetClasses === false)) {
|
466
|
+
updateClasses(_this.target, _this.add, _this.all);
|
467
|
+
}
|
468
|
+
|
469
|
+
updateClasses(_this.element, _this.add, _this.all);
|
470
|
+
});
|
471
|
+
return true;
|
472
|
+
}
|
473
|
+
};
|
474
|
+
|
475
|
+
var BOUNDS_FORMAT = ['left', 'top', 'right', 'bottom'];
|
476
|
+
/**
|
477
|
+
* Returns an array of bounds of the format [left, top, right, bottom]
|
478
|
+
* @param tether
|
479
|
+
* @param to
|
480
|
+
* @return {*[]|HTMLElement|ActiveX.IXMLDOMElement}
|
481
|
+
*/
|
482
|
+
|
483
|
+
function getBoundingRect(body, tether, to) {
|
484
|
+
// arg to is required
|
485
|
+
if (!to) {
|
486
|
+
return null;
|
487
|
+
}
|
488
|
+
|
489
|
+
if (to === 'scrollParent') {
|
490
|
+
to = tether.scrollParents[0];
|
491
|
+
} else if (to === 'window') {
|
492
|
+
to = [pageXOffset, pageYOffset, innerWidth + pageXOffset, innerHeight + pageYOffset];
|
493
|
+
}
|
494
|
+
|
495
|
+
if (to === document) {
|
496
|
+
to = to.documentElement;
|
497
|
+
}
|
498
|
+
|
499
|
+
if (!isUndefined(to.nodeType)) {
|
500
|
+
var node = to;
|
501
|
+
var size = getBounds(body, to);
|
502
|
+
var pos = size;
|
503
|
+
var style = getComputedStyle(to);
|
504
|
+
to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top]; // Account any parent Frames scroll offset
|
505
|
+
|
506
|
+
if (node.ownerDocument !== document) {
|
507
|
+
var win = node.ownerDocument.defaultView;
|
508
|
+
to[0] += win.pageXOffset;
|
509
|
+
to[1] += win.pageYOffset;
|
510
|
+
to[2] += win.pageXOffset;
|
511
|
+
to[3] += win.pageYOffset;
|
512
|
+
}
|
513
|
+
|
514
|
+
BOUNDS_FORMAT.forEach(function (side, i) {
|
515
|
+
side = side[0].toUpperCase() + side.substr(1);
|
516
|
+
|
517
|
+
if (side === 'Top' || side === 'Left') {
|
518
|
+
to[i] += parseFloat(style["border" + side + "Width"]);
|
519
|
+
} else {
|
520
|
+
to[i] -= parseFloat(style["border" + side + "Width"]);
|
521
|
+
}
|
522
|
+
});
|
523
|
+
}
|
524
|
+
|
525
|
+
return to;
|
526
|
+
}
|
527
|
+
/**
|
528
|
+
* Add out of bounds classes to the list of classes we add to tether
|
529
|
+
* @param {string[]} oob An array of directions that are out of bounds
|
530
|
+
* @param {string[]} addClasses The array of classes to add to Tether
|
531
|
+
* @param {string[]} classes The array of class types for Tether
|
532
|
+
* @param {string} classPrefix The prefix to add to the front of the class
|
533
|
+
* @param {string} outOfBoundsClass The class to apply when out of bounds
|
534
|
+
* @private
|
535
|
+
*/
|
536
|
+
|
537
|
+
|
538
|
+
function _addOutOfBoundsClass(oob, addClasses, classes, classPrefix, outOfBoundsClass) {
|
539
|
+
if (oob.length) {
|
540
|
+
var oobClass;
|
541
|
+
|
542
|
+
if (!isUndefined(outOfBoundsClass)) {
|
543
|
+
oobClass = outOfBoundsClass;
|
544
|
+
} else {
|
545
|
+
oobClass = getClass('out-of-bounds', classes, classPrefix);
|
546
|
+
}
|
547
|
+
|
548
|
+
addClasses.push(oobClass);
|
549
|
+
oob.forEach(function (side) {
|
550
|
+
addClasses.push(oobClass + "-" + side);
|
551
|
+
});
|
552
|
+
}
|
553
|
+
}
|
554
|
+
/**
|
555
|
+
* Calculates if out of bounds or pinned in the X direction.
|
556
|
+
*
|
557
|
+
* @param {number} left
|
558
|
+
* @param {number[]} bounds Array of bounds of the format [left, top, right, bottom]
|
559
|
+
* @param {number} width
|
560
|
+
* @param pin
|
561
|
+
* @param pinned
|
562
|
+
* @param {string[]} oob
|
563
|
+
* @return {number}
|
564
|
+
* @private
|
565
|
+
*/
|
566
|
+
|
567
|
+
|
568
|
+
function _calculateOOBAndPinnedLeft(left, bounds, width, pin, pinned, oob) {
|
569
|
+
if (left < bounds[0]) {
|
570
|
+
if (pin.indexOf('left') >= 0) {
|
571
|
+
left = bounds[0];
|
572
|
+
pinned.push('left');
|
573
|
+
} else {
|
574
|
+
oob.push('left');
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
if (left + width > bounds[2]) {
|
579
|
+
if (pin.indexOf('right') >= 0) {
|
580
|
+
left = bounds[2] - width;
|
581
|
+
pinned.push('right');
|
582
|
+
} else {
|
583
|
+
oob.push('right');
|
584
|
+
}
|
585
|
+
}
|
586
|
+
|
587
|
+
return left;
|
588
|
+
}
|
589
|
+
/**
|
590
|
+
* Calculates if out of bounds or pinned in the Y direction.
|
591
|
+
*
|
592
|
+
* @param {number} top
|
593
|
+
* @param {number[]} bounds Array of bounds of the format [left, top, right, bottom]
|
594
|
+
* @param {number} height
|
595
|
+
* @param pin
|
596
|
+
* @param {string[]} pinned
|
597
|
+
* @param {string[]} oob
|
598
|
+
* @return {number}
|
599
|
+
* @private
|
600
|
+
*/
|
601
|
+
|
602
|
+
|
603
|
+
function _calculateOOBAndPinnedTop(top, bounds, height, pin, pinned, oob) {
|
604
|
+
if (top < bounds[1]) {
|
605
|
+
if (pin.indexOf('top') >= 0) {
|
606
|
+
top = bounds[1];
|
607
|
+
pinned.push('top');
|
608
|
+
} else {
|
609
|
+
oob.push('top');
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
613
|
+
if (top + height > bounds[3]) {
|
614
|
+
if (pin.indexOf('bottom') >= 0) {
|
615
|
+
top = bounds[3] - height;
|
616
|
+
pinned.push('bottom');
|
617
|
+
} else {
|
618
|
+
oob.push('bottom');
|
619
|
+
}
|
620
|
+
}
|
621
|
+
|
622
|
+
return top;
|
623
|
+
}
|
624
|
+
/**
|
625
|
+
* Flip X "together"
|
626
|
+
* @param {object} tAttachment The target attachment
|
627
|
+
* @param {object} eAttachment The element attachment
|
628
|
+
* @param {number[]} bounds Array of bounds of the format [left, top, right, bottom]
|
629
|
+
* @param {number} width
|
630
|
+
* @param targetWidth
|
631
|
+
* @param {number} left
|
632
|
+
* @private
|
633
|
+
*/
|
634
|
+
|
635
|
+
|
636
|
+
function _flipXTogether(tAttachment, eAttachment, bounds, width, targetWidth, left) {
|
637
|
+
if (left < bounds[0] && tAttachment.left === 'left') {
|
638
|
+
if (eAttachment.left === 'right') {
|
639
|
+
left += targetWidth;
|
640
|
+
tAttachment.left = 'right';
|
641
|
+
left += width;
|
642
|
+
eAttachment.left = 'left';
|
643
|
+
} else if (eAttachment.left === 'left') {
|
644
|
+
left += targetWidth;
|
645
|
+
tAttachment.left = 'right';
|
646
|
+
left -= width;
|
647
|
+
eAttachment.left = 'right';
|
648
|
+
}
|
649
|
+
} else if (left + width > bounds[2] && tAttachment.left === 'right') {
|
650
|
+
if (eAttachment.left === 'left') {
|
651
|
+
left -= targetWidth;
|
652
|
+
tAttachment.left = 'left';
|
653
|
+
left -= width;
|
654
|
+
eAttachment.left = 'right';
|
655
|
+
} else if (eAttachment.left === 'right') {
|
656
|
+
left -= targetWidth;
|
657
|
+
tAttachment.left = 'left';
|
658
|
+
left += width;
|
659
|
+
eAttachment.left = 'left';
|
660
|
+
}
|
661
|
+
} else if (tAttachment.left === 'center') {
|
662
|
+
if (left + width > bounds[2] && eAttachment.left === 'left') {
|
663
|
+
left -= width;
|
664
|
+
eAttachment.left = 'right';
|
665
|
+
} else if (left < bounds[0] && eAttachment.left === 'right') {
|
666
|
+
left += width;
|
667
|
+
eAttachment.left = 'left';
|
668
|
+
}
|
669
|
+
}
|
670
|
+
|
671
|
+
return left;
|
672
|
+
}
|
673
|
+
/**
|
674
|
+
* Flip Y "together"
|
675
|
+
* @param {object} tAttachment The target attachment
|
676
|
+
* @param {object} eAttachment The element attachment
|
677
|
+
* @param {number[]} bounds Array of bounds of the format [left, top, right, bottom]
|
678
|
+
* @param {number} height
|
679
|
+
* @param targetHeight
|
680
|
+
* @param {number} top
|
681
|
+
* @private
|
682
|
+
*/
|
683
|
+
|
684
|
+
|
685
|
+
function _flipYTogether(tAttachment, eAttachment, bounds, height, targetHeight, top) {
|
686
|
+
if (tAttachment.top === 'top') {
|
687
|
+
if (eAttachment.top === 'bottom' && top < bounds[1]) {
|
688
|
+
top += targetHeight;
|
689
|
+
tAttachment.top = 'bottom';
|
690
|
+
top += height;
|
691
|
+
eAttachment.top = 'top';
|
692
|
+
} else if (eAttachment.top === 'top' && top + height > bounds[3] && top - (height - targetHeight) >= bounds[1]) {
|
693
|
+
top -= height - targetHeight;
|
694
|
+
tAttachment.top = 'bottom';
|
695
|
+
eAttachment.top = 'bottom';
|
696
|
+
}
|
697
|
+
}
|
698
|
+
|
699
|
+
if (tAttachment.top === 'bottom') {
|
700
|
+
if (eAttachment.top === 'top' && top + height > bounds[3]) {
|
701
|
+
top -= targetHeight;
|
702
|
+
tAttachment.top = 'top';
|
703
|
+
top -= height;
|
704
|
+
eAttachment.top = 'bottom';
|
705
|
+
} else if (eAttachment.top === 'bottom' && top < bounds[1] && top + (height * 2 - targetHeight) <= bounds[3]) {
|
706
|
+
top += height - targetHeight;
|
707
|
+
tAttachment.top = 'top';
|
708
|
+
eAttachment.top = 'top';
|
709
|
+
}
|
710
|
+
}
|
711
|
+
|
712
|
+
if (tAttachment.top === 'middle') {
|
713
|
+
if (top + height > bounds[3] && eAttachment.top === 'top') {
|
714
|
+
top -= height;
|
715
|
+
eAttachment.top = 'bottom';
|
716
|
+
} else if (top < bounds[1] && eAttachment.top === 'bottom') {
|
717
|
+
top += height;
|
718
|
+
eAttachment.top = 'top';
|
719
|
+
}
|
720
|
+
}
|
721
|
+
|
722
|
+
return top;
|
723
|
+
}
|
724
|
+
/**
|
725
|
+
* Get all the initial classes
|
726
|
+
* @param classes
|
727
|
+
* @param {string} classPrefix
|
728
|
+
* @param constraints
|
729
|
+
* @return {[*, *]}
|
730
|
+
* @private
|
731
|
+
*/
|
732
|
+
|
733
|
+
|
734
|
+
function _getAllClasses(classes, classPrefix, constraints) {
|
735
|
+
var allClasses = [getClass('pinned', classes, classPrefix), getClass('out-of-bounds', classes, classPrefix)];
|
736
|
+
constraints.forEach(function (constraint) {
|
737
|
+
var outOfBoundsClass = constraint.outOfBoundsClass,
|
738
|
+
pinnedClass = constraint.pinnedClass;
|
739
|
+
|
740
|
+
if (outOfBoundsClass) {
|
741
|
+
allClasses.push(outOfBoundsClass);
|
742
|
+
}
|
743
|
+
|
744
|
+
if (pinnedClass) {
|
745
|
+
allClasses.push(pinnedClass);
|
746
|
+
}
|
747
|
+
});
|
748
|
+
allClasses.forEach(function (cls) {
|
749
|
+
['left', 'top', 'right', 'bottom'].forEach(function (side) {
|
750
|
+
allClasses.push(cls + "-" + side);
|
751
|
+
});
|
752
|
+
});
|
753
|
+
return allClasses;
|
754
|
+
}
|
755
|
+
|
756
|
+
var Constraint = {
|
757
|
+
position: function position(_ref) {
|
758
|
+
var _this = this;
|
759
|
+
|
760
|
+
var top = _ref.top,
|
761
|
+
left = _ref.left,
|
762
|
+
targetAttachment = _ref.targetAttachment;
|
763
|
+
|
764
|
+
if (!this.options.constraints) {
|
765
|
+
return true;
|
766
|
+
}
|
767
|
+
|
768
|
+
var _this$cache = this.cache('element-bounds', function () {
|
769
|
+
return getBounds(_this.bodyElement, _this.element);
|
770
|
+
}),
|
771
|
+
height = _this$cache.height,
|
772
|
+
width = _this$cache.width;
|
773
|
+
|
774
|
+
if (width === 0 && height === 0 && !isUndefined(this.lastSize)) {
|
775
|
+
// Handle the item getting hidden as a result of our positioning without glitching
|
776
|
+
// the classes in and out
|
777
|
+
var _this$lastSize = this.lastSize;
|
778
|
+
width = _this$lastSize.width;
|
779
|
+
height = _this$lastSize.height;
|
780
|
+
}
|
781
|
+
|
782
|
+
var targetSize = this.cache('target-bounds', function () {
|
783
|
+
return _this.getTargetBounds();
|
784
|
+
});
|
785
|
+
var targetHeight = targetSize.height,
|
786
|
+
targetWidth = targetSize.width;
|
787
|
+
var _this$options = this.options,
|
788
|
+
classes = _this$options.classes,
|
789
|
+
classPrefix = _this$options.classPrefix;
|
790
|
+
|
791
|
+
var allClasses = _getAllClasses(classes, classPrefix, this.options.constraints);
|
792
|
+
|
793
|
+
var addClasses = [];
|
794
|
+
var tAttachment = extend({}, targetAttachment);
|
795
|
+
var eAttachment = extend({}, this.attachment);
|
796
|
+
this.options.constraints.forEach(function (constraint) {
|
797
|
+
var to = constraint.to,
|
798
|
+
attachment = constraint.attachment,
|
799
|
+
pin = constraint.pin;
|
800
|
+
|
801
|
+
if (isUndefined(attachment)) {
|
802
|
+
attachment = '';
|
803
|
+
}
|
804
|
+
|
805
|
+
var changeAttachX, changeAttachY;
|
806
|
+
|
807
|
+
if (attachment.indexOf(' ') >= 0) {
|
808
|
+
var _attachment$split = attachment.split(' ');
|
809
|
+
|
810
|
+
changeAttachY = _attachment$split[0];
|
811
|
+
changeAttachX = _attachment$split[1];
|
812
|
+
} else {
|
813
|
+
changeAttachX = changeAttachY = attachment;
|
814
|
+
}
|
815
|
+
|
816
|
+
var bounds = getBoundingRect(_this.bodyElement, _this, to);
|
817
|
+
|
818
|
+
if (changeAttachY === 'target' || changeAttachY === 'both') {
|
819
|
+
if (top < bounds[1] && tAttachment.top === 'top') {
|
820
|
+
top += targetHeight;
|
821
|
+
tAttachment.top = 'bottom';
|
822
|
+
}
|
823
|
+
|
824
|
+
if (top + height > bounds[3] && tAttachment.top === 'bottom') {
|
825
|
+
top -= targetHeight;
|
826
|
+
tAttachment.top = 'top';
|
827
|
+
}
|
828
|
+
}
|
829
|
+
|
830
|
+
if (changeAttachY === 'together') {
|
831
|
+
top = _flipYTogether(tAttachment, eAttachment, bounds, height, targetHeight, top);
|
832
|
+
}
|
833
|
+
|
834
|
+
if (changeAttachX === 'target' || changeAttachX === 'both') {
|
835
|
+
if (left < bounds[0] && tAttachment.left === 'left') {
|
836
|
+
left += targetWidth;
|
837
|
+
tAttachment.left = 'right';
|
838
|
+
}
|
839
|
+
|
840
|
+
if (left + width > bounds[2] && tAttachment.left === 'right') {
|
841
|
+
left -= targetWidth;
|
842
|
+
tAttachment.left = 'left';
|
843
|
+
}
|
844
|
+
}
|
845
|
+
|
846
|
+
if (changeAttachX === 'together') {
|
847
|
+
left = _flipXTogether(tAttachment, eAttachment, bounds, width, targetWidth, left);
|
848
|
+
}
|
849
|
+
|
850
|
+
if (changeAttachY === 'element' || changeAttachY === 'both') {
|
851
|
+
if (top < bounds[1] && eAttachment.top === 'bottom') {
|
852
|
+
top += height;
|
853
|
+
eAttachment.top = 'top';
|
854
|
+
}
|
855
|
+
|
856
|
+
if (top + height > bounds[3] && eAttachment.top === 'top') {
|
857
|
+
top -= height;
|
858
|
+
eAttachment.top = 'bottom';
|
859
|
+
}
|
860
|
+
}
|
861
|
+
|
862
|
+
if (changeAttachX === 'element' || changeAttachX === 'both') {
|
863
|
+
if (left < bounds[0]) {
|
864
|
+
if (eAttachment.left === 'right') {
|
865
|
+
left += width;
|
866
|
+
eAttachment.left = 'left';
|
867
|
+
} else if (eAttachment.left === 'center') {
|
868
|
+
left += width / 2;
|
869
|
+
eAttachment.left = 'left';
|
870
|
+
}
|
871
|
+
}
|
872
|
+
|
873
|
+
if (left + width > bounds[2]) {
|
874
|
+
if (eAttachment.left === 'left') {
|
875
|
+
left -= width;
|
876
|
+
eAttachment.left = 'right';
|
877
|
+
} else if (eAttachment.left === 'center') {
|
878
|
+
left -= width / 2;
|
879
|
+
eAttachment.left = 'right';
|
880
|
+
}
|
881
|
+
}
|
882
|
+
}
|
883
|
+
|
884
|
+
if (isString(pin)) {
|
885
|
+
pin = pin.split(',').map(function (p) {
|
886
|
+
return p.trim();
|
887
|
+
});
|
888
|
+
} else if (pin === true) {
|
889
|
+
pin = ['top', 'left', 'right', 'bottom'];
|
890
|
+
}
|
891
|
+
|
892
|
+
pin = pin || [];
|
893
|
+
var pinned = [];
|
894
|
+
var oob = [];
|
895
|
+
left = _calculateOOBAndPinnedLeft(left, bounds, width, pin, pinned, oob);
|
896
|
+
top = _calculateOOBAndPinnedTop(top, bounds, height, pin, pinned, oob);
|
897
|
+
|
898
|
+
if (pinned.length) {
|
899
|
+
var pinnedClass;
|
900
|
+
|
901
|
+
if (!isUndefined(_this.options.pinnedClass)) {
|
902
|
+
pinnedClass = _this.options.pinnedClass;
|
903
|
+
} else {
|
904
|
+
pinnedClass = getClass('pinned', classes, classPrefix);
|
905
|
+
}
|
906
|
+
|
907
|
+
addClasses.push(pinnedClass);
|
908
|
+
pinned.forEach(function (side) {
|
909
|
+
addClasses.push(pinnedClass + "-" + side);
|
910
|
+
});
|
911
|
+
}
|
912
|
+
|
913
|
+
_addOutOfBoundsClass(oob, addClasses, classes, classPrefix, _this.options.outOfBoundsClass);
|
914
|
+
|
915
|
+
if (pinned.indexOf('left') >= 0 || pinned.indexOf('right') >= 0) {
|
916
|
+
eAttachment.left = tAttachment.left = false;
|
917
|
+
}
|
918
|
+
|
919
|
+
if (pinned.indexOf('top') >= 0 || pinned.indexOf('bottom') >= 0) {
|
920
|
+
eAttachment.top = tAttachment.top = false;
|
921
|
+
}
|
922
|
+
|
923
|
+
if (tAttachment.top !== targetAttachment.top || tAttachment.left !== targetAttachment.left || eAttachment.top !== _this.attachment.top || eAttachment.left !== _this.attachment.left) {
|
924
|
+
_this.updateAttachClasses(eAttachment, tAttachment);
|
925
|
+
|
926
|
+
_this.trigger('update', {
|
927
|
+
attachment: eAttachment,
|
928
|
+
targetAttachment: tAttachment
|
929
|
+
});
|
930
|
+
}
|
931
|
+
});
|
932
|
+
defer(function () {
|
933
|
+
if (!(_this.options.addTargetClasses === false)) {
|
934
|
+
updateClasses(_this.target, addClasses, allClasses);
|
935
|
+
}
|
936
|
+
|
937
|
+
updateClasses(_this.element, addClasses, allClasses);
|
938
|
+
});
|
939
|
+
return {
|
940
|
+
top: top,
|
941
|
+
left: left
|
942
|
+
};
|
943
|
+
}
|
944
|
+
};
|
945
|
+
|
946
|
+
var Shift = {
|
947
|
+
position: function position(_ref) {
|
948
|
+
var top = _ref.top,
|
949
|
+
left = _ref.left;
|
950
|
+
|
951
|
+
if (!this.options.shift) {
|
952
|
+
return;
|
953
|
+
}
|
954
|
+
|
955
|
+
var shift = this.options.shift;
|
956
|
+
|
957
|
+
if (isFunction(shift)) {
|
958
|
+
shift = shift.call(this, {
|
959
|
+
top: top,
|
960
|
+
left: left
|
961
|
+
});
|
962
|
+
}
|
963
|
+
|
964
|
+
var shiftTop, shiftLeft;
|
965
|
+
|
966
|
+
if (isString(shift)) {
|
967
|
+
shift = shift.split(' ');
|
968
|
+
shift[1] = shift[1] || shift[0];
|
969
|
+
var _shift = shift;
|
970
|
+
shiftTop = _shift[0];
|
971
|
+
shiftLeft = _shift[1];
|
972
|
+
shiftTop = parseFloat(shiftTop, 10);
|
973
|
+
shiftLeft = parseFloat(shiftLeft, 10);
|
974
|
+
} else {
|
975
|
+
var _ref2 = [shift.top, shift.left];
|
976
|
+
shiftTop = _ref2[0];
|
977
|
+
shiftLeft = _ref2[1];
|
978
|
+
}
|
979
|
+
|
980
|
+
top += shiftTop;
|
981
|
+
left += shiftLeft;
|
982
|
+
return {
|
983
|
+
top: top,
|
984
|
+
left: left
|
985
|
+
};
|
986
|
+
}
|
987
|
+
};
|
988
|
+
|
989
|
+
var Evented = /*#__PURE__*/function () {
|
990
|
+
function Evented() {}
|
991
|
+
|
992
|
+
var _proto = Evented.prototype;
|
993
|
+
|
994
|
+
_proto.on = function on(event, handler, ctx, once) {
|
995
|
+
if (once === void 0) {
|
996
|
+
once = false;
|
997
|
+
}
|
998
|
+
|
999
|
+
if (isUndefined(this.bindings)) {
|
1000
|
+
this.bindings = {};
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
if (isUndefined(this.bindings[event])) {
|
1004
|
+
this.bindings[event] = [];
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
this.bindings[event].push({
|
1008
|
+
handler: handler,
|
1009
|
+
ctx: ctx,
|
1010
|
+
once: once
|
1011
|
+
});
|
1012
|
+
return this;
|
1013
|
+
};
|
1014
|
+
|
1015
|
+
_proto.once = function once(event, handler, ctx) {
|
1016
|
+
return this.on(event, handler, ctx, true);
|
1017
|
+
};
|
1018
|
+
|
1019
|
+
_proto.off = function off(event, handler) {
|
1020
|
+
var _this = this;
|
1021
|
+
|
1022
|
+
if (isUndefined(this.bindings) || isUndefined(this.bindings[event])) {
|
1023
|
+
return this;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
if (isUndefined(handler)) {
|
1027
|
+
delete this.bindings[event];
|
1028
|
+
} else {
|
1029
|
+
this.bindings[event].forEach(function (binding, index) {
|
1030
|
+
if (binding.handler === handler) {
|
1031
|
+
_this.bindings[event].splice(index, 1);
|
1032
|
+
}
|
1033
|
+
});
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
return this;
|
1037
|
+
};
|
1038
|
+
|
1039
|
+
_proto.trigger = function trigger(event) {
|
1040
|
+
var _this2 = this;
|
1041
|
+
|
1042
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
1043
|
+
args[_key - 1] = arguments[_key];
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
if (!isUndefined(this.bindings) && this.bindings[event]) {
|
1047
|
+
this.bindings[event].forEach(function (binding, index) {
|
1048
|
+
var ctx = binding.ctx,
|
1049
|
+
handler = binding.handler,
|
1050
|
+
once = binding.once;
|
1051
|
+
var context = ctx || _this2;
|
1052
|
+
handler.apply(context, args);
|
1053
|
+
|
1054
|
+
if (once) {
|
1055
|
+
_this2.bindings[event].splice(index, 1);
|
1056
|
+
}
|
1057
|
+
});
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
return this;
|
1061
|
+
};
|
1062
|
+
|
1063
|
+
return Evented;
|
1064
|
+
}();
|
1065
|
+
|
1066
|
+
var MIRROR_LR = {
|
1067
|
+
center: 'center',
|
1068
|
+
left: 'right',
|
1069
|
+
right: 'left'
|
1070
|
+
};
|
1071
|
+
var MIRROR_TB = {
|
1072
|
+
middle: 'middle',
|
1073
|
+
top: 'bottom',
|
1074
|
+
bottom: 'top'
|
1075
|
+
};
|
1076
|
+
var OFFSET_MAP = {
|
1077
|
+
top: 0,
|
1078
|
+
left: 0,
|
1079
|
+
middle: '50%',
|
1080
|
+
center: '50%',
|
1081
|
+
bottom: '100%',
|
1082
|
+
right: '100%'
|
1083
|
+
};
|
1084
|
+
function addOffset() {
|
1085
|
+
var out = {
|
1086
|
+
top: 0,
|
1087
|
+
left: 0
|
1088
|
+
};
|
1089
|
+
|
1090
|
+
for (var _len = arguments.length, offsets = new Array(_len), _key = 0; _key < _len; _key++) {
|
1091
|
+
offsets[_key] = arguments[_key];
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
offsets.forEach(function (_ref) {
|
1095
|
+
var top = _ref.top,
|
1096
|
+
left = _ref.left;
|
1097
|
+
|
1098
|
+
if (isString(top)) {
|
1099
|
+
top = parseFloat(top);
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
if (isString(left)) {
|
1103
|
+
left = parseFloat(left);
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
out.top += top;
|
1107
|
+
out.left += left;
|
1108
|
+
});
|
1109
|
+
return out;
|
1110
|
+
}
|
1111
|
+
function attachmentToOffset(attachment) {
|
1112
|
+
var left = attachment.left,
|
1113
|
+
top = attachment.top;
|
1114
|
+
|
1115
|
+
if (!isUndefined(OFFSET_MAP[attachment.left])) {
|
1116
|
+
left = OFFSET_MAP[attachment.left];
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
if (!isUndefined(OFFSET_MAP[attachment.top])) {
|
1120
|
+
top = OFFSET_MAP[attachment.top];
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
return {
|
1124
|
+
left: left,
|
1125
|
+
top: top
|
1126
|
+
};
|
1127
|
+
}
|
1128
|
+
function autoToFixedAttachment(attachment, relativeToAttachment) {
|
1129
|
+
var left = attachment.left,
|
1130
|
+
top = attachment.top;
|
1131
|
+
|
1132
|
+
if (left === 'auto') {
|
1133
|
+
left = MIRROR_LR[relativeToAttachment.left];
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
if (top === 'auto') {
|
1137
|
+
top = MIRROR_TB[relativeToAttachment.top];
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
return {
|
1141
|
+
left: left,
|
1142
|
+
top: top
|
1143
|
+
};
|
1144
|
+
}
|
1145
|
+
function offsetToPx(offset, size) {
|
1146
|
+
if (isString(offset.left) && offset.left.indexOf('%') !== -1) {
|
1147
|
+
offset.left = parseFloat(offset.left) / 100 * size.width;
|
1148
|
+
}
|
1149
|
+
|
1150
|
+
if (isString(offset.top) && offset.top.indexOf('%') !== -1) {
|
1151
|
+
offset.top = parseFloat(offset.top) / 100 * size.height;
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
return offset;
|
1155
|
+
}
|
1156
|
+
function parseTopLeft(value) {
|
1157
|
+
var _value$split = value.split(' '),
|
1158
|
+
top = _value$split[0],
|
1159
|
+
left = _value$split[1];
|
1160
|
+
|
1161
|
+
return {
|
1162
|
+
top: top,
|
1163
|
+
left: left
|
1164
|
+
};
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
function getScrollParents(el) {
|
1168
|
+
// In firefox if the el is inside an iframe with display: none; window.getComputedStyle() will return null;
|
1169
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=548397
|
1170
|
+
var computedStyle = getComputedStyle(el) || {};
|
1171
|
+
var position = computedStyle.position;
|
1172
|
+
var parents = [];
|
1173
|
+
|
1174
|
+
if (position === 'fixed') {
|
1175
|
+
return [el];
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
var parent = el;
|
1179
|
+
|
1180
|
+
while ((parent = parent.parentNode) && parent && parent.nodeType === 1) {
|
1181
|
+
var style = void 0;
|
1182
|
+
|
1183
|
+
try {
|
1184
|
+
style = getComputedStyle(parent);
|
1185
|
+
} catch (err) {// Intentionally blank
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
if (isUndefined(style) || style === null) {
|
1189
|
+
parents.push(parent);
|
1190
|
+
return parents;
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
var _style = style,
|
1194
|
+
overflow = _style.overflow,
|
1195
|
+
overflowX = _style.overflowX,
|
1196
|
+
overflowY = _style.overflowY;
|
1197
|
+
|
1198
|
+
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
|
1199
|
+
if (position !== 'absolute' || ['relative', 'absolute', 'fixed'].indexOf(style.position) >= 0) {
|
1200
|
+
parents.push(parent);
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
}
|
1204
|
+
|
1205
|
+
parents.push(el.ownerDocument.body); // If the node is within a frame, account for the parent window scroll
|
1206
|
+
|
1207
|
+
if (el.ownerDocument !== document) {
|
1208
|
+
parents.push(el.ownerDocument.defaultView);
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
return parents;
|
1212
|
+
}
|
1213
|
+
function getOffsetParent(el) {
|
1214
|
+
return el.offsetParent || document.documentElement;
|
1215
|
+
}
|
1216
|
+
|
1217
|
+
var TetherBase = {
|
1218
|
+
modules: [Constraint, Abutment, Shift]
|
1219
|
+
};
|
1220
|
+
|
1221
|
+
function isFullscreenElement(e) {
|
1222
|
+
var d = e.ownerDocument;
|
1223
|
+
var fe = d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement || d.msFullscreenElement;
|
1224
|
+
return fe === e;
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
function within(a, b, diff) {
|
1228
|
+
if (diff === void 0) {
|
1229
|
+
diff = 1;
|
1230
|
+
}
|
1231
|
+
|
1232
|
+
return a + diff >= b && b >= a - diff;
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
var transformKey = function () {
|
1236
|
+
if (isUndefined(document)) {
|
1237
|
+
return '';
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
var el = document.createElement('div');
|
1241
|
+
var transforms = ['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
|
1242
|
+
|
1243
|
+
for (var i = 0; i < transforms.length; ++i) {
|
1244
|
+
var key = transforms[i];
|
1245
|
+
|
1246
|
+
if (el.style[key] !== undefined) {
|
1247
|
+
return key;
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
}();
|
1251
|
+
|
1252
|
+
var tethers = [];
|
1253
|
+
|
1254
|
+
var position = function position() {
|
1255
|
+
tethers.forEach(function (tether) {
|
1256
|
+
tether.position(false);
|
1257
|
+
});
|
1258
|
+
flush();
|
1259
|
+
};
|
1260
|
+
|
1261
|
+
function now() {
|
1262
|
+
return performance.now();
|
1263
|
+
}
|
1264
|
+
|
1265
|
+
(function () {
|
1266
|
+
var lastCall = null;
|
1267
|
+
var lastDuration = null;
|
1268
|
+
var pendingTimeout = null;
|
1269
|
+
|
1270
|
+
var tick = function tick() {
|
1271
|
+
if (!isUndefined(lastDuration) && lastDuration > 16) {
|
1272
|
+
// We voluntarily throttle ourselves if we can't manage 60fps
|
1273
|
+
lastDuration = Math.min(lastDuration - 16, 250); // Just in case this is the last event, remember to position just once more
|
1274
|
+
|
1275
|
+
pendingTimeout = setTimeout(tick, 250);
|
1276
|
+
return;
|
1277
|
+
}
|
1278
|
+
|
1279
|
+
if (!isUndefined(lastCall) && now() - lastCall < 10) {
|
1280
|
+
// Some browsers call events a little too frequently, refuse to run more than is reasonable
|
1281
|
+
return;
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
if (pendingTimeout != null) {
|
1285
|
+
clearTimeout(pendingTimeout);
|
1286
|
+
pendingTimeout = null;
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
lastCall = now();
|
1290
|
+
position();
|
1291
|
+
lastDuration = now() - lastCall;
|
1292
|
+
};
|
1293
|
+
|
1294
|
+
if (!isUndefined(window) && !isUndefined(window.addEventListener)) {
|
1295
|
+
['resize', 'scroll', 'touchmove'].forEach(function (event) {
|
1296
|
+
window.addEventListener(event, tick);
|
1297
|
+
});
|
1298
|
+
}
|
1299
|
+
})();
|
1300
|
+
|
1301
|
+
var TetherClass = /*#__PURE__*/function (_Evented) {
|
1302
|
+
_inheritsLoose(TetherClass, _Evented);
|
1303
|
+
|
1304
|
+
function TetherClass(options) {
|
1305
|
+
var _this;
|
1306
|
+
|
1307
|
+
_this = _Evented.call(this) || this;
|
1308
|
+
_this.position = _this.position.bind(_assertThisInitialized(_this));
|
1309
|
+
tethers.push(_assertThisInitialized(_this));
|
1310
|
+
_this.history = [];
|
1311
|
+
|
1312
|
+
_this.setOptions(options, false);
|
1313
|
+
|
1314
|
+
TetherBase.modules.forEach(function (module) {
|
1315
|
+
if (!isUndefined(module.initialize)) {
|
1316
|
+
module.initialize.call(_assertThisInitialized(_this));
|
1317
|
+
}
|
1318
|
+
});
|
1319
|
+
|
1320
|
+
_this.position();
|
1321
|
+
|
1322
|
+
return _this;
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
var _proto = TetherClass.prototype;
|
1326
|
+
|
1327
|
+
_proto.setOptions = function setOptions(options, pos) {
|
1328
|
+
var _this2 = this;
|
1329
|
+
|
1330
|
+
if (pos === void 0) {
|
1331
|
+
pos = true;
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
var defaults = {
|
1335
|
+
offset: '0 0',
|
1336
|
+
targetOffset: '0 0',
|
1337
|
+
targetAttachment: 'auto auto',
|
1338
|
+
classPrefix: 'tether',
|
1339
|
+
bodyElement: document.body
|
1340
|
+
};
|
1341
|
+
this.options = extend(defaults, options);
|
1342
|
+
var _this$options = this.options,
|
1343
|
+
element = _this$options.element,
|
1344
|
+
target = _this$options.target,
|
1345
|
+
targetModifier = _this$options.targetModifier,
|
1346
|
+
bodyElement = _this$options.bodyElement;
|
1347
|
+
this.element = element;
|
1348
|
+
this.target = target;
|
1349
|
+
this.targetModifier = targetModifier;
|
1350
|
+
|
1351
|
+
if (typeof bodyElement === 'string') {
|
1352
|
+
bodyElement = document.querySelector(bodyElement);
|
1353
|
+
}
|
1354
|
+
|
1355
|
+
this.bodyElement = bodyElement;
|
1356
|
+
|
1357
|
+
if (this.target === 'viewport') {
|
1358
|
+
this.target = document.body;
|
1359
|
+
this.targetModifier = 'visible';
|
1360
|
+
} else if (this.target === 'scroll-handle') {
|
1361
|
+
this.target = document.body;
|
1362
|
+
this.targetModifier = 'scroll-handle';
|
1363
|
+
}
|
1364
|
+
|
1365
|
+
['element', 'target'].forEach(function (key) {
|
1366
|
+
if (isUndefined(_this2[key])) {
|
1367
|
+
throw new Error('Tether Error: Both element and target must be defined');
|
1368
|
+
}
|
1369
|
+
|
1370
|
+
if (!isUndefined(_this2[key].jquery)) {
|
1371
|
+
_this2[key] = _this2[key][0];
|
1372
|
+
} else if (isString(_this2[key])) {
|
1373
|
+
_this2[key] = document.querySelector(_this2[key]);
|
1374
|
+
}
|
1375
|
+
});
|
1376
|
+
|
1377
|
+
this._addClasses();
|
1378
|
+
|
1379
|
+
if (!this.options.attachment) {
|
1380
|
+
throw new Error('Tether Error: You must provide an attachment');
|
1381
|
+
}
|
1382
|
+
|
1383
|
+
this.targetAttachment = parseTopLeft(this.options.targetAttachment);
|
1384
|
+
this.attachment = parseTopLeft(this.options.attachment);
|
1385
|
+
this.offset = parseTopLeft(this.options.offset);
|
1386
|
+
this.targetOffset = parseTopLeft(this.options.targetOffset);
|
1387
|
+
|
1388
|
+
if (!isUndefined(this.scrollParents)) {
|
1389
|
+
this.disable();
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
if (this.targetModifier === 'scroll-handle') {
|
1393
|
+
this.scrollParents = [this.target];
|
1394
|
+
} else {
|
1395
|
+
this.scrollParents = getScrollParents(this.target);
|
1396
|
+
}
|
1397
|
+
|
1398
|
+
if (!(this.options.enabled === false)) {
|
1399
|
+
this.enable(pos);
|
1400
|
+
}
|
1401
|
+
};
|
1402
|
+
|
1403
|
+
_proto.getTargetBounds = function getTargetBounds() {
|
1404
|
+
if (!isUndefined(this.targetModifier)) {
|
1405
|
+
if (this.targetModifier === 'visible') {
|
1406
|
+
return getVisibleBounds(this.bodyElement, this.target);
|
1407
|
+
} else if (this.targetModifier === 'scroll-handle') {
|
1408
|
+
return getScrollHandleBounds(this.bodyElement, this.target);
|
1409
|
+
}
|
1410
|
+
} else {
|
1411
|
+
return getBounds(this.bodyElement, this.target);
|
1412
|
+
}
|
1413
|
+
};
|
1414
|
+
|
1415
|
+
_proto.clearCache = function clearCache() {
|
1416
|
+
this._cache = {};
|
1417
|
+
};
|
1418
|
+
|
1419
|
+
_proto.cache = function cache(k, getter) {
|
1420
|
+
// More than one module will often need the same DOM info, so
|
1421
|
+
// we keep a cache which is cleared on each position call
|
1422
|
+
if (isUndefined(this._cache)) {
|
1423
|
+
this._cache = {};
|
1424
|
+
}
|
1425
|
+
|
1426
|
+
if (isUndefined(this._cache[k])) {
|
1427
|
+
this._cache[k] = getter.call(this);
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
return this._cache[k];
|
1431
|
+
};
|
1432
|
+
|
1433
|
+
_proto.enable = function enable(pos) {
|
1434
|
+
var _this3 = this;
|
1435
|
+
|
1436
|
+
if (pos === void 0) {
|
1437
|
+
pos = true;
|
1438
|
+
}
|
1439
|
+
|
1440
|
+
var _this$options2 = this.options,
|
1441
|
+
classes = _this$options2.classes,
|
1442
|
+
classPrefix = _this$options2.classPrefix;
|
1443
|
+
|
1444
|
+
if (!(this.options.addTargetClasses === false)) {
|
1445
|
+
addClass(this.target, getClass('enabled', classes, classPrefix));
|
1446
|
+
}
|
1447
|
+
|
1448
|
+
addClass(this.element, getClass('enabled', classes, classPrefix));
|
1449
|
+
this.enabled = true;
|
1450
|
+
this.scrollParents.forEach(function (parent) {
|
1451
|
+
if (parent !== _this3.target.ownerDocument) {
|
1452
|
+
parent.addEventListener('scroll', _this3.position);
|
1453
|
+
}
|
1454
|
+
});
|
1455
|
+
|
1456
|
+
if (pos) {
|
1457
|
+
this.position();
|
1458
|
+
}
|
1459
|
+
};
|
1460
|
+
|
1461
|
+
_proto.disable = function disable() {
|
1462
|
+
var _this4 = this;
|
1463
|
+
|
1464
|
+
var _this$options3 = this.options,
|
1465
|
+
classes = _this$options3.classes,
|
1466
|
+
classPrefix = _this$options3.classPrefix;
|
1467
|
+
removeClass(this.target, getClass('enabled', classes, classPrefix));
|
1468
|
+
removeClass(this.element, getClass('enabled', classes, classPrefix));
|
1469
|
+
this.enabled = false;
|
1470
|
+
|
1471
|
+
if (!isUndefined(this.scrollParents)) {
|
1472
|
+
this.scrollParents.forEach(function (parent) {
|
1473
|
+
if (parent && parent.removeEventListener) {
|
1474
|
+
parent.removeEventListener('scroll', _this4.position);
|
1475
|
+
}
|
1476
|
+
});
|
1477
|
+
}
|
1478
|
+
};
|
1479
|
+
|
1480
|
+
_proto.destroy = function destroy() {
|
1481
|
+
var _this5 = this;
|
1482
|
+
|
1483
|
+
this.disable();
|
1484
|
+
|
1485
|
+
this._removeClasses();
|
1486
|
+
|
1487
|
+
tethers.forEach(function (tether, i) {
|
1488
|
+
if (tether === _this5) {
|
1489
|
+
tethers.splice(i, 1);
|
1490
|
+
}
|
1491
|
+
}); // Remove any elements we were using for convenience from the DOM
|
1492
|
+
|
1493
|
+
if (tethers.length === 0) {
|
1494
|
+
removeUtilElements(this.bodyElement);
|
1495
|
+
}
|
1496
|
+
};
|
1497
|
+
|
1498
|
+
_proto.updateAttachClasses = function updateAttachClasses(elementAttach, targetAttach) {
|
1499
|
+
var _this6 = this;
|
1500
|
+
|
1501
|
+
elementAttach = elementAttach || this.attachment;
|
1502
|
+
targetAttach = targetAttach || this.targetAttachment;
|
1503
|
+
var sides = ['left', 'top', 'bottom', 'right', 'middle', 'center'];
|
1504
|
+
var _this$options4 = this.options,
|
1505
|
+
classes = _this$options4.classes,
|
1506
|
+
classPrefix = _this$options4.classPrefix;
|
1507
|
+
|
1508
|
+
if (!isUndefined(this._addAttachClasses) && this._addAttachClasses.length) {
|
1509
|
+
// updateAttachClasses can be called more than once in a position call, so
|
1510
|
+
// we need to clean up after ourselves such that when the last defer gets
|
1511
|
+
// ran it doesn't add any extra classes from previous calls.
|
1512
|
+
this._addAttachClasses.splice(0, this._addAttachClasses.length);
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
if (isUndefined(this._addAttachClasses)) {
|
1516
|
+
this._addAttachClasses = [];
|
1517
|
+
}
|
1518
|
+
|
1519
|
+
this.add = this._addAttachClasses;
|
1520
|
+
|
1521
|
+
if (elementAttach.top) {
|
1522
|
+
this.add.push(getClass('element-attached', classes, classPrefix) + "-" + elementAttach.top);
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
if (elementAttach.left) {
|
1526
|
+
this.add.push(getClass('element-attached', classes, classPrefix) + "-" + elementAttach.left);
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
if (targetAttach.top) {
|
1530
|
+
this.add.push(getClass('target-attached', classes, classPrefix) + "-" + targetAttach.top);
|
1531
|
+
}
|
1532
|
+
|
1533
|
+
if (targetAttach.left) {
|
1534
|
+
this.add.push(getClass('target-attached', classes, classPrefix) + "-" + targetAttach.left);
|
1535
|
+
}
|
1536
|
+
|
1537
|
+
this.all = [];
|
1538
|
+
sides.forEach(function (side) {
|
1539
|
+
_this6.all.push(getClass('element-attached', classes, classPrefix) + "-" + side);
|
1540
|
+
|
1541
|
+
_this6.all.push(getClass('target-attached', classes, classPrefix) + "-" + side);
|
1542
|
+
});
|
1543
|
+
defer(function () {
|
1544
|
+
if (isUndefined(_this6._addAttachClasses)) {
|
1545
|
+
return;
|
1546
|
+
}
|
1547
|
+
|
1548
|
+
updateClasses(_this6.element, _this6._addAttachClasses, _this6.all);
|
1549
|
+
|
1550
|
+
if (!(_this6.options.addTargetClasses === false)) {
|
1551
|
+
updateClasses(_this6.target, _this6._addAttachClasses, _this6.all);
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
delete _this6._addAttachClasses;
|
1555
|
+
});
|
1556
|
+
};
|
1557
|
+
|
1558
|
+
_proto.position = function position(flushChanges) {
|
1559
|
+
var _this7 = this;
|
1560
|
+
|
1561
|
+
if (flushChanges === void 0) {
|
1562
|
+
flushChanges = true;
|
1563
|
+
}
|
1564
|
+
|
1565
|
+
// flushChanges commits the changes immediately, leave true unless you are positioning multiple
|
1566
|
+
// tethers (in which case call Tether.Utils.flush yourself when you're done)
|
1567
|
+
if (!this.enabled) {
|
1568
|
+
return;
|
1569
|
+
}
|
1570
|
+
|
1571
|
+
this.clearCache(); // Turn 'auto' attachments into the appropriate corner or edge
|
1572
|
+
|
1573
|
+
var targetAttachment = autoToFixedAttachment(this.targetAttachment, this.attachment);
|
1574
|
+
this.updateAttachClasses(this.attachment, targetAttachment);
|
1575
|
+
var elementPos = this.cache('element-bounds', function () {
|
1576
|
+
return getBounds(_this7.bodyElement, _this7.element);
|
1577
|
+
});
|
1578
|
+
var width = elementPos.width,
|
1579
|
+
height = elementPos.height;
|
1580
|
+
|
1581
|
+
if (width === 0 && height === 0 && !isUndefined(this.lastSize)) {
|
1582
|
+
// We cache the height and width to make it possible to position elements that are
|
1583
|
+
// getting hidden.
|
1584
|
+
var _this$lastSize = this.lastSize;
|
1585
|
+
width = _this$lastSize.width;
|
1586
|
+
height = _this$lastSize.height;
|
1587
|
+
} else {
|
1588
|
+
this.lastSize = {
|
1589
|
+
width: width,
|
1590
|
+
height: height
|
1591
|
+
};
|
1592
|
+
}
|
1593
|
+
|
1594
|
+
var targetPos = this.cache('target-bounds', function () {
|
1595
|
+
return _this7.getTargetBounds();
|
1596
|
+
});
|
1597
|
+
var targetSize = targetPos; // Get an actual px offset from the attachment
|
1598
|
+
|
1599
|
+
var offset = offsetToPx(attachmentToOffset(this.attachment), {
|
1600
|
+
width: width,
|
1601
|
+
height: height
|
1602
|
+
});
|
1603
|
+
var targetOffset = offsetToPx(attachmentToOffset(targetAttachment), targetSize);
|
1604
|
+
var manualOffset = offsetToPx(this.offset, {
|
1605
|
+
width: width,
|
1606
|
+
height: height
|
1607
|
+
});
|
1608
|
+
var manualTargetOffset = offsetToPx(this.targetOffset, targetSize); // Add the manually provided offset
|
1609
|
+
|
1610
|
+
offset = addOffset(offset, manualOffset);
|
1611
|
+
targetOffset = addOffset(targetOffset, manualTargetOffset); // It's now our goal to make (element position + offset) == (target position + target offset)
|
1612
|
+
|
1613
|
+
var left = targetPos.left + targetOffset.left - offset.left;
|
1614
|
+
var top = targetPos.top + targetOffset.top - offset.top;
|
1615
|
+
|
1616
|
+
for (var i = 0; i < TetherBase.modules.length; ++i) {
|
1617
|
+
var module = TetherBase.modules[i];
|
1618
|
+
var ret = module.position.call(this, {
|
1619
|
+
left: left,
|
1620
|
+
top: top,
|
1621
|
+
targetAttachment: targetAttachment,
|
1622
|
+
targetPos: targetPos,
|
1623
|
+
elementPos: elementPos,
|
1624
|
+
offset: offset,
|
1625
|
+
targetOffset: targetOffset,
|
1626
|
+
manualOffset: manualOffset,
|
1627
|
+
manualTargetOffset: manualTargetOffset,
|
1628
|
+
scrollbarSize: scrollbarSize,
|
1629
|
+
attachment: this.attachment
|
1630
|
+
});
|
1631
|
+
|
1632
|
+
if (ret === false) {
|
1633
|
+
return false;
|
1634
|
+
} else if (isUndefined(ret) || !isObject(ret)) {
|
1635
|
+
continue;
|
1636
|
+
} else {
|
1637
|
+
top = ret.top;
|
1638
|
+
left = ret.left;
|
1639
|
+
}
|
1640
|
+
} // We describe the position three different ways to give the optimizer
|
1641
|
+
// a chance to decide the best possible way to position the element
|
1642
|
+
// with the fewest repaints.
|
1643
|
+
|
1644
|
+
|
1645
|
+
var next = {
|
1646
|
+
// It's position relative to the page (absolute positioning when
|
1647
|
+
// the element is a child of the body)
|
1648
|
+
page: {
|
1649
|
+
top: top,
|
1650
|
+
left: left
|
1651
|
+
},
|
1652
|
+
// It's position relative to the viewport (fixed positioning)
|
1653
|
+
viewport: {
|
1654
|
+
top: top - pageYOffset,
|
1655
|
+
bottom: pageYOffset - top - height + innerHeight,
|
1656
|
+
left: left - pageXOffset,
|
1657
|
+
right: pageXOffset - left - width + innerWidth
|
1658
|
+
}
|
1659
|
+
};
|
1660
|
+
var doc = this.target.ownerDocument;
|
1661
|
+
var win = doc.defaultView;
|
1662
|
+
var scrollbarSize;
|
1663
|
+
|
1664
|
+
if (win.innerHeight > doc.documentElement.clientHeight) {
|
1665
|
+
scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
|
1666
|
+
next.viewport.bottom -= scrollbarSize.height;
|
1667
|
+
}
|
1668
|
+
|
1669
|
+
if (win.innerWidth > doc.documentElement.clientWidth) {
|
1670
|
+
scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
|
1671
|
+
next.viewport.right -= scrollbarSize.width;
|
1672
|
+
}
|
1673
|
+
|
1674
|
+
if (['', 'static'].indexOf(doc.body.style.position) === -1 || ['', 'static'].indexOf(doc.body.parentElement.style.position) === -1) {
|
1675
|
+
// Absolute positioning in the body will be relative to the page, not the 'initial containing block'
|
1676
|
+
next.page.bottom = doc.body.scrollHeight - top - height;
|
1677
|
+
next.page.right = doc.body.scrollWidth - left - width;
|
1678
|
+
}
|
1679
|
+
|
1680
|
+
if (!isUndefined(this.options.optimizations) && this.options.optimizations.moveElement !== false && isUndefined(this.targetModifier)) {
|
1681
|
+
var offsetParent = this.cache('target-offsetparent', function () {
|
1682
|
+
return getOffsetParent(_this7.target);
|
1683
|
+
});
|
1684
|
+
var offsetPosition = this.cache('target-offsetparent-bounds', function () {
|
1685
|
+
return getBounds(_this7.bodyElement, offsetParent);
|
1686
|
+
});
|
1687
|
+
var offsetParentStyle = getComputedStyle(offsetParent);
|
1688
|
+
var offsetParentSize = offsetPosition;
|
1689
|
+
var offsetBorder = {};
|
1690
|
+
['Top', 'Left', 'Bottom', 'Right'].forEach(function (side) {
|
1691
|
+
offsetBorder[side.toLowerCase()] = parseFloat(offsetParentStyle["border" + side + "Width"]);
|
1692
|
+
});
|
1693
|
+
offsetPosition.right = doc.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
|
1694
|
+
offsetPosition.bottom = doc.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
|
1695
|
+
|
1696
|
+
if (next.page.top >= offsetPosition.top + offsetBorder.top && next.page.bottom >= offsetPosition.bottom) {
|
1697
|
+
if (next.page.left >= offsetPosition.left + offsetBorder.left && next.page.right >= offsetPosition.right) {
|
1698
|
+
// We're within the visible part of the target's scroll parent
|
1699
|
+
var scrollLeft = offsetParent.scrollLeft,
|
1700
|
+
scrollTop = offsetParent.scrollTop; // It's position relative to the target's offset parent (absolute positioning when
|
1701
|
+
// the element is moved to be a child of the target's offset parent).
|
1702
|
+
|
1703
|
+
next.offset = {
|
1704
|
+
top: next.page.top - offsetPosition.top + scrollTop - offsetBorder.top,
|
1705
|
+
left: next.page.left - offsetPosition.left + scrollLeft - offsetBorder.left
|
1706
|
+
};
|
1707
|
+
}
|
1708
|
+
}
|
1709
|
+
} // We could also travel up the DOM and try each containing context, rather than only
|
1710
|
+
// looking at the body, but we're gonna get diminishing returns.
|
1711
|
+
|
1712
|
+
|
1713
|
+
this.move(next);
|
1714
|
+
this.history.unshift(next);
|
1715
|
+
|
1716
|
+
if (this.history.length > 3) {
|
1717
|
+
this.history.pop();
|
1718
|
+
}
|
1719
|
+
|
1720
|
+
if (flushChanges) {
|
1721
|
+
flush();
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
return true;
|
1725
|
+
} // THE ISSUE
|
1726
|
+
;
|
1727
|
+
|
1728
|
+
_proto.move = function move(pos) {
|
1729
|
+
var _this8 = this;
|
1730
|
+
|
1731
|
+
if (isUndefined(this.element.parentNode)) {
|
1732
|
+
return;
|
1733
|
+
}
|
1734
|
+
|
1735
|
+
var same = {};
|
1736
|
+
|
1737
|
+
for (var type in pos) {
|
1738
|
+
same[type] = {};
|
1739
|
+
|
1740
|
+
for (var key in pos[type]) {
|
1741
|
+
var found = false;
|
1742
|
+
|
1743
|
+
for (var i = 0; i < this.history.length; ++i) {
|
1744
|
+
var point = this.history[i];
|
1745
|
+
|
1746
|
+
if (!isUndefined(point[type]) && !within(point[type][key], pos[type][key])) {
|
1747
|
+
found = true;
|
1748
|
+
break;
|
1749
|
+
}
|
1750
|
+
}
|
1751
|
+
|
1752
|
+
if (!found) {
|
1753
|
+
same[type][key] = true;
|
1754
|
+
}
|
1755
|
+
}
|
1756
|
+
}
|
1757
|
+
|
1758
|
+
var css = {
|
1759
|
+
top: '',
|
1760
|
+
left: '',
|
1761
|
+
right: '',
|
1762
|
+
bottom: ''
|
1763
|
+
};
|
1764
|
+
|
1765
|
+
var transcribe = function transcribe(_same, _pos) {
|
1766
|
+
var hasOptimizations = !isUndefined(_this8.options.optimizations);
|
1767
|
+
var gpu = hasOptimizations ? _this8.options.optimizations.gpu : null;
|
1768
|
+
|
1769
|
+
if (gpu !== false) {
|
1770
|
+
var yPos, xPos;
|
1771
|
+
|
1772
|
+
if (_same.top) {
|
1773
|
+
css.top = 0;
|
1774
|
+
yPos = _pos.top;
|
1775
|
+
} else {
|
1776
|
+
css.bottom = 0;
|
1777
|
+
yPos = -_pos.bottom;
|
1778
|
+
}
|
1779
|
+
|
1780
|
+
if (_same.left) {
|
1781
|
+
css.left = 0;
|
1782
|
+
xPos = _pos.left;
|
1783
|
+
} else {
|
1784
|
+
css.right = 0;
|
1785
|
+
xPos = -_pos.right;
|
1786
|
+
}
|
1787
|
+
|
1788
|
+
if (isNumber(window.devicePixelRatio) && devicePixelRatio % 1 === 0) {
|
1789
|
+
xPos = Math.round(xPos * devicePixelRatio) / devicePixelRatio;
|
1790
|
+
yPos = Math.round(yPos * devicePixelRatio) / devicePixelRatio;
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
css[transformKey] = "translateX(" + xPos + "px) translateY(" + yPos + "px)";
|
1794
|
+
|
1795
|
+
if (transformKey !== 'msTransform') {
|
1796
|
+
// The Z transform will keep this in the GPU (faster, and prevents artifacts),
|
1797
|
+
// but IE9 doesn't support 3d transforms and will choke.
|
1798
|
+
css[transformKey] += ' translateZ(0)';
|
1799
|
+
}
|
1800
|
+
} else {
|
1801
|
+
if (_same.top) {
|
1802
|
+
css.top = _pos.top + "px";
|
1803
|
+
} else {
|
1804
|
+
css.bottom = _pos.bottom + "px";
|
1805
|
+
}
|
1806
|
+
|
1807
|
+
if (_same.left) {
|
1808
|
+
css.left = _pos.left + "px";
|
1809
|
+
} else {
|
1810
|
+
css.right = _pos.right + "px";
|
1811
|
+
}
|
1812
|
+
}
|
1813
|
+
};
|
1814
|
+
|
1815
|
+
var hasOptimizations = !isUndefined(this.options.optimizations);
|
1816
|
+
var allowPositionFixed = true;
|
1817
|
+
|
1818
|
+
if (hasOptimizations && this.options.optimizations.allowPositionFixed === false) {
|
1819
|
+
allowPositionFixed = false;
|
1820
|
+
}
|
1821
|
+
|
1822
|
+
var moved = false;
|
1823
|
+
|
1824
|
+
if ((same.page.top || same.page.bottom) && (same.page.left || same.page.right)) {
|
1825
|
+
css.position = 'absolute';
|
1826
|
+
transcribe(same.page, pos.page);
|
1827
|
+
} else if (allowPositionFixed && (same.viewport.top || same.viewport.bottom) && (same.viewport.left || same.viewport.right)) {
|
1828
|
+
css.position = 'fixed';
|
1829
|
+
transcribe(same.viewport, pos.viewport);
|
1830
|
+
} else if (!isUndefined(same.offset) && same.offset.top && same.offset.left) {
|
1831
|
+
css.position = 'absolute';
|
1832
|
+
var offsetParent = this.cache('target-offsetparent', function () {
|
1833
|
+
return getOffsetParent(_this8.target);
|
1834
|
+
});
|
1835
|
+
|
1836
|
+
if (getOffsetParent(this.element) !== offsetParent) {
|
1837
|
+
defer(function () {
|
1838
|
+
_this8.element.parentNode.removeChild(_this8.element);
|
1839
|
+
|
1840
|
+
offsetParent.appendChild(_this8.element);
|
1841
|
+
});
|
1842
|
+
}
|
1843
|
+
|
1844
|
+
transcribe(same.offset, pos.offset);
|
1845
|
+
moved = true;
|
1846
|
+
} else {
|
1847
|
+
css.position = 'absolute';
|
1848
|
+
transcribe({
|
1849
|
+
top: true,
|
1850
|
+
left: true
|
1851
|
+
}, pos.page);
|
1852
|
+
}
|
1853
|
+
|
1854
|
+
if (!moved) {
|
1855
|
+
if (this.options.bodyElement) {
|
1856
|
+
if (this.element.parentNode !== this.options.bodyElement) {
|
1857
|
+
this.options.bodyElement.appendChild(this.element);
|
1858
|
+
}
|
1859
|
+
} else {
|
1860
|
+
var offsetParentIsBody = true;
|
1861
|
+
var currentNode = this.element.parentNode;
|
1862
|
+
|
1863
|
+
while (currentNode && currentNode.nodeType === 1 && currentNode.tagName !== 'BODY' && !isFullscreenElement(currentNode)) {
|
1864
|
+
if (getComputedStyle(currentNode).position !== 'static') {
|
1865
|
+
offsetParentIsBody = false;
|
1866
|
+
break;
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
currentNode = currentNode.parentNode;
|
1870
|
+
}
|
1871
|
+
|
1872
|
+
if (!offsetParentIsBody) {
|
1873
|
+
this.element.parentNode.removeChild(this.element);
|
1874
|
+
this.element.ownerDocument.body.appendChild(this.element);
|
1875
|
+
}
|
1876
|
+
}
|
1877
|
+
} // Any css change will trigger a repaint, so let's avoid one if nothing changed
|
1878
|
+
|
1879
|
+
|
1880
|
+
var writeCSS = {};
|
1881
|
+
var write = false;
|
1882
|
+
|
1883
|
+
for (var _key in css) {
|
1884
|
+
var val = css[_key];
|
1885
|
+
var elVal = this.element.style[_key];
|
1886
|
+
|
1887
|
+
if (elVal !== val) {
|
1888
|
+
write = true;
|
1889
|
+
writeCSS[_key] = val;
|
1890
|
+
}
|
1891
|
+
}
|
1892
|
+
|
1893
|
+
if (write) {
|
1894
|
+
defer(function () {
|
1895
|
+
extend(_this8.element.style, writeCSS);
|
1896
|
+
|
1897
|
+
_this8.trigger('repositioned');
|
1898
|
+
});
|
1899
|
+
}
|
1900
|
+
};
|
1901
|
+
|
1902
|
+
_proto._addClasses = function _addClasses() {
|
1903
|
+
var _this$options5 = this.options,
|
1904
|
+
classes = _this$options5.classes,
|
1905
|
+
classPrefix = _this$options5.classPrefix;
|
1906
|
+
addClass(this.element, getClass('element', classes, classPrefix));
|
1907
|
+
|
1908
|
+
if (!(this.options.addTargetClasses === false)) {
|
1909
|
+
addClass(this.target, getClass('target', classes, classPrefix));
|
1910
|
+
}
|
1911
|
+
};
|
1912
|
+
|
1913
|
+
_proto._removeClasses = function _removeClasses() {
|
1914
|
+
var _this9 = this;
|
1915
|
+
|
1916
|
+
var _this$options6 = this.options,
|
1917
|
+
classes = _this$options6.classes,
|
1918
|
+
classPrefix = _this$options6.classPrefix;
|
1919
|
+
removeClass(this.element, getClass('element', classes, classPrefix));
|
1920
|
+
|
1921
|
+
if (!(this.options.addTargetClasses === false)) {
|
1922
|
+
removeClass(this.target, getClass('target', classes, classPrefix));
|
1923
|
+
}
|
1924
|
+
|
1925
|
+
this.all.forEach(function (className) {
|
1926
|
+
_this9.element.classList.remove(className);
|
1927
|
+
|
1928
|
+
_this9.target.classList.remove(className);
|
1929
|
+
});
|
1930
|
+
};
|
1931
|
+
|
1932
|
+
return TetherClass;
|
1933
|
+
}(Evented);
|
1934
|
+
|
1935
|
+
TetherClass.modules = [];
|
1936
|
+
TetherBase.position = position;
|
1937
|
+
var Tether = extend(TetherClass, TetherBase);
|
1938
|
+
Tether.modules.push({
|
1939
|
+
initialize: function initialize() {
|
1940
|
+
var _this10 = this;
|
1941
|
+
|
1942
|
+
var _this$options7 = this.options,
|
1943
|
+
classes = _this$options7.classes,
|
1944
|
+
classPrefix = _this$options7.classPrefix;
|
1945
|
+
this.markers = {};
|
1946
|
+
['target', 'element'].forEach(function (type) {
|
1947
|
+
var el = document.createElement('div');
|
1948
|
+
el.className = getClass(type + "-marker", classes, classPrefix);
|
1949
|
+
var dot = document.createElement('div');
|
1950
|
+
dot.className = getClass('marker-dot', classes, classPrefix);
|
1951
|
+
el.appendChild(dot);
|
1952
|
+
|
1953
|
+
_this10[type].appendChild(el);
|
1954
|
+
|
1955
|
+
_this10.markers[type] = {
|
1956
|
+
dot: dot,
|
1957
|
+
el: el
|
1958
|
+
};
|
1959
|
+
});
|
1960
|
+
},
|
1961
|
+
position: function position(_ref) {
|
1962
|
+
var manualOffset = _ref.manualOffset,
|
1963
|
+
manualTargetOffset = _ref.manualTargetOffset;
|
1964
|
+
var offsets = {
|
1965
|
+
element: manualOffset,
|
1966
|
+
target: manualTargetOffset
|
1967
|
+
};
|
1968
|
+
|
1969
|
+
for (var type in offsets) {
|
1970
|
+
var offset = offsets[type];
|
1971
|
+
|
1972
|
+
for (var side in offset) {
|
1973
|
+
var _this$markers$type$do;
|
1974
|
+
|
1975
|
+
var val = offset[side];
|
1976
|
+
|
1977
|
+
if (!isString(val) || val.indexOf('%') === -1 && val.indexOf('px') === -1) {
|
1978
|
+
val += 'px';
|
1979
|
+
}
|
1980
|
+
|
1981
|
+
if (this.markers[type] && ((_this$markers$type$do = this.markers[type].dot) == null ? void 0 : _this$markers$type$do.style[side]) !== val) {
|
1982
|
+
this.markers[type].dot.style[side] = val;
|
1983
|
+
}
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
|
1987
|
+
return true;
|
1988
|
+
}
|
1989
|
+
});
|
1990
|
+
|
1991
|
+
return Tether;
|
1992
|
+
|
1993
|
+
})));
|
1994
|
+
//# sourceMappingURL=tether.js.map
|