rails-assets-tether 1.1.1

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