lavanda-tether 1.4.3

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