4 (function(root, factory) {
5 if (typeof define === 'function' && define.amd) {
7 } else if (typeof exports === 'object') {
8 module.exports = factory(require,exports,module);
10 root.Tether = factory();
12 }(this, function(require,exports,module) {
15 var Evented, addClass, defer, deferred, extend, flush, getBounds, getOffsetParent, getOrigin, getScrollBarSize, getScrollParent, hasClass, node, removeClass, uniqueId, updateClasses, zeroPosCache,
16 __hasProp = {}.hasOwnProperty,
17 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
20 if (this.Tether == null) {
26 getScrollParent = function(el) {
27 var parent, position, scrollParent, style, _ref;
28 position = getComputedStyle(el).position;
29 if (position === 'fixed') {
32 scrollParent = void 0;
34 while (parent = parent.parentNode) {
36 style = getComputedStyle(parent);
41 if (/(auto|scroll)/.test(style['overflow'] + style['overflow-y'] + style['overflow-x'])) {
42 if (position !== 'absolute' || ((_ref = style['position']) === 'relative' || _ref === 'absolute' || _ref === 'fixed')) {
50 uniqueId = (function() {
60 getOrigin = function(doc) {
61 var id, k, node, v, _ref;
62 node = doc._tetherZeroElement;
64 node = doc.createElement('div');
65 node.setAttribute('data-tether-id', uniqueId());
71 doc.body.appendChild(node);
72 doc._tetherZeroElement = node;
74 id = node.getAttribute('data-tether-id');
75 if (zeroPosCache[id] == null) {
76 zeroPosCache[id] = {};
77 _ref = node.getBoundingClientRect();
80 zeroPosCache[id][k] = v;
83 return zeroPosCache[id] = void 0;
86 return zeroPosCache[id];
91 getBounds = function(el) {
92 var box, doc, docEl, k, origin, v, _ref;
93 if (el === document) {
95 el = document.documentElement;
97 doc = el.ownerDocument;
99 docEl = doc.documentElement;
101 _ref = el.getBoundingClientRect();
106 origin = getOrigin(doc);
107 box.top -= origin.top;
108 box.left -= origin.left;
109 if (box.width == null) {
110 box.width = document.body.scrollWidth - box.left - box.right;
112 if (box.height == null) {
113 box.height = document.body.scrollHeight - box.top - box.bottom;
115 box.top = box.top - docEl.clientTop;
116 box.left = box.left - docEl.clientLeft;
117 box.right = doc.body.clientWidth - box.width - box.left;
118 box.bottom = doc.body.clientHeight - box.height - box.top;
122 getOffsetParent = function(el) {
123 return el.offsetParent || document.documentElement;
126 getScrollBarSize = function() {
127 var inner, outer, width, widthContained, widthScroll;
128 inner = document.createElement('div');
129 inner.style.width = '100%';
130 inner.style.height = '200px';
131 outer = document.createElement('div');
132 extend(outer.style, {
133 position: 'absolute',
136 pointerEvents: 'none',
137 visibility: 'hidden',
142 outer.appendChild(inner);
143 document.body.appendChild(outer);
144 widthContained = inner.offsetWidth;
145 outer.style.overflow = 'scroll';
146 widthScroll = inner.offsetWidth;
147 if (widthContained === widthScroll) {
148 widthScroll = outer.clientWidth;
150 document.body.removeChild(outer);
151 width = widthContained - widthScroll;
158 extend = function(out) {
159 var args, key, obj, val, _i, _len, _ref;
164 Array.prototype.push.apply(args, arguments);
165 _ref = args.slice(1);
166 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
170 if (!__hasProp.call(obj, key)) continue;
179 removeClass = function(el, name) {
180 var cls, _i, _len, _ref, _results;
181 if (el.classList != null) {
182 _ref = name.split(' ');
184 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
187 _results.push(el.classList.remove(cls));
192 return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
196 addClass = function(el, name) {
197 var cls, _i, _len, _ref, _results;
198 if (el.classList != null) {
199 _ref = name.split(' ');
201 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
204 _results.push(el.classList.add(cls));
209 removeClass(el, name);
210 return el.className += " " + name;
214 hasClass = function(el, name) {
215 if (el.classList != null) {
216 return el.classList.contains(name);
218 return new RegExp("(^| )" + name + "( |$)", 'gi').test(el.className);
222 updateClasses = function(el, add, all) {
223 var cls, _i, _j, _len, _len1, _results;
224 for (_i = 0, _len = all.length; _i < _len; _i++) {
226 if (__indexOf.call(add, cls) < 0) {
227 if (hasClass(el, cls)) {
228 removeClass(el, cls);
233 for (_j = 0, _len1 = add.length; _j < _len1; _j++) {
235 if (!hasClass(el, cls)) {
236 _results.push(addClass(el, cls));
238 _results.push(void 0);
246 defer = function(fn) {
247 return deferred.push(fn);
253 while (fn = deferred.pop()) {
259 Evented = (function() {
260 function Evented() {}
262 Evented.prototype.on = function(event, handler, ctx, once) {
267 if (this.bindings == null) {
270 if ((_base = this.bindings)[event] == null) {
273 return this.bindings[event].push({
280 Evented.prototype.once = function(event, handler, ctx) {
281 return this.on(event, handler, ctx, true);
284 Evented.prototype.off = function(event, handler) {
285 var i, _ref, _results;
286 if (((_ref = this.bindings) != null ? _ref[event] : void 0) == null) {
289 if (handler == null) {
290 return delete this.bindings[event];
294 while (i < this.bindings[event].length) {
295 if (this.bindings[event][i].handler === handler) {
296 _results.push(this.bindings[event].splice(i, 1));
305 Evented.prototype.trigger = function() {
306 var args, ctx, event, handler, i, once, _ref, _ref1, _results;
307 event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
308 if ((_ref = this.bindings) != null ? _ref[event] : void 0) {
311 while (i < this.bindings[event].length) {
312 _ref1 = this.bindings[event][i], handler = _ref1.handler, ctx = _ref1.ctx, once = _ref1.once;
313 handler.apply(ctx != null ? ctx : this, args);
315 _results.push(this.bindings[event].splice(i, 1));
328 this.Tether.Utils = {
329 getScrollParent: getScrollParent,
330 getBounds: getBounds,
331 getOffsetParent: getOffsetParent,
334 removeClass: removeClass,
336 updateClasses: updateClasses,
341 getScrollBarSize: getScrollBarSize
347 var MIRROR_LR, MIRROR_TB, OFFSET_MAP, Tether, addClass, addOffset, attachmentToOffset, autoToFixedAttachment, defer, extend, flush, getBounds, getOffsetParent, getOuterSize, getScrollBarSize, getScrollParent, getSize, now, offsetToPx, parseAttachment, parseOffset, position, removeClass, tethers, transformKey, updateClasses, within, _Tether, _ref,
349 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
351 if (this.Tether == null) {
352 throw new Error("You must include the utils.js file before tether.js");
355 Tether = this.Tether;
357 _ref = Tether.Utils, getScrollParent = _ref.getScrollParent, getSize = _ref.getSize, getOuterSize = _ref.getOuterSize, getBounds = _ref.getBounds, getOffsetParent = _ref.getOffsetParent, extend = _ref.extend, addClass = _ref.addClass, removeClass = _ref.removeClass, updateClasses = _ref.updateClasses, defer = _ref.defer, flush = _ref.flush, getScrollBarSize = _ref.getScrollBarSize;
359 within = function(a, b, diff) {
363 return (a + diff >= b && b >= a - diff);
366 transformKey = (function() {
367 var el, key, _i, _len, _ref1;
368 el = document.createElement('div');
369 _ref1 = ['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
370 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
372 if (el.style[key] !== void 0) {
380 position = function() {
381 var tether, _i, _len;
382 for (_i = 0, _len = tethers.length; _i < _len; _i++) {
383 tether = tethers[_i];
384 tether.position(false);
391 return (_ref1 = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref1 : +(new Date);
395 var event, lastCall, lastDuration, pendingTimeout, tick, _i, _len, _ref1, _results;
398 pendingTimeout = null;
400 if ((lastDuration != null) && lastDuration > 16) {
401 lastDuration = Math.min(lastDuration - 16, 250);
402 pendingTimeout = setTimeout(tick, 250);
405 if ((lastCall != null) && (now() - lastCall) < 10) {
408 if (pendingTimeout != null) {
409 clearTimeout(pendingTimeout);
410 pendingTimeout = null;
414 return lastDuration = now() - lastCall;
416 _ref1 = ['resize', 'scroll', 'touchmove'];
418 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
420 _results.push(window.addEventListener(event, tick));
446 autoToFixedAttachment = function(attachment, relativeToAttachment) {
448 left = attachment.left, top = attachment.top;
449 if (left === 'auto') {
450 left = MIRROR_LR[relativeToAttachment.left];
452 if (top === 'auto') {
453 top = MIRROR_TB[relativeToAttachment.top];
461 attachmentToOffset = function(attachment) {
464 left: (_ref1 = OFFSET_MAP[attachment.left]) != null ? _ref1 : attachment.left,
465 top: (_ref2 = OFFSET_MAP[attachment.top]) != null ? _ref2 : attachment.top
469 addOffset = function() {
470 var left, offsets, out, top, _i, _len, _ref1;
471 offsets = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
476 for (_i = 0, _len = offsets.length; _i < _len; _i++) {
477 _ref1 = offsets[_i], top = _ref1.top, left = _ref1.left;
478 if (typeof top === 'string') {
479 top = parseFloat(top, 10);
481 if (typeof left === 'string') {
482 left = parseFloat(left, 10);
490 offsetToPx = function(offset, size) {
491 if (typeof offset.left === 'string' && offset.left.indexOf('%') !== -1) {
492 offset.left = parseFloat(offset.left, 10) / 100 * size.width;
494 if (typeof offset.top === 'string' && offset.top.indexOf('%') !== -1) {
495 offset.top = parseFloat(offset.top, 10) / 100 * size.height;
500 parseAttachment = parseOffset = function(value) {
501 var left, top, _ref1;
502 _ref1 = value.split(' '), top = _ref1[0], left = _ref1[1];
509 _Tether = (function() {
510 _Tether.modules = [];
512 function _Tether(options) {
513 this.position = __bind(this.position, this);
514 var module, _i, _len, _ref1, _ref2;
517 this.setOptions(options, false);
518 _ref1 = Tether.modules;
519 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
521 if ((_ref2 = module.initialize) != null) {
528 _Tether.prototype.getClass = function(key) {
530 if ((_ref1 = this.options.classes) != null ? _ref1[key] : void 0) {
531 return this.options.classes[key];
532 } else if (((_ref2 = this.options.classes) != null ? _ref2[key] : void 0) !== false) {
533 if (this.options.classPrefix) {
534 return "" + this.options.classPrefix + "-" + key;
543 _Tether.prototype.setOptions = function(options, position) {
544 var defaults, key, _i, _len, _ref1, _ref2;
545 this.options = options;
546 if (position == null) {
552 targetAttachment: 'auto auto',
553 classPrefix: 'tether'
555 this.options = extend(defaults, this.options);
556 _ref1 = this.options, this.element = _ref1.element, this.target = _ref1.target, this.targetModifier = _ref1.targetModifier;
557 if (this.target === 'viewport') {
558 this.target = document.body;
559 this.targetModifier = 'visible';
560 } else if (this.target === 'scroll-handle') {
561 this.target = document.body;
562 this.targetModifier = 'scroll-handle';
564 _ref2 = ['element', 'target'];
565 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
567 if (this[key] == null) {
568 throw new Error("Tether Error: Both element and target must be defined");
570 if (this[key].jquery != null) {
571 this[key] = this[key][0];
572 } else if (typeof this[key] === 'string') {
573 this[key] = document.querySelector(this[key]);
576 addClass(this.element, this.getClass('element'));
577 addClass(this.target, this.getClass('target'));
578 if (!this.options.attachment) {
579 throw new Error("Tether Error: You must provide an attachment");
581 this.targetAttachment = parseAttachment(this.options.targetAttachment);
582 this.attachment = parseAttachment(this.options.attachment);
583 this.offset = parseOffset(this.options.offset);
584 this.targetOffset = parseOffset(this.options.targetOffset);
585 if (this.scrollParent != null) {
588 if (this.targetModifier === 'scroll-handle') {
589 this.scrollParent = this.target;
591 this.scrollParent = getScrollParent(this.target);
593 if (this.options.enabled !== false) {
594 return this.enable(position);
598 _Tether.prototype.getTargetBounds = function() {
599 var bounds, fitAdj, hasBottomScroll, height, out, scrollBottom, scrollPercentage, style, target;
600 if (this.targetModifier != null) {
601 switch (this.targetModifier) {
603 if (this.target === document.body) {
611 bounds = getBounds(this.target);
613 height: bounds.height,
618 out.height = Math.min(out.height, bounds.height - (pageYOffset - bounds.top));
619 out.height = Math.min(out.height, bounds.height - ((bounds.top + bounds.height) - (pageYOffset + innerHeight)));
620 out.height = Math.min(innerHeight, out.height);
622 out.width = Math.min(out.width, bounds.width - (pageXOffset - bounds.left));
623 out.width = Math.min(out.width, bounds.width - ((bounds.left + bounds.width) - (pageXOffset + innerWidth)));
624 out.width = Math.min(innerWidth, out.width);
626 if (out.top < pageYOffset) {
627 out.top = pageYOffset;
629 if (out.left < pageXOffset) {
630 out.left = pageXOffset;
635 case 'scroll-handle':
636 target = this.target;
637 if (target === document.body) {
638 target = document.documentElement;
646 bounds = getBounds(target);
648 style = getComputedStyle(target);
649 hasBottomScroll = target.scrollWidth > target.clientWidth || 'scroll' === [style.overflow, style.overflowX] || this.target !== document.body;
651 if (hasBottomScroll) {
654 height = bounds.height - parseFloat(style.borderTopWidth) - parseFloat(style.borderBottomWidth) - scrollBottom;
657 height: height * 0.975 * (height / target.scrollHeight),
658 left: bounds.left + bounds.width - parseFloat(style.borderLeftWidth) - 15
661 if (height < 408 && this.target === document.body) {
662 fitAdj = -0.00011 * Math.pow(height, 2) - 0.00727 * height + 22.58;
664 if (this.target !== document.body) {
665 out.height = Math.max(out.height, 24);
667 scrollPercentage = this.target.scrollTop / (target.scrollHeight - height);
668 out.top = scrollPercentage * (height - out.height - fitAdj) + bounds.top + parseFloat(style.borderTopWidth);
669 if (this.target === document.body) {
670 out.height = Math.max(out.height, 24);
675 return getBounds(this.target);
679 _Tether.prototype.clearCache = function() {
680 return this._cache = {};
683 _Tether.prototype.cache = function(k, getter) {
684 if (this._cache == null) {
687 if (this._cache[k] == null) {
688 this._cache[k] = getter.call(this);
690 return this._cache[k];
693 _Tether.prototype.enable = function(position) {
694 if (position == null) {
697 addClass(this.target, this.getClass('enabled'));
698 addClass(this.element, this.getClass('enabled'));
700 if (this.scrollParent !== document) {
701 this.scrollParent.addEventListener('scroll', this.position);
704 return this.position();
708 _Tether.prototype.disable = function() {
709 removeClass(this.target, this.getClass('enabled'));
710 removeClass(this.element, this.getClass('enabled'));
711 this.enabled = false;
712 if (this.scrollParent != null) {
713 return this.scrollParent.removeEventListener('scroll', this.position);
717 _Tether.prototype.destroy = function() {
718 var i, tether, _i, _len, _results;
721 for (i = _i = 0, _len = tethers.length; _i < _len; i = ++_i) {
723 if (tether === this) {
724 tethers.splice(i, 1);
727 _results.push(void 0);
733 _Tether.prototype.updateAttachClasses = function(elementAttach, targetAttach) {
734 var add, all, side, sides, _i, _j, _len, _len1, _ref1,
736 if (elementAttach == null) {
737 elementAttach = this.attachment;
739 if (targetAttach == null) {
740 targetAttach = this.targetAttachment;
742 sides = ['left', 'top', 'bottom', 'right', 'middle', 'center'];
743 if ((_ref1 = this._addAttachClasses) != null ? _ref1.length : void 0) {
744 this._addAttachClasses.splice(0, this._addAttachClasses.length);
746 add = this._addAttachClasses != null ? this._addAttachClasses : this._addAttachClasses = [];
747 if (elementAttach.top) {
748 add.push("" + (this.getClass('element-attached')) + "-" + elementAttach.top);
750 if (elementAttach.left) {
751 add.push("" + (this.getClass('element-attached')) + "-" + elementAttach.left);
753 if (targetAttach.top) {
754 add.push("" + (this.getClass('target-attached')) + "-" + targetAttach.top);
756 if (targetAttach.left) {
757 add.push("" + (this.getClass('target-attached')) + "-" + targetAttach.left);
760 for (_i = 0, _len = sides.length; _i < _len; _i++) {
762 all.push("" + (this.getClass('element-attached')) + "-" + side);
764 for (_j = 0, _len1 = sides.length; _j < _len1; _j++) {
766 all.push("" + (this.getClass('target-attached')) + "-" + side);
768 return defer(function() {
769 if (_this._addAttachClasses == null) {
772 updateClasses(_this.element, _this._addAttachClasses, all);
773 updateClasses(_this.target, _this._addAttachClasses, all);
774 return _this._addAttachClasses = void 0;
778 _Tether.prototype.position = function(flushChanges) {
779 var elementPos, elementStyle, height, left, manualOffset, manualTargetOffset, module, next, offset, offsetBorder, offsetParent, offsetParentSize, offsetParentStyle, offsetPosition, ret, scrollLeft, scrollTop, scrollbarSize, side, targetAttachment, targetOffset, targetPos, targetSize, top, width, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6,
781 if (flushChanges == null) {
788 targetAttachment = autoToFixedAttachment(this.targetAttachment, this.attachment);
789 this.updateAttachClasses(this.attachment, targetAttachment);
790 elementPos = this.cache('element-bounds', function() {
791 return getBounds(_this.element);
793 width = elementPos.width, height = elementPos.height;
794 if (width === 0 && height === 0 && (this.lastSize != null)) {
795 _ref1 = this.lastSize, width = _ref1.width, height = _ref1.height;
802 targetSize = targetPos = this.cache('target-bounds', function() {
803 return _this.getTargetBounds();
805 offset = offsetToPx(attachmentToOffset(this.attachment), {
809 targetOffset = offsetToPx(attachmentToOffset(targetAttachment), targetSize);
810 manualOffset = offsetToPx(this.offset, {
814 manualTargetOffset = offsetToPx(this.targetOffset, targetSize);
815 offset = addOffset(offset, manualOffset);
816 targetOffset = addOffset(targetOffset, manualTargetOffset);
817 left = targetPos.left + targetOffset.left - offset.left;
818 top = targetPos.top + targetOffset.top - offset.top;
819 _ref2 = Tether.modules;
820 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
822 ret = module.position.call(this, {
825 targetAttachment: targetAttachment,
826 targetPos: targetPos,
827 attachment: this.attachment,
828 elementPos: elementPos,
830 targetOffset: targetOffset,
831 manualOffset: manualOffset,
832 manualTargetOffset: manualTargetOffset,
833 scrollbarSize: scrollbarSize
835 if ((ret == null) || typeof ret !== 'object') {
837 } else if (ret === false) {
840 top = ret.top, left = ret.left;
849 top: top - pageYOffset,
850 bottom: pageYOffset - top - height + innerHeight,
851 left: left - pageXOffset,
852 right: pageXOffset - left - width + innerWidth
855 if (document.body.scrollWidth > window.innerWidth) {
856 scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
857 next.viewport.bottom -= scrollbarSize.height;
859 if (document.body.scrollHeight > window.innerHeight) {
860 scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
861 next.viewport.right -= scrollbarSize.width;
863 if (((_ref3 = document.body.style.position) !== '' && _ref3 !== 'static') || ((_ref4 = document.body.parentElement.style.position) !== '' && _ref4 !== 'static')) {
864 next.page.bottom = document.body.scrollHeight - top - height;
865 next.page.right = document.body.scrollWidth - left - width;
867 if (((_ref5 = this.options.optimizations) != null ? _ref5.moveElement : void 0) !== false && (this.targetModifier == null)) {
868 offsetParent = this.cache('target-offsetparent', function() {
869 return getOffsetParent(_this.target);
871 offsetPosition = this.cache('target-offsetparent-bounds', function() {
872 return getBounds(offsetParent);
874 offsetParentStyle = getComputedStyle(offsetParent);
875 elementStyle = getComputedStyle(this.element);
876 offsetParentSize = offsetPosition;
878 _ref6 = ['Top', 'Left', 'Bottom', 'Right'];
879 for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
881 offsetBorder[side.toLowerCase()] = parseFloat(offsetParentStyle["border" + side + "Width"]);
883 offsetPosition.right = document.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
884 offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
885 if (next.page.top >= (offsetPosition.top + offsetBorder.top) && next.page.bottom >= offsetPosition.bottom) {
886 if (next.page.left >= (offsetPosition.left + offsetBorder.left) && next.page.right >= offsetPosition.right) {
887 scrollTop = offsetParent.scrollTop;
888 scrollLeft = offsetParent.scrollLeft;
890 top: next.page.top - offsetPosition.top + scrollTop - offsetBorder.top,
891 left: next.page.left - offsetPosition.left + scrollLeft - offsetBorder.left
897 this.history.unshift(next);
898 if (this.history.length > 3) {
907 _Tether.prototype.move = function(position) {
908 var css, elVal, found, key, moved, offsetParent, point, same, transcribe, type, val, write, writeCSS, _i, _len, _ref1, _ref2,
910 if (this.element.parentNode == null) {
914 for (type in position) {
916 for (key in position[type]) {
918 _ref1 = this.history;
919 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
921 if (!within((_ref2 = point[type]) != null ? _ref2[key] : void 0, position[type][key])) {
927 same[type][key] = true;
937 transcribe = function(same, pos) {
938 var xPos, yPos, _ref3;
939 if (((_ref3 = _this.options.optimizations) != null ? _ref3.gpu : void 0) !== false) {
954 css[transformKey] = "translateX(" + (Math.round(xPos)) + "px) translateY(" + (Math.round(yPos)) + "px)";
955 if (transformKey !== 'msTransform') {
956 return css[transformKey] += " translateZ(0)";
960 css.top = "" + pos.top + "px";
962 css.bottom = "" + pos.bottom + "px";
965 return css.left = "" + pos.left + "px";
967 return css.right = "" + pos.right + "px";
972 if ((same.page.top || same.page.bottom) && (same.page.left || same.page.right)) {
973 css.position = 'absolute';
974 transcribe(same.page, position.page);
975 } else if ((same.viewport.top || same.viewport.bottom) && (same.viewport.left || same.viewport.right)) {
976 css.position = 'fixed';
977 transcribe(same.viewport, position.viewport);
978 } else if ((same.offset != null) && same.offset.top && same.offset.left) {
979 css.position = 'absolute';
980 offsetParent = this.cache('target-offsetparent', function() {
981 return getOffsetParent(_this.target);
983 if (getOffsetParent(this.element) !== offsetParent) {
985 _this.element.parentNode.removeChild(_this.element);
986 return offsetParent.appendChild(_this.element);
989 transcribe(same.offset, position.offset);
992 css.position = 'absolute';
998 if (!moved && this.element.parentNode.tagName !== 'BODY') {
999 this.element.parentNode.removeChild(this.element);
1000 document.body.appendChild(this.element);
1006 elVal = this.element.style[key];
1007 if (elVal !== '' && val !== '' && (key === 'top' || key === 'left' || key === 'bottom' || key === 'right')) {
1008 elVal = parseFloat(elVal);
1009 val = parseFloat(val);
1011 if (elVal !== val) {
1013 writeCSS[key] = css[key];
1017 return defer(function() {
1018 return extend(_this.element.style, writeCSS);
1027 Tether.position = position;
1029 this.Tether = extend(_Tether, Tether);
1034 var BOUNDS_FORMAT, MIRROR_ATTACH, defer, extend, getBoundingRect, getBounds, getOuterSize, getSize, updateClasses, _ref,
1035 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
1037 _ref = this.Tether.Utils, getOuterSize = _ref.getOuterSize, getBounds = _ref.getBounds, getSize = _ref.getSize, extend = _ref.extend, updateClasses = _ref.updateClasses, defer = _ref.defer;
1047 BOUNDS_FORMAT = ['left', 'top', 'right', 'bottom'];
1049 getBoundingRect = function(tether, to) {
1050 var i, pos, side, size, style, _i, _len;
1051 if (to === 'scrollParent') {
1052 to = tether.scrollParent;
1053 } else if (to === 'window') {
1054 to = [pageXOffset, pageYOffset, innerWidth + pageXOffset, innerHeight + pageYOffset];
1056 if (to === document) {
1057 to = to.documentElement;
1059 if (to.nodeType != null) {
1060 pos = size = getBounds(to);
1061 style = getComputedStyle(to);
1062 to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top];
1063 for (i = _i = 0, _len = BOUNDS_FORMAT.length; _i < _len; i = ++_i) {
1064 side = BOUNDS_FORMAT[i];
1065 side = side[0].toUpperCase() + side.substr(1);
1066 if (side === 'Top' || side === 'Left') {
1067 to[i] += parseFloat(style["border" + side + "Width"]);
1069 to[i] -= parseFloat(style["border" + side + "Width"]);
1076 this.Tether.modules.push({
1077 position: function(_arg) {
1078 var addClasses, allClasses, attachment, bounds, changeAttachX, changeAttachY, cls, constraint, eAttachment, height, left, oob, oobClass, p, pin, pinned, pinnedClass, removeClass, side, tAttachment, targetAttachment, targetHeight, targetSize, targetWidth, to, top, width, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8,
1080 top = _arg.top, left = _arg.left, targetAttachment = _arg.targetAttachment;
1081 if (!this.options.constraints) {
1084 removeClass = function(prefix) {
1085 var side, _i, _len, _results;
1086 _this.removeClass(prefix);
1088 for (_i = 0, _len = BOUNDS_FORMAT.length; _i < _len; _i++) {
1089 side = BOUNDS_FORMAT[_i];
1090 _results.push(_this.removeClass("" + prefix + "-" + side));
1094 _ref1 = this.cache('element-bounds', function() {
1095 return getBounds(_this.element);
1096 }), height = _ref1.height, width = _ref1.width;
1097 if (width === 0 && height === 0 && (this.lastSize != null)) {
1098 _ref2 = this.lastSize, width = _ref2.width, height = _ref2.height;
1100 targetSize = this.cache('target-bounds', function() {
1101 return _this.getTargetBounds();
1103 targetHeight = targetSize.height;
1104 targetWidth = targetSize.width;
1107 allClasses = [this.getClass('pinned'), this.getClass('out-of-bounds')];
1108 _ref3 = this.options.constraints;
1109 for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
1110 constraint = _ref3[_i];
1111 if (constraint.outOfBoundsClass) {
1112 allClasses.push(constraint.outOfBoundsClass);
1114 if (constraint.pinnedClass) {
1115 allClasses.push(constraint.pinnedClass);
1118 for (_j = 0, _len1 = allClasses.length; _j < _len1; _j++) {
1119 cls = allClasses[_j];
1120 _ref4 = ['left', 'top', 'right', 'bottom'];
1121 for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
1123 allClasses.push("" + cls + "-" + side);
1127 tAttachment = extend({}, targetAttachment);
1128 eAttachment = extend({}, this.attachment);
1129 _ref5 = this.options.constraints;
1130 for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
1131 constraint = _ref5[_l];
1132 to = constraint.to, attachment = constraint.attachment, pin = constraint.pin;
1133 if (attachment == null) {
1136 if (__indexOf.call(attachment, ' ') >= 0) {
1137 _ref6 = attachment.split(' '), changeAttachY = _ref6[0], changeAttachX = _ref6[1];
1139 changeAttachX = changeAttachY = attachment;
1141 bounds = getBoundingRect(this, to);
1142 if (changeAttachY === 'target' || changeAttachY === 'both') {
1143 if (top < bounds[1] && tAttachment.top === 'top') {
1144 top += targetHeight;
1145 tAttachment.top = 'bottom';
1147 if (top + height > bounds[3] && tAttachment.top === 'bottom') {
1148 top -= targetHeight;
1149 tAttachment.top = 'top';
1152 if (changeAttachY === 'together') {
1153 if (top < bounds[1] && tAttachment.top === 'top') {
1154 if (eAttachment.top === 'bottom') {
1155 top += targetHeight;
1156 tAttachment.top = 'bottom';
1158 eAttachment.top = 'top';
1159 } else if (eAttachment.top === 'top') {
1160 top += targetHeight;
1161 tAttachment.top = 'bottom';
1163 eAttachment.top = 'bottom';
1166 if (top + height > bounds[3] && tAttachment.top === 'bottom') {
1167 if (eAttachment.top === 'top') {
1168 top -= targetHeight;
1169 tAttachment.top = 'top';
1171 eAttachment.top = 'bottom';
1172 } else if (eAttachment.top === 'bottom') {
1173 top -= targetHeight;
1174 tAttachment.top = 'top';
1176 eAttachment.top = 'top';
1179 if (tAttachment.top === 'middle') {
1180 if (top + height > bounds[3] && eAttachment.top === 'top') {
1182 eAttachment.top = 'bottom';
1183 } else if (top < bounds[1] && eAttachment.top === 'bottom') {
1185 eAttachment.top = 'top';
1189 if (changeAttachX === 'target' || changeAttachX === 'both') {
1190 if (left < bounds[0] && tAttachment.left === 'left') {
1191 left += targetWidth;
1192 tAttachment.left = 'right';
1194 if (left + width > bounds[2] && tAttachment.left === 'right') {
1195 left -= targetWidth;
1196 tAttachment.left = 'left';
1199 if (changeAttachX === 'together') {
1200 if (left < bounds[0] && tAttachment.left === 'left') {
1201 if (eAttachment.left === 'right') {
1202 left += targetWidth;
1203 tAttachment.left = 'right';
1205 eAttachment.left = 'left';
1206 } else if (eAttachment.left === 'left') {
1207 left += targetWidth;
1208 tAttachment.left = 'right';
1210 eAttachment.left = 'right';
1212 } else if (left + width > bounds[2] && tAttachment.left === 'right') {
1213 if (eAttachment.left === 'left') {
1214 left -= targetWidth;
1215 tAttachment.left = 'left';
1217 eAttachment.left = 'right';
1218 } else if (eAttachment.left === 'right') {
1219 left -= targetWidth;
1220 tAttachment.left = 'left';
1222 eAttachment.left = 'left';
1224 } else if (tAttachment.left === 'center') {
1225 if (left + width > bounds[2] && eAttachment.left === 'left') {
1227 eAttachment.left = 'right';
1228 } else if (left < bounds[0] && eAttachment.left === 'right') {
1230 eAttachment.left = 'left';
1234 if (changeAttachY === 'element' || changeAttachY === 'both') {
1235 if (top < bounds[1] && eAttachment.top === 'bottom') {
1237 eAttachment.top = 'top';
1239 if (top + height > bounds[3] && eAttachment.top === 'top') {
1241 eAttachment.top = 'bottom';
1244 if (changeAttachX === 'element' || changeAttachX === 'both') {
1245 if (left < bounds[0] && eAttachment.left === 'right') {
1247 eAttachment.left = 'left';
1249 if (left + width > bounds[2] && eAttachment.left === 'left') {
1251 eAttachment.left = 'right';
1254 if (typeof pin === 'string') {
1256 var _len4, _m, _ref7, _results;
1257 _ref7 = pin.split(',');
1259 for (_m = 0, _len4 = _ref7.length; _m < _len4; _m++) {
1261 _results.push(p.trim());
1265 } else if (pin === true) {
1266 pin = ['top', 'left', 'right', 'bottom'];
1271 if (top < bounds[1]) {
1272 if (__indexOf.call(pin, 'top') >= 0) {
1279 if (top + height > bounds[3]) {
1280 if (__indexOf.call(pin, 'bottom') >= 0) {
1281 top = bounds[3] - height;
1282 pinned.push('bottom');
1287 if (left < bounds[0]) {
1288 if (__indexOf.call(pin, 'left') >= 0) {
1290 pinned.push('left');
1295 if (left + width > bounds[2]) {
1296 if (__indexOf.call(pin, 'right') >= 0) {
1297 left = bounds[2] - width;
1298 pinned.push('right');
1303 if (pinned.length) {
1304 pinnedClass = (_ref7 = this.options.pinnedClass) != null ? _ref7 : this.getClass('pinned');
1305 addClasses.push(pinnedClass);
1306 for (_m = 0, _len4 = pinned.length; _m < _len4; _m++) {
1308 addClasses.push("" + pinnedClass + "-" + side);
1312 oobClass = (_ref8 = this.options.outOfBoundsClass) != null ? _ref8 : this.getClass('out-of-bounds');
1313 addClasses.push(oobClass);
1314 for (_n = 0, _len5 = oob.length; _n < _len5; _n++) {
1316 addClasses.push("" + oobClass + "-" + side);
1319 if (__indexOf.call(pinned, 'left') >= 0 || __indexOf.call(pinned, 'right') >= 0) {
1320 eAttachment.left = tAttachment.left = false;
1322 if (__indexOf.call(pinned, 'top') >= 0 || __indexOf.call(pinned, 'bottom') >= 0) {
1323 eAttachment.top = tAttachment.top = false;
1325 if (tAttachment.top !== targetAttachment.top || tAttachment.left !== targetAttachment.left || eAttachment.top !== this.attachment.top || eAttachment.left !== this.attachment.left) {
1326 this.updateAttachClasses(eAttachment, tAttachment);
1330 updateClasses(_this.target, addClasses, allClasses);
1331 return updateClasses(_this.element, addClasses, allClasses);
1343 var defer, getBounds, updateClasses, _ref;
1345 _ref = this.Tether.Utils, getBounds = _ref.getBounds, updateClasses = _ref.updateClasses, defer = _ref.defer;
1347 this.Tether.modules.push({
1348 position: function(_arg) {
1349 var abutted, addClasses, allClasses, bottom, height, left, right, side, sides, targetPos, top, width, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3, _ref4, _ref5,
1351 top = _arg.top, left = _arg.left;
1352 _ref1 = this.cache('element-bounds', function() {
1353 return getBounds(_this.element);
1354 }), height = _ref1.height, width = _ref1.width;
1355 targetPos = this.getTargetBounds();
1356 bottom = top + height;
1357 right = left + width;
1359 if (top <= targetPos.bottom && bottom >= targetPos.top) {
1360 _ref2 = ['left', 'right'];
1361 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1363 if ((_ref3 = targetPos[side]) === left || _ref3 === right) {
1368 if (left <= targetPos.right && right >= targetPos.left) {
1369 _ref4 = ['top', 'bottom'];
1370 for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
1372 if ((_ref5 = targetPos[side]) === top || _ref5 === bottom) {
1379 sides = ['left', 'top', 'right', 'bottom'];
1380 allClasses.push(this.getClass('abutted'));
1381 for (_k = 0, _len2 = sides.length; _k < _len2; _k++) {
1383 allClasses.push("" + (this.getClass('abutted')) + "-" + side);
1385 if (abutted.length) {
1386 addClasses.push(this.getClass('abutted'));
1388 for (_l = 0, _len3 = abutted.length; _l < _len3; _l++) {
1390 addClasses.push("" + (this.getClass('abutted')) + "-" + side);
1393 updateClasses(_this.target, addClasses, allClasses);
1394 return updateClasses(_this.element, addClasses, allClasses);
1403 this.Tether.modules.push({
1404 position: function(_arg) {
1405 var left, result, shift, shiftLeft, shiftTop, top, _ref;
1406 top = _arg.top, left = _arg.left;
1407 if (!this.options.shift) {
1410 result = function(val) {
1411 if (typeof val === 'function') {
1412 return val.call(this, {
1420 shift = result(this.options.shift);
1421 if (typeof shift === 'string') {
1422 shift = shift.split(' ');
1423 shift[1] || (shift[1] = shift[0]);
1424 shiftTop = shift[0], shiftLeft = shift[1];
1425 shiftTop = parseFloat(shiftTop, 10);
1426 shiftLeft = parseFloat(shiftLeft, 10);
1428 _ref = [shift.top, shift.left], shiftTop = _ref[0], shiftLeft = _ref[1];