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.

479 lines
14 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. <div id="cls-Ext.Layer"></div>/**
  16. * @class Ext.Layer
  17. * @extends Ext.Element
  18. * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
  19. * automatic maintaining of shadow/shim positions.
  20. * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
  21. * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
  22. * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
  23. * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
  24. * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
  25. * @cfg {String} cls CSS class to add to the element
  26. * @cfg {Number} zindex Starting z-index (defaults to 11000)
  27. * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
  28. * @cfg {Boolean} useDisplay
  29. * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
  30. * to use css style <tt>'display:none;'</tt> to hide the Layer.
  31. * @constructor
  32. * @param {Object} config An object with config options.
  33. * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
  34. */
  35. (function(){
  36. Ext.Layer = function(config, existingEl){
  37. config = config || {};
  38. var dh = Ext.DomHelper,
  39. cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
  40. if (existingEl) {
  41. this.dom = Ext.getDom(existingEl);
  42. }
  43. if(!this.dom){
  44. var o = config.dh || {tag: 'div', cls: 'x-layer'};
  45. this.dom = dh.append(pel, o);
  46. }
  47. if(config.cls){
  48. this.addClass(config.cls);
  49. }
  50. this.constrain = config.constrain !== false;
  51. this.setVisibilityMode(Ext.Element.VISIBILITY);
  52. if(config.id){
  53. this.id = this.dom.id = config.id;
  54. }else{
  55. this.id = Ext.id(this.dom);
  56. }
  57. this.zindex = config.zindex || this.getZIndex();
  58. this.position('absolute', this.zindex);
  59. if(config.shadow){
  60. this.shadowOffset = config.shadowOffset || 4;
  61. this.shadow = new Ext.Shadow({
  62. offset : this.shadowOffset,
  63. mode : config.shadow
  64. });
  65. }else{
  66. this.shadowOffset = 0;
  67. }
  68. this.useShim = config.shim !== false && Ext.useShims;
  69. this.useDisplay = config.useDisplay;
  70. this.hide();
  71. };
  72. var supr = Ext.Element.prototype;
  73. // shims are shared among layer to keep from having 100 iframes
  74. var shims = [];
  75. Ext.extend(Ext.Layer, Ext.Element, {
  76. getZIndex : function(){
  77. return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
  78. },
  79. getShim : function(){
  80. if(!this.useShim){
  81. return null;
  82. }
  83. if(this.shim){
  84. return this.shim;
  85. }
  86. var shim = shims.shift();
  87. if(!shim){
  88. shim = this.createShim();
  89. shim.enableDisplayMode('block');
  90. shim.dom.style.display = 'none';
  91. shim.dom.style.visibility = 'visible';
  92. }
  93. var pn = this.dom.parentNode;
  94. if(shim.dom.parentNode != pn){
  95. pn.insertBefore(shim.dom, this.dom);
  96. }
  97. shim.setStyle('z-index', this.getZIndex()-2);
  98. this.shim = shim;
  99. return shim;
  100. },
  101. hideShim : function(){
  102. if(this.shim){
  103. this.shim.setDisplayed(false);
  104. shims.push(this.shim);
  105. delete this.shim;
  106. }
  107. },
  108. disableShadow : function(){
  109. if(this.shadow){
  110. this.shadowDisabled = true;
  111. this.shadow.hide();
  112. this.lastShadowOffset = this.shadowOffset;
  113. this.shadowOffset = 0;
  114. }
  115. },
  116. enableShadow : function(show){
  117. if(this.shadow){
  118. this.shadowDisabled = false;
  119. this.shadowOffset = this.lastShadowOffset;
  120. delete this.lastShadowOffset;
  121. if(show){
  122. this.sync(true);
  123. }
  124. }
  125. },
  126. // private
  127. // this code can execute repeatedly in milliseconds (i.e. during a drag) so
  128. // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
  129. sync : function(doShow){
  130. var shadow = this.shadow;
  131. if(!this.updating && this.isVisible() && (shadow || this.useShim)){
  132. var shim = this.getShim(),
  133. w = this.getWidth(),
  134. h = this.getHeight(),
  135. l = this.getLeft(true),
  136. t = this.getTop(true);
  137. if(shadow && !this.shadowDisabled){
  138. if(doShow && !shadow.isVisible()){
  139. shadow.show(this);
  140. }else{
  141. shadow.realign(l, t, w, h);
  142. }
  143. if(shim){
  144. if(doShow){
  145. shim.show();
  146. }
  147. // fit the shim behind the shadow, so it is shimmed too
  148. var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
  149. shadowSize = shadow.el.getSize();
  150. shimStyle.left = (shadowAdj[0])+'px';
  151. shimStyle.top = (shadowAdj[1])+'px';
  152. shimStyle.width = (shadowSize.width)+'px';
  153. shimStyle.height = (shadowSize.height)+'px';
  154. }
  155. }else if(shim){
  156. if(doShow){
  157. shim.show();
  158. }
  159. shim.setSize(w, h);
  160. shim.setLeftTop(l, t);
  161. }
  162. }
  163. },
  164. // private
  165. destroy : function(){
  166. this.hideShim();
  167. if(this.shadow){
  168. this.shadow.hide();
  169. }
  170. this.removeAllListeners();
  171. Ext.removeNode(this.dom);
  172. delete this.dom;
  173. },
  174. remove : function(){
  175. this.destroy();
  176. },
  177. // private
  178. beginUpdate : function(){
  179. this.updating = true;
  180. },
  181. // private
  182. endUpdate : function(){
  183. this.updating = false;
  184. this.sync(true);
  185. },
  186. // private
  187. hideUnders : function(negOffset){
  188. if(this.shadow){
  189. this.shadow.hide();
  190. }
  191. this.hideShim();
  192. },
  193. // private
  194. constrainXY : function(){
  195. if(this.constrain){
  196. var vw = Ext.lib.Dom.getViewWidth(),
  197. vh = Ext.lib.Dom.getViewHeight();
  198. var s = Ext.getDoc().getScroll();
  199. var xy = this.getXY();
  200. var x = xy[0], y = xy[1];
  201. var so = this.shadowOffset;
  202. var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
  203. // only move it if it needs it
  204. var moved = false;
  205. // first validate right/bottom
  206. if((x + w) > vw+s.left){
  207. x = vw - w - so;
  208. moved = true;
  209. }
  210. if((y + h) > vh+s.top){
  211. y = vh - h - so;
  212. moved = true;
  213. }
  214. // then make sure top/left isn't negative
  215. if(x < s.left){
  216. x = s.left;
  217. moved = true;
  218. }
  219. if(y < s.top){
  220. y = s.top;
  221. moved = true;
  222. }
  223. if(moved){
  224. if(this.avoidY){
  225. var ay = this.avoidY;
  226. if(y <= ay && (y+h) >= ay){
  227. y = ay-h-5;
  228. }
  229. }
  230. xy = [x, y];
  231. this.storeXY(xy);
  232. supr.setXY.call(this, xy);
  233. this.sync();
  234. }
  235. }
  236. return this;
  237. },
  238. getConstrainOffset : function(){
  239. return this.shadowOffset;
  240. },
  241. isVisible : function(){
  242. return this.visible;
  243. },
  244. // private
  245. showAction : function(){
  246. this.visible = true; // track visibility to prevent getStyle calls
  247. if(this.useDisplay === true){
  248. this.setDisplayed('');
  249. }else if(this.lastXY){
  250. supr.setXY.call(this, this.lastXY);
  251. }else if(this.lastLT){
  252. supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
  253. }
  254. },
  255. // private
  256. hideAction : function(){
  257. this.visible = false;
  258. if(this.useDisplay === true){
  259. this.setDisplayed(false);
  260. }else{
  261. this.setLeftTop(-10000,-10000);
  262. }
  263. },
  264. // overridden Element method
  265. setVisible : function(v, a, d, c, e){
  266. if(v){
  267. this.showAction();
  268. }
  269. if(a && v){
  270. var cb = function(){
  271. this.sync(true);
  272. if(c){
  273. c();
  274. }
  275. }.createDelegate(this);
  276. supr.setVisible.call(this, true, true, d, cb, e);
  277. }else{
  278. if(!v){
  279. this.hideUnders(true);
  280. }
  281. var cb = c;
  282. if(a){
  283. cb = function(){
  284. this.hideAction();
  285. if(c){
  286. c();
  287. }
  288. }.createDelegate(this);
  289. }
  290. supr.setVisible.call(this, v, a, d, cb, e);
  291. if(v){
  292. this.sync(true);
  293. }else if(!a){
  294. this.hideAction();
  295. }
  296. }
  297. return this;
  298. },
  299. storeXY : function(xy){
  300. delete this.lastLT;
  301. this.lastXY = xy;
  302. },
  303. storeLeftTop : function(left, top){
  304. delete this.lastXY;
  305. this.lastLT = [left, top];
  306. },
  307. // private
  308. beforeFx : function(){
  309. this.beforeAction();
  310. return Ext.Layer.superclass.beforeFx.apply(this, arguments);
  311. },
  312. // private
  313. afterFx : function(){
  314. Ext.Layer.superclass.afterFx.apply(this, arguments);
  315. this.sync(this.isVisible());
  316. },
  317. // private
  318. beforeAction : function(){
  319. if(!this.updating && this.shadow){
  320. this.shadow.hide();
  321. }
  322. },
  323. // overridden Element method
  324. setLeft : function(left){
  325. this.storeLeftTop(left, this.getTop(true));
  326. supr.setLeft.apply(this, arguments);
  327. this.sync();
  328. return this;
  329. },
  330. setTop : function(top){
  331. this.storeLeftTop(this.getLeft(true), top);
  332. supr.setTop.apply(this, arguments);
  333. this.sync();
  334. return this;
  335. },
  336. setLeftTop : function(left, top){
  337. this.storeLeftTop(left, top);
  338. supr.setLeftTop.apply(this, arguments);
  339. this.sync();
  340. return this;
  341. },
  342. setXY : function(xy, a, d, c, e){
  343. this.fixDisplay();
  344. this.beforeAction();
  345. this.storeXY(xy);
  346. var cb = this.createCB(c);
  347. supr.setXY.call(this, xy, a, d, cb, e);
  348. if(!a){
  349. cb();
  350. }
  351. return this;
  352. },
  353. // private
  354. createCB : function(c){
  355. var el = this;
  356. return function(){
  357. el.constrainXY();
  358. el.sync(true);
  359. if(c){
  360. c();
  361. }
  362. };
  363. },
  364. // overridden Element method
  365. setX : function(x, a, d, c, e){
  366. this.setXY([x, this.getY()], a, d, c, e);
  367. return this;
  368. },
  369. // overridden Element method
  370. setY : function(y, a, d, c, e){
  371. this.setXY([this.getX(), y], a, d, c, e);
  372. return this;
  373. },
  374. // overridden Element method
  375. setSize : function(w, h, a, d, c, e){
  376. this.beforeAction();
  377. var cb = this.createCB(c);
  378. supr.setSize.call(this, w, h, a, d, cb, e);
  379. if(!a){
  380. cb();
  381. }
  382. return this;
  383. },
  384. // overridden Element method
  385. setWidth : function(w, a, d, c, e){
  386. this.beforeAction();
  387. var cb = this.createCB(c);
  388. supr.setWidth.call(this, w, a, d, cb, e);
  389. if(!a){
  390. cb();
  391. }
  392. return this;
  393. },
  394. // overridden Element method
  395. setHeight : function(h, a, d, c, e){
  396. this.beforeAction();
  397. var cb = this.createCB(c);
  398. supr.setHeight.call(this, h, a, d, cb, e);
  399. if(!a){
  400. cb();
  401. }
  402. return this;
  403. },
  404. // overridden Element method
  405. setBounds : function(x, y, w, h, a, d, c, e){
  406. this.beforeAction();
  407. var cb = this.createCB(c);
  408. if(!a){
  409. this.storeXY([x, y]);
  410. supr.setXY.call(this, [x, y]);
  411. supr.setSize.call(this, w, h, a, d, cb, e);
  412. cb();
  413. }else{
  414. supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
  415. }
  416. return this;
  417. },
  418. /**
  419. * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
  420. * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
  421. * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
  422. * @param {Number} zindex The new z-index to set
  423. * @return {this} The Layer
  424. */
  425. setZIndex : function(zindex){
  426. this.zindex = zindex;
  427. this.setStyle('z-index', zindex + 2);
  428. if(this.shadow){
  429. this.shadow.setZIndex(zindex + 1);
  430. }
  431. if(this.shim){
  432. this.shim.setStyle('z-index', zindex);
  433. }
  434. return this;
  435. }
  436. });
  437. })();
  438. </pre>
  439. </body>
  440. </html>