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.

427 lines
15 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. /**
  16. * @class Ext.Element
  17. */
  18. Ext.Element.addMethods({
  19. <div id="method-Ext.Element-getAnchorXY"></div>/**
  20. * Gets the x,y coordinates specified by the anchor position on the element.
  21. * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo}
  22. * for details on supported anchor positions.
  23. * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead
  24. * of page coordinates
  25. * @param {Object} size (optional) An object containing the size to use for calculating anchor position
  26. * {width: (target width), height: (target height)} (defaults to the element's current size)
  27. * @return {Array} [x, y] An array containing the element's x and y coordinates
  28. */
  29. getAnchorXY : function(anchor, local, s){
  30. //Passing a different size is useful for pre-calculating anchors,
  31. //especially for anchored animations that change the el size.
  32. anchor = (anchor || "tl").toLowerCase();
  33. s = s || {};
  34. var me = this,
  35. vp = me.dom == document.body || me.dom == document,
  36. w = s.width || vp ? Ext.lib.Dom.getViewWidth() : me.getWidth(),
  37. h = s.height || vp ? Ext.lib.Dom.getViewHeight() : me.getHeight(),
  38. xy,
  39. r = Math.round,
  40. o = me.getXY(),
  41. scroll = me.getScroll(),
  42. extraX = vp ? scroll.left : !local ? o[0] : 0,
  43. extraY = vp ? scroll.top : !local ? o[1] : 0,
  44. hash = {
  45. c : [r(w * 0.5), r(h * 0.5)],
  46. t : [r(w * 0.5), 0],
  47. l : [0, r(h * 0.5)],
  48. r : [w, r(h * 0.5)],
  49. b : [r(w * 0.5), h],
  50. tl : [0, 0],
  51. bl : [0, h],
  52. br : [w, h],
  53. tr : [w, 0]
  54. };
  55. xy = hash[anchor];
  56. return [xy[0] + extraX, xy[1] + extraY];
  57. },
  58. <div id="method-Ext.Element-anchorTo"></div>/**
  59. * Anchors an element to another element and realigns it when the window is resized.
  60. * @param {Mixed} element The element to align to.
  61. * @param {String} position The position to align to.
  62. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  63. * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
  64. * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
  65. * is a number, it is used as the buffer delay (defaults to 50ms).
  66. * @param {Function} callback The function to call after the animation finishes
  67. * @return {Ext.Element} this
  68. */
  69. anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
  70. var me = this,
  71. dom = me.dom,
  72. scroll = !Ext.isEmpty(monitorScroll),
  73. action = function(){
  74. Ext.fly(dom).alignTo(el, alignment, offsets, animate);
  75. Ext.callback(callback, Ext.fly(dom));
  76. },
  77. anchor = this.getAnchor();
  78. // previous listener anchor, remove it
  79. this.removeAnchor();
  80. Ext.apply(anchor, {
  81. fn: action,
  82. scroll: scroll
  83. });
  84. Ext.EventManager.onWindowResize(action, null);
  85. if(scroll){
  86. Ext.EventManager.on(window, 'scroll', action, null,
  87. {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
  88. }
  89. action.call(me); // align immediately
  90. return me;
  91. },
  92. <div id="method-Ext.Element-removeAnchor"></div>/**
  93. * Remove any anchor to this element. See {@link #anchorTo}.
  94. * @return {Ext.Element} this
  95. */
  96. removeAnchor : function(){
  97. var me = this,
  98. anchor = this.getAnchor();
  99. if(anchor && anchor.fn){
  100. Ext.EventManager.removeResizeListener(anchor.fn);
  101. if(anchor.scroll){
  102. Ext.EventManager.un(window, 'scroll', anchor.fn);
  103. }
  104. delete anchor.fn;
  105. }
  106. return me;
  107. },
  108. // private
  109. getAnchor : function(){
  110. var data = Ext.Element.data,
  111. dom = this.dom;
  112. if (!dom) {
  113. return;
  114. }
  115. var anchor = data(dom, '_anchor');
  116. if(!anchor){
  117. anchor = data(dom, '_anchor', {});
  118. }
  119. return anchor;
  120. },
  121. <div id="method-Ext.Element-getAlignToXY"></div>/**
  122. * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
  123. * supported position values.
  124. * @param {Mixed} element The element to align to.
  125. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  126. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  127. * @return {Array} [x, y]
  128. */
  129. getAlignToXY : function(el, p, o){
  130. el = Ext.get(el);
  131. if(!el || !el.dom){
  132. throw "Element.alignToXY with an element that doesn't exist";
  133. }
  134. o = o || [0,0];
  135. p = (!p || p == "?" ? "tl-bl?" : (!(/-/).test(p) && p !== "" ? "tl-" + p : p || "tl-bl")).toLowerCase();
  136. var me = this,
  137. d = me.dom,
  138. a1,
  139. a2,
  140. x,
  141. y,
  142. //constrain the aligned el to viewport if necessary
  143. w,
  144. h,
  145. r,
  146. dw = Ext.lib.Dom.getViewWidth() -10, // 10px of margin for ie
  147. dh = Ext.lib.Dom.getViewHeight()-10, // 10px of margin for ie
  148. p1y,
  149. p1x,
  150. p2y,
  151. p2x,
  152. swapY,
  153. swapX,
  154. doc = document,
  155. docElement = doc.documentElement,
  156. docBody = doc.body,
  157. scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0)+5,
  158. scrollY = (docElement.scrollTop || docBody.scrollTop || 0)+5,
  159. c = false, //constrain to viewport
  160. p1 = "",
  161. p2 = "",
  162. m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  163. if(!m){
  164. throw "Element.alignTo with an invalid alignment " + p;
  165. }
  166. p1 = m[1];
  167. p2 = m[2];
  168. c = !!m[3];
  169. //Subtract the aligned el's internal xy from the target's offset xy
  170. //plus custom offset to get the aligned el's new offset xy
  171. a1 = me.getAnchorXY(p1, true);
  172. a2 = el.getAnchorXY(p2, false);
  173. x = a2[0] - a1[0] + o[0];
  174. y = a2[1] - a1[1] + o[1];
  175. if(c){
  176. w = me.getWidth();
  177. h = me.getHeight();
  178. r = el.getRegion();
  179. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  180. //perpendicular to the vp border, allow the aligned el to slide on that border,
  181. //otherwise swap the aligned el to the opposite border of the target.
  182. p1y = p1.charAt(0);
  183. p1x = p1.charAt(p1.length-1);
  184. p2y = p2.charAt(0);
  185. p2x = p2.charAt(p2.length-1);
  186. swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
  187. swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
  188. if (x + w > dw + scrollX) {
  189. x = swapX ? r.left-w : dw+scrollX-w;
  190. }
  191. if (x < scrollX) {
  192. x = swapX ? r.right : scrollX;
  193. }
  194. if (y + h > dh + scrollY) {
  195. y = swapY ? r.top-h : dh+scrollY-h;
  196. }
  197. if (y < scrollY){
  198. y = swapY ? r.bottom : scrollY;
  199. }
  200. }
  201. return [x,y];
  202. },
  203. <div id="method-Ext.Element-alignTo"></div>/**
  204. * Aligns this element with another element relative to the specified anchor points. If the other element is the
  205. * document it aligns it to the viewport.
  206. * The position parameter is optional, and can be specified in any one of the following formats:
  207. * <ul>
  208. * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
  209. * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
  210. * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
  211. * deprecated in favor of the newer two anchor syntax below</i>.</li>
  212. * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
  213. * element's anchor point, and the second value is used as the target's anchor point.</li>
  214. * </ul>
  215. * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
  216. * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
  217. * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
  218. * that specified in order to enforce the viewport constraints.
  219. * Following are all of the supported anchor positions:
  220. <pre>
  221. Value Description
  222. ----- -----------------------------
  223. tl The top left corner (default)
  224. t The center of the top edge
  225. tr The top right corner
  226. l The center of the left edge
  227. c In the center of the element
  228. r The center of the right edge
  229. bl The bottom left corner
  230. b The center of the bottom edge
  231. br The bottom right corner
  232. </pre>
  233. Example Usage:
  234. <pre><code>
  235. // align el to other-el using the default positioning ("tl-bl", non-constrained)
  236. el.alignTo("other-el");
  237. // align the top left corner of el with the top right corner of other-el (constrained to viewport)
  238. el.alignTo("other-el", "tr?");
  239. // align the bottom right corner of el with the center left edge of other-el
  240. el.alignTo("other-el", "br-l?");
  241. // align the center of el with the bottom left corner of other-el and
  242. // adjust the x position by -6 pixels (and the y position by 0)
  243. el.alignTo("other-el", "c-bl", [-6, 0]);
  244. </code></pre>
  245. * @param {Mixed} element The element to align to.
  246. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  247. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  248. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  249. * @return {Ext.Element} this
  250. */
  251. alignTo : function(element, position, offsets, animate){
  252. var me = this;
  253. return me.setXY(me.getAlignToXY(element, position, offsets),
  254. me.preanim && !!animate ? me.preanim(arguments, 3) : false);
  255. },
  256. // private ==> used outside of core
  257. adjustForConstraints : function(xy, parent, offsets){
  258. return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
  259. },
  260. // private ==> used outside of core
  261. getConstrainToXY : function(el, local, offsets, proposedXY){
  262. var os = {top:0, left:0, bottom:0, right: 0};
  263. return function(el, local, offsets, proposedXY){
  264. el = Ext.get(el);
  265. offsets = offsets ? Ext.applyIf(offsets, os) : os;
  266. var vw, vh, vx = 0, vy = 0;
  267. if(el.dom == document.body || el.dom == document){
  268. vw =Ext.lib.Dom.getViewWidth();
  269. vh = Ext.lib.Dom.getViewHeight();
  270. }else{
  271. vw = el.dom.clientWidth;
  272. vh = el.dom.clientHeight;
  273. if(!local){
  274. var vxy = el.getXY();
  275. vx = vxy[0];
  276. vy = vxy[1];
  277. }
  278. }
  279. var s = el.getScroll();
  280. vx += offsets.left + s.left;
  281. vy += offsets.top + s.top;
  282. vw -= offsets.right;
  283. vh -= offsets.bottom;
  284. var vr = vx + vw,
  285. vb = vy + vh,
  286. xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]),
  287. x = xy[0], y = xy[1],
  288. offset = this.getConstrainOffset(),
  289. w = this.dom.offsetWidth + offset,
  290. h = this.dom.offsetHeight + offset;
  291. // only move it if it needs it
  292. var moved = false;
  293. // first validate right/bottom
  294. if((x + w) > vr){
  295. x = vr - w;
  296. moved = true;
  297. }
  298. if((y + h) > vb){
  299. y = vb - h;
  300. moved = true;
  301. }
  302. // then make sure top/left isn't negative
  303. if(x < vx){
  304. x = vx;
  305. moved = true;
  306. }
  307. if(y < vy){
  308. y = vy;
  309. moved = true;
  310. }
  311. return moved ? [x, y] : false;
  312. };
  313. }(),
  314. // el = Ext.get(el);
  315. // offsets = Ext.applyIf(offsets || {}, {top : 0, left : 0, bottom : 0, right : 0});
  316. // var me = this,
  317. // doc = document,
  318. // s = el.getScroll(),
  319. // vxy = el.getXY(),
  320. // vx = offsets.left + s.left,
  321. // vy = offsets.top + s.top,
  322. // vw = -offsets.right,
  323. // vh = -offsets.bottom,
  324. // vr,
  325. // vb,
  326. // xy = proposedXY || (!local ? me.getXY() : [me.getLeft(true), me.getTop(true)]),
  327. // x = xy[0],
  328. // y = xy[1],
  329. // w = me.dom.offsetWidth, h = me.dom.offsetHeight,
  330. // moved = false; // only move it if it needs it
  331. //
  332. //
  333. // if(el.dom == doc.body || el.dom == doc){
  334. // vw += Ext.lib.Dom.getViewWidth();
  335. // vh += Ext.lib.Dom.getViewHeight();
  336. // }else{
  337. // vw += el.dom.clientWidth;
  338. // vh += el.dom.clientHeight;
  339. // if(!local){
  340. // vx += vxy[0];
  341. // vy += vxy[1];
  342. // }
  343. // }
  344. // // first validate right/bottom
  345. // if(x + w > vx + vw){
  346. // x = vx + vw - w;
  347. // moved = true;
  348. // }
  349. // if(y + h > vy + vh){
  350. // y = vy + vh - h;
  351. // moved = true;
  352. // }
  353. // // then make sure top/left isn't negative
  354. // if(x < vx){
  355. // x = vx;
  356. // moved = true;
  357. // }
  358. // if(y < vy){
  359. // y = vy;
  360. // moved = true;
  361. // }
  362. // return moved ? [x, y] : false;
  363. // },
  364. // private, used internally
  365. getConstrainOffset : function(){
  366. return 0;
  367. },
  368. <div id="method-Ext.Element-getCenterXY"></div>/**
  369. * Calculates the x, y to center this element on the screen
  370. * @return {Array} The x, y values [x, y]
  371. */
  372. getCenterXY : function(){
  373. return this.getAlignToXY(document, 'c-c');
  374. },
  375. <div id="method-Ext.Element-center"></div>/**
  376. * Centers the Element in either the viewport, or another Element.
  377. * @param {Mixed} centerIn (optional) The element in which to center the element.
  378. */
  379. center : function(centerIn){
  380. return this.alignTo(centerIn || document, 'c-c');
  381. }
  382. });
  383. </pre>
  384. </body>
  385. </html>