(function(root, factory) {
if (typeof define === 'function' && define.amd) {
} else if (typeof exports === 'object') {
module.exports = factory(require,exports,module);
}(this, function(require,exports,module) {
var Evented, addClass, defer, deferred, extend, flush, getBounds, getOffsetParent, getOrigin, getScrollBarSize, getScrollParent, hasClass, node, removeClass, uniqueId, updateClasses, zeroPosCache,
__hasProp = {}.hasOwnProperty,
__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; },
if (this.Tether == null) {
getScrollParent = function(el) {
var parent, position, scrollParent, style, _ref;
position = getComputedStyle(el).position;
if (position === 'fixed') {
while (parent = parent.parentNode) {
style = getComputedStyle(parent);
if (/(auto|scroll)/.test(style['overflow'] + style['overflow-y'] + style['overflow-x'])) {
if (position !== 'absolute' || ((_ref = style['position']) === 'relative' || _ref === 'absolute' || _ref === 'fixed')) {
getOrigin = function(doc) {
var id, k, node, v, _ref;
node = doc._tetherZeroElement;
node = doc.createElement('div');
node.setAttribute('data-tether-id', uniqueId());
doc.body.appendChild(node);
doc._tetherZeroElement = node;
id = node.getAttribute('data-tether-id');
if (zeroPosCache[id] == null) {
_ref = node.getBoundingClientRect();
return zeroPosCache[id] = void 0;
getBounds = function(el) {
var box, doc, docEl, k, origin, v, _ref;
el = document.documentElement;
docEl = doc.documentElement;
_ref = el.getBoundingClientRect();
box.width = document.body.scrollWidth - box.left - box.right;
if (box.height == null) {
box.height = document.body.scrollHeight - box.top - box.bottom;
box.top = box.top - docEl.clientTop;
box.left = box.left - docEl.clientLeft;
box.right = doc.body.clientWidth - box.width - box.left;
box.bottom = doc.body.clientHeight - box.height - box.top;
getOffsetParent = function(el) {
return el.offsetParent || document.documentElement;
getScrollBarSize = function() {
var inner, outer, width, widthContained, widthScroll;
inner = document.createElement('div');
inner.style.width = '100%';
inner.style.height = '200px';
outer = document.createElement('div');
outer.appendChild(inner);
document.body.appendChild(outer);
widthContained = inner.offsetWidth;
outer.style.overflow = 'scroll';
widthScroll = inner.offsetWidth;
if (widthContained === widthScroll) {
widthScroll = outer.clientWidth;
document.body.removeChild(outer);
width = widthContained - widthScroll;
var args, key, obj, val, _i, _len, _ref;
Array.prototype.push.apply(args, arguments);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
if (!__hasProp.call(obj, key)) continue;
removeClass = function(el, name) {
var cls, _i, _len, _ref, _results;
if (el.classList != null) {
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_results.push(el.classList.remove(cls));
return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
addClass = function(el, name) {
var cls, _i, _len, _ref, _results;
if (el.classList != null) {
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_results.push(el.classList.add(cls));
return el.className += " " + name;
hasClass = function(el, name) {
if (el.classList != null) {
return el.classList.contains(name);
return new RegExp("(^| )" + name + "( |$)", 'gi').test(el.className);
updateClasses = function(el, add, all) {
var cls, _i, _j, _len, _len1, _results;
for (_i = 0, _len = all.length; _i < _len; _i++) {
if (__indexOf.call(add, cls) < 0) {
for (_j = 0, _len1 = add.length; _j < _len1; _j++) {
if (!hasClass(el, cls)) {
_results.push(addClass(el, cls));
return deferred.push(fn);
while (fn = deferred.pop()) {
Evented.prototype.on = function(event, handler, ctx, once) {
if (this.bindings == null) {
if ((_base = this.bindings)[event] == null) {
return this.bindings[event].push({
Evented.prototype.once = function(event, handler, ctx) {
return this.on(event, handler, ctx, true);
Evented.prototype.off = function(event, handler) {
if (((_ref = this.bindings) != null ? _ref[event] : void 0) == null) {
return delete this.bindings[event];
while (i < this.bindings[event].length) {
if (this.bindings[event][i].handler === handler) {
_results.push(this.bindings[event].splice(i, 1));
Evented.prototype.trigger = function() {
var args, ctx, event, handler, i, once, _ref, _ref1, _results;
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if ((_ref = this.bindings) != null ? _ref[event] : void 0) {
while (i < this.bindings[event].length) {
_ref1 = this.bindings[event][i], handler = _ref1.handler, ctx = _ref1.ctx, once = _ref1.once;
handler.apply(ctx != null ? ctx : this, args);
_results.push(this.bindings[event].splice(i, 1));
getScrollParent: getScrollParent,
getOffsetParent: getOffsetParent,
removeClass: removeClass,
updateClasses: updateClasses,
getScrollBarSize: getScrollBarSize
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,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
if (this.Tether == null) {
throw new Error("You must include the utils.js file before tether.js");
_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;
within = function(a, b, diff) {
return (a + diff >= b && b >= a - diff);
transformKey = (function() {
var el, key, _i, _len, _ref1;
el = document.createElement('div');
_ref1 = ['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
if (el.style[key] !== void 0) {
for (_i = 0, _len = tethers.length; _i < _len; _i++) {
return (_ref1 = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref1 : +(new Date);
var event, lastCall, lastDuration, pendingTimeout, tick, _i, _len, _ref1, _results;
if ((lastDuration != null) && lastDuration > 16) {
lastDuration = Math.min(lastDuration - 16, 250);
pendingTimeout = setTimeout(tick, 250);
if ((lastCall != null) && (now() - lastCall) < 10) {
if (pendingTimeout != null) {
clearTimeout(pendingTimeout);
return lastDuration = now() - lastCall;
_ref1 = ['resize', 'scroll', 'touchmove'];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
_results.push(window.addEventListener(event, tick));
autoToFixedAttachment = function(attachment, relativeToAttachment) {
left = attachment.left, top = attachment.top;
left = MIRROR_LR[relativeToAttachment.left];
top = MIRROR_TB[relativeToAttachment.top];
attachmentToOffset = function(attachment) {
left: (_ref1 = OFFSET_MAP[attachment.left]) != null ? _ref1 : attachment.left,
top: (_ref2 = OFFSET_MAP[attachment.top]) != null ? _ref2 : attachment.top
var left, offsets, out, top, _i, _len, _ref1;
offsets = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
for (_i = 0, _len = offsets.length; _i < _len; _i++) {
_ref1 = offsets[_i], top = _ref1.top, left = _ref1.left;
if (typeof top === 'string') {
top = parseFloat(top, 10);
if (typeof left === 'string') {
left = parseFloat(left, 10);
offsetToPx = function(offset, size) {
if (typeof offset.left === 'string' && offset.left.indexOf('%') !== -1) {
offset.left = parseFloat(offset.left, 10) / 100 * size.width;
if (typeof offset.top === 'string' && offset.top.indexOf('%') !== -1) {
offset.top = parseFloat(offset.top, 10) / 100 * size.height;
parseAttachment = parseOffset = function(value) {