/*! tether 0.6.5 */ (function(root, factory) { if (typeof define === 'function' && define.amd) { define(factory); } else if (typeof exports === 'object') { module.exports = factory(require,exports,module); } else { root.Tether = factory(); } }(this, function(require,exports,module) { (function() { 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; }, __slice = [].slice; if (this.Tether == null) { this.Tether = { modules: [] }; } getScrollParent = function(el) { var parent, position, scrollParent, style, _ref; position = getComputedStyle(el).position; if (position === 'fixed') { return el; } scrollParent = void 0; parent = el; while (parent = parent.parentNode) { try { style = getComputedStyle(parent); } catch (_error) {} if (style == null) { return parent; } if (/(auto|scroll)/.test(style['overflow'] + style['overflow-y'] + style['overflow-x'])) { if (position !== 'absolute' || ((_ref = style['position']) === 'relative' || _ref === 'absolute' || _ref === 'fixed')) { return parent; } } } return document.body; }; uniqueId = (function() { var id; id = 0; return function() { return id++; }; })(); zeroPosCache = {}; getOrigin = function(doc) { var id, k, node, v, _ref; node = doc._tetherZeroElement; if (node == null) { node = doc.createElement('div'); node.setAttribute('data-tether-id', uniqueId()); extend(node.style, { top: 0, left: 0, position: 'absolute' }); doc.body.appendChild(node); doc._tetherZeroElement = node; } id = node.getAttribute('data-tether-id'); if (zeroPosCache[id] == null) { zeroPosCache[id] = {}; _ref = node.getBoundingClientRect(); for (k in _ref) { v = _ref[k]; zeroPosCache[id][k] = v; } defer(function() { return zeroPosCache[id] = void 0; }); } return zeroPosCache[id]; }; node = null; getBounds = function(el) { var box, doc, docEl, k, origin, v, _ref; if (el === document) { doc = document; el = document.documentElement; } else { doc = el.ownerDocument; } docEl = doc.documentElement; box = {}; _ref = el.getBoundingClientRect(); for (k in _ref) { v = _ref[k]; box[k] = v; } origin = getOrigin(doc); box.top -= origin.top; box.left -= origin.left; if (box.width == null) { 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; return box; }; 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'); extend(outer.style, { position: 'absolute', top: 0, left: 0, pointerEvents: 'none', visibility: 'hidden', width: '200px', height: '150px', overflow: 'hidden' }); 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; return { width: width, height: width }; }; extend = function(out) { var args, key, obj, val, _i, _len, _ref; if (out == null) { out = {}; } args = []; Array.prototype.push.apply(args, arguments); _ref = args.slice(1); for (_i = 0, _len = _ref.length; _i < _len; _i++) { obj = _ref[_i]; if (obj) { for (key in obj) { if (!__hasProp.call(obj, key)) continue; val = obj[key]; out[key] = val; } } } return out; }; removeClass = function(el, name) { var cls, _i, _len, _ref, _results; if (el.classList != null) { _ref = name.split(' '); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { cls = _ref[_i]; if (cls.trim()) { _results.push(el.classList.remove(cls)); } } return _results; } else { 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) { _ref = name.split(' '); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { cls = _ref[_i]; if (cls.trim()) { _results.push(el.classList.add(cls)); } } return _results; } else { removeClass(el, name); return el.className += " " + name; } }; hasClass = function(el, name) { if (el.classList != null) { return el.classList.contains(name); } else { 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++) { cls = all[_i]; if (__indexOf.call(add, cls) < 0) { if (hasClass(el, cls)) { removeClass(el, cls); } } } _results = []; for (_j = 0, _len1 = add.length; _j < _len1; _j++) { cls = add[_j]; if (!hasClass(el, cls)) { _results.push(addClass(el, cls)); } else { _results.push(void 0); } } return _results; }; deferred = []; defer = function(fn) { return deferred.push(fn); }; flush = function() { var fn, _results; _results = []; while (fn = deferred.pop()) { _results.push(fn()); } return _results; }; Evented = (function() { function Evented() {} Evented.prototype.on = function(event, handler, ctx, once) { var _base; if (once == null) { once = false; } if (this.bindings == null) { this.bindings = {}; } if ((_base = this.bindings)[event] == null) { _base[event] = []; } return this.bindings[event].push({ handler: handler,
/*
 * Copyright (C) 2015, 2016 "IoT.bzh"
 * Author "Romain Forlot" <romain.forlot@iot.bzh>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#include "clientApp.hpp"

clientAppCtx::clientAppCtx(const char* uuid)
: uuid_(uuid)
{}

void clientAppCtx::update(Signal* sig)
{
	json_object* sigJ = sig->toJSON();
	if(afb_event_push(event_, sigJ) == 0)
		{sig->delObserver(this);}
	return;
}

void clientAppCtx::appendSignals(std::vector<Signal*>& sigV)
{
	bool set = false;
	// Clean up already subscribed signals to avoid duplicata
	for (std::vector<Signal*>::const_iterator it = sigV.begin();
	it != sigV.end(); ++it)
	{
		for (auto& ctxSig: subscribedSignals_)
			{if(*it == ctxSig) {set = true;}}
		if (set)
		{
			set = false;
			sigV.erase(it);
			continue;
		}
		Signal* sig = *it;
		sig->addObserver(this);
	}

	subscribedSignals_.insert(subscribedSignals_.end(), sigV.begin(), sigV.end());
}

int clientAppCtx::makeSubscription(struct afb_req request)
{
	event_ = afb_event_is_valid(event_) ?
		event_ : afb_daemon_make_event(uuid_.c_str());
	return afb_req_subscribe(request, event_);
}

int clientAppCtx::makeUnsubscription(struct afb_req request)
{
	return afb_event_is_valid(event_) ?
		afb_req_unsubscribe(request, event_) : -1;
}
th.max(out.height, 24); } return out; } } else { return getBounds(this.target); } }; _Tether.prototype.clearCache = function() { return this._cache = {}; }; _Tether.prototype.cache = function(k, getter) { if (this._cache == null) { this._cache = {}; } if (this._cache[k] == null) { this._cache[k] = getter.call(this); } return this._cache[k]; }; _Tether.prototype.enable = function(position) { if (position == null) { position = true; } addClass(this.target, this.getClass('enabled')); addClass(this.element, this.getClass('enabled')); this.enabled = true; if (this.scrollParent !== document) { this.scrollParent.addEventListener('scroll', this.position); } if (position) { return this.position(); } }; _Tether.prototype.disable = function() { removeClass(this.target, this.getClass('enabled')); removeClass(this.element, this.getClass('enabled')); this.enabled = false; if (this.scrollParent != null) { return this.scrollParent.removeEventListener('scroll', this.position); } }; _Tether.prototype.destroy = function() { var i, tether, _i, _len, _results; this.disable(); _results = []; for (i = _i = 0, _len = tethers.length; _i < _len; i = ++_i) { tether = tethers[i]; if (tether === this) { tethers.splice(i, 1); break; } else { _results.push(void 0); } } return _results; }; _Tether.prototype.updateAttachClasses = function(elementAttach, targetAttach) { var add, all, side, sides, _i, _j, _len, _len1, _ref1, _this = this; if (elementAttach == null) { elementAttach = this.attachment; } if (targetAttach == null) { targetAttach = this.targetAttachment; } sides = ['left', 'top', 'bottom', 'right', 'middle', 'center']; if ((_ref1 = this._addAttachClasses) != null ? _ref1.length : void 0) { this._addAttachClasses.splice(0, this._addAttachClasses.length); } add = this._addAttachClasses != null ? this._addAttachClasses : this._addAttachClasses = []; if (elementAttach.top) { add.push("" + (this.getClass('element-attached')) + "-" + elementAttach.top); } if (elementAttach.left) { add.push("" + (this.getClass('element-attached')) + "-" + elementAttach.left); } if (targetAttach.top) { add.push("" + (this.getClass('target-attached')) + "-" + targetAttach.top); } if (targetAttach.left) { add.push("" + (this.getClass('target-attached')) + "-" + targetAttach.left); } all = []; for (_i = 0, _len = sides.length; _i < _len; _i++) { side = sides[_i]; all.push("" + (this.getClass('element-attached')) + "-" + side); } for (_j = 0, _len1 = sides.length; _j < _len1; _j++) { side = sides[_j]; all.push("" + (this.getClass('target-attached')) + "-" + side); } return defer(function() { if (_this._addAttachClasses == null) { return; } updateClasses(_this.element, _this._addAttachClasses, all); updateClasses(_this.target, _this._addAttachClasses, all); return _this._addAttachClasses = void 0; }); }; _Tether.prototype.position = function(flushChanges) { 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, _this = this; if (flushChanges == null) { flushChanges = true; } if (!this.enabled) { return; } this.clearCache(); targetAttachment = autoToFixedAttachment(this.targetAttachment, this.attachment); this.updateAttachClasses(this.attachment, targetAttachment); elementPos = this.cache('element-bounds', function() { return getBounds(_this.element); }); width = elementPos.width, height = elementPos.height; if (width === 0 && height === 0 && (this.lastSize != null)) { _ref1 = this.lastSize, width = _ref1.width, height = _ref1.height; } else { this.lastSize = { width: width, height: height }; } targetSize = targetPos = this.cache('target-bounds', function() { return _this.getTargetBounds(); }); offset = offsetToPx(attachmentToOffset(this.attachment), { width: width, height: height }); targetOffset = offsetToPx(attachmentToOffset(targetAttachment), targetSize); manualOffset = offsetToPx(this.offset, { width: width, height: height }); manualTargetOffset = offsetToPx(this.targetOffset, targetSize); offset = addOffset(offset, manualOffset); targetOffset = addOffset(targetOffset, manualTargetOffset); left = targetPos.left + targetOffset.left - offset.left; top = targetPos.top + targetOffset.top - offset.top; _ref2 = Tether.modules; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { module = _ref2[_i]; ret = module.position.call(this, { left: left, top: top, targetAttachment: targetAttachment, targetPos: targetPos, attachment: this.attachment, elementPos: elementPos, offset: offset, targetOffset: targetOffset, manualOffset: manualOffset, manualTargetOffset: manualTargetOffset, scrollbarSize: scrollbarSize }); if ((ret == null) || typeof ret !== 'object') { continue; } else if (ret === false) { return false; } else { top = ret.top, left = ret.left; } } next = { page: { top: top, left: left }, viewport: { top: top - pageYOffset, bottom: pageYOffset - top - height + innerHeight, left: left - pageXOffset, right: pageXOffset - left - width + innerWidth } }; if (document.body.scrollWidth > window.innerWidth) { scrollbarSize = this.cache('scrollbar-size', getScrollBarSize); next.viewport.bottom -= scrollbarSize.height; } if (document.body.scrollHeight > window.innerHeight) { scrollbarSize = this.cache('scrollbar-size', getScrollBarSize); next.viewport.right -= scrollbarSize.width; } if (((_ref3 = document.body.style.position) !== '' && _ref3 !== 'static') || ((_ref4 = document.body.parentElement.style.position) !== '' && _ref4 !== 'static')) { next.page.bottom = document.body.scrollHeight - top - height; next.page.right = document.body.scrollWidth - left - width; } if (((_ref5 = this.options.optimizations) != null ? _ref5.moveElement : void 0) !== false && (this.targetModifier == null)) { offsetParent = this.cache('target-offsetparent', function() { return getOffsetParent(_this.target); }); offsetPosition = this.cache('target-offsetparent-bounds', function() { return getBounds(offsetParent); }); offsetParentStyle = getComputedStyle(offsetParent); elementStyle = getComputedStyle(this.element); offsetParentSize = offsetPosition; offsetBorder = {}; _ref6 = ['Top', 'Left', 'Bottom', 'Right']; for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) { side = _ref6[_j]; offsetBorder[side.toLowerCase()] = parseFloat(offsetParentStyle["border" + side + "Width"]); } offsetPosition.right = document.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right; offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom; if (next.page.top >= (offsetPosition.top + offsetBorder.top) && next.page.bottom >= offsetPosition.bottom) { if (next.page.left >= (offsetPosition.left + offsetBorder.left) && next.page.right >= offsetPosition.right) { scrollTop = offsetParent.scrollTop; scrollLeft = offsetParent.scrollLeft; next.offset = { top: next.page.top - offsetPosition.top + scrollTop - offsetBorder.top, left: next.page.left - offsetPosition.left + scrollLeft - offsetBorder.left }; } } } this.move(next); this.history.unshift(next); if (this.history.length > 3) { this.history.pop(); } if (flushChanges) { flush(); } return true; }; _Tether.prototype.move = function(position) { var css, elVal, found, key, moved, offsetParent, point, same, transcribe, type, val, write, writeCSS, _i, _len, _ref1, _ref2, _this = this; if (this.element.parentNode == null) { return; } same = {}; for (type in position) { same[type] = {}; for (key in position[type]) { found = false; _ref1 = this.history; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { point = _ref1[_i]; if (!within((_ref2 = point[type]) != null ? _ref2[key] : void 0, position[type][key])) { found = true; break; } } if (!found) { same[type][key] = true; } } } css = { top: '', left: '', right: '', bottom: '' }; transcribe = function(same, pos) { var xPos, yPos, _ref3; if (((_ref3 = _this.options.optimizations) != null ? _ref3.gpu : void 0) !== false) { if (same.top) { css.top = 0; yPos = pos.top; } else { css.bottom = 0; yPos = -pos.bottom; } if (same.left) { css.left = 0; xPos = pos.left; } else { css.right = 0; xPos = -pos.right; } css[transformKey] = "translateX(" + (Math.round(xPos)) + "px) translateY(" + (Math.round(yPos)) + "px)"; if (transformKey !== 'msTransform') { return css[transformKey] += " translateZ(0)"; } } else { if (same.top) { css.top = "" + pos.top + "px"; } else { css.bottom = "" + pos.bottom + "px"; } if (same.left) { return css.left = "" + pos.left + "px"; } else { return css.right = "" + pos.right + "px"; } } }; moved = false; if ((same.page.top || same.page.bottom) && (same.page.left || same.page.right)) { css.position = 'absolute'; transcribe(same.page, position.page); } else if ((same.viewport.top || same.viewport.bottom) && (same.viewport.left || same.viewport.right)) { css.position = 'fixed'; transcribe(same.viewport, position.viewport); } else if ((same.offset != null) && same.offset.top && same.offset.left) { css.position = 'absolute'; offsetParent = this.cache('target-offsetparent', function() { return getOffsetParent(_this.target); }); if (getOffsetParent(this.element) !== offsetParent) { defer(function() { _this.element.parentNode.removeChild(_this.element); return offsetParent.appendChild(_this.element); }); } transcribe(same.offset, position.offset); moved = true; } else { css.position = 'absolute'; transcribe({ top: true, left: true }, position.page); } if (!moved && this.element.parentNode.tagName !== 'BODY') { this.element.parentNode.removeChild(this.element); document.body.appendChild(this.element); } writeCSS = {}; write = false; for (key in css) { val = css[key]; elVal = this.element.style[key]; if (elVal !== '' && val !== '' && (key === 'top' || key === 'left' || key === 'bottom' || key === 'right')) { elVal = parseFloat(elVal); val = parseFloat(val); } if (elVal !== val) { write = true; writeCSS[key] = css[key]; } } if (write) { return defer(function() { return extend(_this.element.style, writeCSS); }); } }; return _Tether; })(); Tether.position = position; this.Tether = extend(_Tether, Tether); }).call(this); (function() { var BOUNDS_FORMAT, MIRROR_ATTACH, defer, extend, getBoundingRect, getBounds, getOuterSize, getSize, updateClasses, _ref, __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; }; _ref = this.Tether.Utils, getOuterSize = _ref.getOuterSize, getBounds = _ref.getBounds, getSize = _ref.getSize, extend = _ref.extend, updateClasses = _ref.updateClasses, defer = _ref.defer; MIRROR_ATTACH = { left: 'right', right: 'left', top: 'bottom', bottom: 'top', middle: 'middle' }; BOUNDS_FORMAT = ['left', 'top', 'right', 'bottom']; getBoundingRect = function(tether, to) { var i, pos, side, size, style, _i, _len; if (to === 'scrollParent') { to = tether.scrollParent; } else if (to === 'window') { to = [pageXOffset, pageYOffset, innerWidth + pageXOffset, innerHeight + pageYOffset]; } if (to === document) { to = to.documentElement; } if (to.nodeType != null) { pos = size = getBounds(to); style = getComputedStyle(to); to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top]; for (i = _i = 0, _len = BOUNDS_FORMAT.length; _i < _len; i = ++_i) { side = BOUNDS_FORMAT[i]; side = side[0].toUpperCase() + side.substr(1); if (side === 'Top' || side === 'Left') { to[i] += parseFloat(style["border" + side + "Width"]); } else { to[i] -= parseFloat(style["border" + side + "Width"]); } } } return to; }; this.Tether.modules.push({ position: function(_arg) { 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, _this = this; top = _arg.top, left = _arg.left, targetAttachment = _arg.targetAttachment; if (!this.options.constraints) { return true; } removeClass = function(prefix) { var side, _i, _len, _results; _this.removeClass(prefix); _results = []; for (_i = 0, _len = BOUNDS_FORMAT.length; _i < _len; _i++) { side = BOUNDS_FORMAT[_i]; _results.push(_this.removeClass("" + prefix + "-" + side)); } return _results; }; _ref1 = this.cache('element-bounds', function() { return getBounds(_this.element); }), height = _ref1.height, width = _ref1.width; if (width === 0 && height === 0 && (this.lastSize != null)) { _ref2 = this.lastSize, width = _ref2.width, height = _ref2.height; } targetSize = this.cache('target-bounds', function() { return _this.getTargetBounds(); }); targetHeight = targetSize.height; targetWidth = targetSize.width; tAttachment = {}; eAttachment = {}; allClasses = [this.getClass('pinned'), this.getClass('out-of-bounds')]; _ref3 = this.options.constraints; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { constraint = _ref3[_i]; if (constraint.outOfBoundsClass) { allClasses.push(constraint.outOfBoundsClass); } if (constraint.pinnedClass) { allClasses.push(constraint.pinnedClass); } } for (_j = 0, _len1 = allClasses.length; _j < _len1; _j++) { cls = allClasses[_j]; _ref4 = ['left', 'top', 'right', 'bottom']; for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { side = _ref4[_k]; allClasses.push("" + cls + "-" + side); } } addClasses = []; tAttachment = extend({}, targetAttachment); eAttachment = extend({}, this.attachment); _ref5 = this.options.constraints; for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) { constraint = _ref5[_l]; to = constraint.to, attachment = constraint.attachment, pin = constraint.pin; if (attachment == null) { attachment = ''; } if (__indexOf.call(attachment, ' ') >= 0) { _ref6 = attachment.split(' '), changeAttachY = _ref6[0], changeAttachX = _ref6[1]; } else { changeAttachX = changeAttachY = attachment; } bounds = getBoundingRect(this, to); if (changeAttachY === 'target' || changeAttachY === 'both') { if (top < bounds[1] && tAttachment.top === 'top') { top += targetHeight; tAttachment.top = 'bottom'; } if (top + height > bounds[3] && tAttachment.top === 'bottom') { top -= targetHeight; tAttachment.top = 'top'; } } if (changeAttachY === 'together') { if (top < bounds[1] && tAttachment.top === 'top') { if (eAttachment.top === 'bottom') { top += targetHeight; tAttachment.top = 'bottom'; top += height; eAttachment.top = 'top'; } else if (eAttachment.top === 'top') { top += targetHeight; tAttachment.top = 'bottom'; top -= height; eAttachment.top = 'bottom'; } } if (top + height > bounds[3] && tAttachment.top === 'bottom') { if (eAttachment.top === 'top') { top -= targetHeight; tAttachment.top = 'top'; top -= height; eAttachment.top = 'bottom'; } else if (eAttachment.top === 'bottom') { top -= targetHeight; tAttachment.top = 'top'; top += height; eAttachment.top = 'top'; } } if (tAttachment.top === 'middle') { if (top + height > bounds[3] && eAttachment.top === 'top') { top -= height; eAttachment.top = 'bottom'; } else if (top < bounds[1] && eAttachment.top === 'bottom') { top += height; eAttachment.top = 'top'; } } } if (changeAttachX === 'target' || changeAttachX === 'both') { if (left < bounds[0] && tAttachment.left === 'left') { left += targetWidth; tAttachment.left = 'right'; } if (left + width > bounds[2] && tAttachment.left === 'right') { left -= targetWidth; tAttachment.left = 'left'; } } if (changeAttachX === 'together') { if (left < bounds[0] && tAttachment.left === 'left') { if (eAttachment.left === 'right') { left += targetWidth; tAttachment.left = 'right'; left += width; eAttachment.left = 'left'; } else if (eAttachment.left === 'left') { left += targetWidth; tAttachment.left = 'right'; left -= width; eAttachment.left = 'right'; } } else if (left + width > bounds[2] && tAttachment.left === 'right') { if (eAttachment.left === 'left') { left -= targetWidth; tAttachment.left = 'left'; left -= width; eAttachment.left = 'right'; } else if (eAttachment.left === 'right') { left -= targetWidth; tAttachment.left = 'left'; left += width; eAttachment.left = 'left'; } } else if (tAttachment.left === 'center') { if (left + width > bounds[2] && eAttachment.left === 'left') { left -= width; eAttachment.left = 'right'; } else if (left < bounds[0] && eAttachment.left === 'right') { left += width; eAttachment.left = 'left'; } } } if (changeAttachY === 'element' || changeAttachY === 'both') { if (top < bounds[1] && eAttachment.top === 'bottom') { top += height; eAttachment.top = 'top'; } if (top + height > bounds[3] && eAttachment.top === 'top') { top -= height; eAttachment.top = 'bottom'; } } if (changeAttachX === 'element' || changeAttachX === 'both') { if (left < bounds[0] && eAttachment.left === 'right') { left += width; eAttachment.left = 'left'; } if (left + width > bounds[2] && eAttachment.left === 'left') { left -= width; eAttachment.left = 'right'; } } if (typeof pin === 'string') { pin = (function() { var _len4, _m, _ref7, _results; _ref7 = pin.split(','); _results = []; for (_m = 0, _len4 = _ref7.length; _m < _len4; _m++) { p = _ref7[_m]; _results.push(p.trim()); } return _results; })(); } else if (pin === true) { pin = ['top', 'left', 'right', 'bottom']; } pin || (pin = []); pinned = []; oob = []; if (top < bounds[1]) { if (__indexOf.call(pin, 'top') >= 0) { top = bounds[1]; pinned.push('top'); } else { oob.push('top'); } } if (top + height > bounds[3]) { if (__indexOf.call(pin, 'bottom') >= 0) { top = bounds[3] - height; pinned.push('bottom'); } else { oob.push('bottom'); } } if (left < bounds[0]) { if (__indexOf.call(pin, 'left') >= 0) { left = bounds[0]; pinned.push('left'); } else { oob.push('left'); } } if (left + width > bounds[2]) { if (__indexOf.call(pin, 'right') >= 0) { left = bounds[2] - width; pinned.push('right'); } else { oob.push('right'); } } if (pinned.length) { pinnedClass = (_ref7 = this.options.pinnedClass) != null ? _ref7 : this.getClass('pinned'); addClasses.push(pinnedClass); for (_m = 0, _len4 = pinned.length; _m < _len4; _m++) { side = pinned[_m]; addClasses.push("" + pinnedClass + "-" + side); } } if (oob.length) { oobClass = (_ref8 = this.options.outOfBoundsClass) != null ? _ref8 : this.getClass('out-of-bounds'); addClasses.push(oobClass); for (_n = 0, _len5 = oob.length; _n < _len5; _n++) { side = oob[_n]; addClasses.push("" + oobClass + "-" + side); } } if (__indexOf.call(pinned, 'left') >= 0 || __indexOf.call(pinned, 'right') >= 0) { eAttachment.left = tAttachment.left = false; } if (__indexOf.call(pinned, 'top') >= 0 || __indexOf.call(pinned, 'bottom') >= 0) { eAttachment.top = tAttachment.top = false; } if (tAttachment.top !== targetAttachment.top || tAttachment.left !== targetAttachment.left || eAttachment.top !== this.attachment.top || eAttachment.left !== this.attachment.left) { this.updateAttachClasses(eAttachment, tAttachment); } } defer(function() { updateClasses(_this.target, addClasses, allClasses); return updateClasses(_this.element, addClasses, allClasses); }); return { top: top, left: left }; } }); }).call(this); (function() { var defer, getBounds, updateClasses, _ref; _ref = this.Tether.Utils, getBounds = _ref.getBounds, updateClasses = _ref.updateClasses, defer = _ref.defer; this.Tether.modules.push({ position: function(_arg) { 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, _this = this; top = _arg.top, left = _arg.left; _ref1 = this.cache('element-bounds', function() { return getBounds(_this.element); }), height = _ref1.height, width = _ref1.width; targetPos = this.getTargetBounds(); bottom = top + height; right = left + width; abutted = []; if (top <= targetPos.bottom && bottom >= targetPos.top) { _ref2 = ['left', 'right']; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { side = _ref2[_i]; if ((_ref3 = targetPos[side]) === left || _ref3 === right) { abutted.push(side); } } } if (left <= targetPos.right && right >= targetPos.left) { _ref4 = ['top', 'bottom']; for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) { side = _ref4[_j]; if ((_ref5 = targetPos[side]) === top || _ref5 === bottom) { abutted.push(side); } } } allClasses = []; addClasses = []; sides = ['left', 'top', 'right', 'bottom']; allClasses.push(this.getClass('abutted')); for (_k = 0, _len2 = sides.length; _k < _len2; _k++) { side = sides[_k]; allClasses.push("" + (this.getClass('abutted')) + "-" + side); } if (abutted.length) { addClasses.push(this.getClass('abutted')); } for (_l = 0, _len3 = abutted.length; _l < _len3; _l++) { side = abutted[_l]; addClasses.push("" + (this.getClass('abutted')) + "-" + side); } defer(function() { updateClasses(_this.target, addClasses, allClasses); return updateClasses(_this.element, addClasses, allClasses); }); return true; } }); }).call(this); (function() { this.Tether.modules.push({ position: function(_arg) { var left, result, shift, shiftLeft, shiftTop, top, _ref; top = _arg.top, left = _arg.left; if (!this.options.shift) { return; } result = function(val) { if (typeof val === 'function') { return val.call(this, { top: top, left: left }); } else { return val; } }; shift = result(this.options.shift); if (typeof shift === 'string') { shift = shift.split(' '); shift[1] || (shift[1] = shift[0]); shiftTop = shift[0], shiftLeft = shift[1]; shiftTop = parseFloat(shiftTop, 10); shiftLeft = parseFloat(shiftLeft, 10); } else { _ref = [shift.top, shift.left], shiftTop = _ref[0], shiftLeft = _ref[1]; } top += shiftTop; left += shiftLeft; return { top: top, left: left }; } }); }).call(this); return this.Tether; }));