Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
7.2 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * VERSION: 1.9.2
  3. * DATE: 2019-02-07
  4. * UPDATES AND DOCS AT: http://greensock.com
  5. *
  6. * @license Copyright (c) 2008-2019, GreenSock. All rights reserved.
  7. * This work is subject to the terms at http://greensock.com/standard-license or for
  8. * Club GreenSock members, the software agreement that was issued with your membership.
  9. *
  10. * @author: Jack Doyle, jack@greensock.com
  11. **/
  12. /* eslint-disable */
  13. import { _gsScope } from "./TweenLite.js";
  14. var _doc = (_gsScope.document || {}).documentElement,
  15. _window = _gsScope,
  16. _max = function(element, axis) {
  17. var dim = (axis === "x") ? "Width" : "Height",
  18. scroll = "scroll" + dim,
  19. client = "client" + dim,
  20. body = document.body;
  21. return (element === _window || element === _doc || element === body) ? Math.max(_doc[scroll], body[scroll]) - (_window["inner" + dim] || _doc[client] || body[client]) : element[scroll] - element["offset" + dim];
  22. },
  23. _unwrapElement = function(value) {
  24. if (typeof(value) === "string") {
  25. value = TweenLite.selector(value);
  26. }
  27. if (value.length && value !== _window && value[0] && value[0].style && !value.nodeType) {
  28. value = value[0];
  29. }
  30. return (value === _window || (value.nodeType && value.style)) ? value : null;
  31. },
  32. _buildGetter = function(e, axis) { //pass in an element and an axis ("x" or "y") and it'll return a getter function for the scroll position of that element (like scrollTop or scrollLeft, although if the element is the window, it'll use the pageXOffset/pageYOffset or the documentElement's scrollTop/scrollLeft or document.body's. Basically this streamlines things and makes a very fast getter across browsers.
  33. var p = "scroll" + ((axis === "x") ? "Left" : "Top");
  34. if (e === _window) {
  35. if (e.pageXOffset != null) {
  36. p = "page" + axis.toUpperCase() + "Offset";
  37. } else if (_doc[p] != null) {
  38. e = _doc;
  39. } else {
  40. e = document.body;
  41. }
  42. }
  43. return function() {
  44. return e[p];
  45. };
  46. },
  47. _getOffset = function(element, container) {
  48. var rect = _unwrapElement(element).getBoundingClientRect(),
  49. b = document.body,
  50. isRoot = (!container || container === _window || container === b),
  51. cRect = isRoot ? {top:_doc.clientTop - (window.pageYOffset || _doc.scrollTop || b.scrollTop || 0), left:_doc.clientLeft - (window.pageXOffset || _doc.scrollLeft || b.scrollLeft || 0)} : container.getBoundingClientRect(),
  52. offsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};
  53. if (!isRoot && container) { //only add the current scroll position if it's not the window/body.
  54. offsets.x += _buildGetter(container, "x")();
  55. offsets.y += _buildGetter(container, "y")();
  56. }
  57. return offsets;
  58. /* PREVIOUS
  59. var rect = _unwrapElement(element).getBoundingClientRect(),
  60. isRoot = (!container || container === _window || container === document.body),
  61. cRect = (isRoot ? _doc : container).getBoundingClientRect(),
  62. offsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};
  63. if (!isRoot && container) { //only add the current scroll position if it's not the window/body.
  64. offsets.x += _buildGetter(container, "x")();
  65. offsets.y += _buildGetter(container, "y")();
  66. }
  67. return offsets;
  68. */
  69. },
  70. _parseVal = function(value, target, axis, currentVal) {
  71. var type = typeof(value);
  72. return !isNaN(value) ? parseFloat(value) : (type === "string" && value.charAt(1) === "=") ? parseInt(value.charAt(0) + "1", 10) * parseFloat(value.substr(2)) + currentVal : (value === "max") ? _max(target, axis) : Math.min(_max(target, axis), _getOffset(value, target)[axis]);
  73. },
  74. ScrollToPlugin = _gsScope._gsDefine.plugin({
  75. propName: "scrollTo",
  76. API: 2,
  77. global: true,
  78. version:"1.9.2",
  79. //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
  80. init: function(target, value, tween) {
  81. this._wdw = (target === _window);
  82. this._target = target;
  83. this._tween = tween;
  84. if (typeof(value) !== "object") {
  85. value = {y:value}; //if we don't receive an object as the parameter, assume the user intends "y".
  86. if (typeof(value.y) === "string" && value.y !== "max" && value.y.charAt(1) !== "=") {
  87. value.x = value.y;
  88. }
  89. } else if (value.nodeType) {
  90. value = {y:value, x:value};
  91. }
  92. this.vars = value;
  93. this._autoKill = (value.autoKill !== false);
  94. this.getX = _buildGetter(target, "x");
  95. this.getY = _buildGetter(target, "y");
  96. this.x = this.xPrev = this.getX();
  97. this.y = this.yPrev = this.getY();
  98. if (value.x != null) {
  99. this._addTween(this, "x", this.x, _parseVal(value.x, target, "x", this.x) - (value.offsetX || 0), "scrollTo_x", true);
  100. this._overwriteProps.push("scrollTo_x");
  101. } else {
  102. this.skipX = true;
  103. }
  104. if (value.y != null) {
  105. this._addTween(this, "y", this.y, _parseVal(value.y, target, "y", this.y) - (value.offsetY || 0), "scrollTo_y", true);
  106. this._overwriteProps.push("scrollTo_y");
  107. } else {
  108. this.skipY = true;
  109. }
  110. return true;
  111. },
  112. //called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
  113. set: function(v) {
  114. this._super.setRatio.call(this, v);
  115. var x = (this._wdw || !this.skipX) ? this.getX() : this.xPrev,
  116. y = (this._wdw || !this.skipY) ? this.getY() : this.yPrev,
  117. yDif = y - this.yPrev,
  118. xDif = x - this.xPrev,
  119. threshold = ScrollToPlugin.autoKillThreshold;
  120. if (this.x < 0) { //can't scroll to a position less than 0! Might happen if someone uses a Back.easeOut or Elastic.easeOut when scrolling back to the top of the page (for example)
  121. this.x = 0;
  122. }
  123. if (this.y < 0) {
  124. this.y = 0;
  125. }
  126. if (this._autoKill) {
  127. //note: iOS has a bug that throws off the scroll by several pixels, so we need to check if it's within 7 pixels of the previous one that we set instead of just looking for an exact match.
  128. if (!this.skipX && (xDif > threshold || xDif < -threshold) && x < _max(this._target, "x")) {
  129. this.skipX = true; //if the user scrolls separately, we should stop tweening!
  130. }
  131. if (!this.skipY && (yDif > threshold || yDif < -threshold) && y < _max(this._target, "y")) {
  132. this.skipY = true; //if the user scrolls separately, we should stop tweening!
  133. }
  134. if (this.skipX && this.skipY) {
  135. this._tween.kill();
  136. if (this.vars.onAutoKill) {
  137. this.vars.onAutoKill.apply(this.vars.onAutoKillScope || this._tween, this.vars.onAutoKillParams || []);
  138. }
  139. }
  140. }
  141. if (this._wdw) {
  142. _window.scrollTo((!this.skipX) ? this.x : x, (!this.skipY) ? this.y : y);
  143. } else {
  144. if (!this.skipY) {
  145. this._target.scrollTop = this.y;
  146. }
  147. if (!this.skipX) {
  148. this._target.scrollLeft = this.x;
  149. }
  150. }
  151. this.xPrev = this.x;
  152. this.yPrev = this.y;
  153. }
  154. }),
  155. p = ScrollToPlugin.prototype;
  156. ScrollToPlugin.max = _max;
  157. ScrollToPlugin.getOffset = _getOffset;
  158. ScrollToPlugin.buildGetter = _buildGetter;
  159. ScrollToPlugin.autoKillThreshold = 7;
  160. p._kill = function(lookup) {
  161. if (lookup.scrollTo_x) {
  162. this.skipX = true;
  163. }
  164. if (lookup.scrollTo_y) {
  165. this.skipY = true;
  166. }
  167. return this._super._kill.call(this, lookup);
  168. };
  169. export { ScrollToPlugin, ScrollToPlugin as default };