tether.js 55 KB

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