Web Interface For Lite Argus Control modules
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.

548 lines
19 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.ToolTip"></div>/**
  16. * @class Ext.ToolTip
  17. * @extends Ext.Tip
  18. * A standard tooltip implementation for providing additional information when hovering over a target element.
  19. * @xtype tooltip
  20. * @constructor
  21. * Create a new Tooltip
  22. * @param {Object} config The configuration options
  23. */
  24. Ext.ToolTip = Ext.extend(Ext.Tip, {
  25. <div id="prop-Ext.ToolTip-triggerElement"></div>/**
  26. * When a Tooltip is configured with the <code>{@link #delegate}</code>
  27. * option to cause selected child elements of the <code>{@link #target}</code>
  28. * Element to each trigger a seperate show event, this property is set to
  29. * the DOM element which triggered the show.
  30. * @type DOMElement
  31. * @property triggerElement
  32. */
  33. <div id="cfg-Ext.ToolTip-target"></div>/**
  34. * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to monitor
  35. * for mouseover events to trigger showing this ToolTip.
  36. */
  37. <div id="cfg-Ext.ToolTip-autoHide"></div>/**
  38. * @cfg {Boolean} autoHide True to automatically hide the tooltip after the
  39. * mouse exits the target element or after the <code>{@link #dismissDelay}</code>
  40. * has expired if set (defaults to true). If <code>{@link closable} = true</code>
  41. * a close tool button will be rendered into the tooltip header.
  42. */
  43. <div id="cfg-Ext.ToolTip-showDelay"></div>/**
  44. * @cfg {Number} showDelay Delay in milliseconds before the tooltip displays
  45. * after the mouse enters the target element (defaults to 500)
  46. */
  47. showDelay : 500,
  48. <div id="cfg-Ext.ToolTip-hideDelay"></div>/**
  49. * @cfg {Number} hideDelay Delay in milliseconds after the mouse exits the
  50. * target element but before the tooltip actually hides (defaults to 200).
  51. * Set to 0 for the tooltip to hide immediately.
  52. */
  53. hideDelay : 200,
  54. <div id="cfg-Ext.ToolTip-dismissDelay"></div>/**
  55. * @cfg {Number} dismissDelay Delay in milliseconds before the tooltip
  56. * automatically hides (defaults to 5000). To disable automatic hiding, set
  57. * dismissDelay = 0.
  58. */
  59. dismissDelay : 5000,
  60. <div id="cfg-Ext.ToolTip-mouseOffset"></div>/**
  61. * @cfg {Array} mouseOffset An XY offset from the mouse position where the
  62. * tooltip should be shown (defaults to [15,18]).
  63. */
  64. <div id="cfg-Ext.ToolTip-trackMouse"></div>/**
  65. * @cfg {Boolean} trackMouse True to have the tooltip follow the mouse as it
  66. * moves over the target element (defaults to false).
  67. */
  68. trackMouse : false,
  69. <div id="cfg-Ext.ToolTip-anchorToTarget"></div>/**
  70. * @cfg {Boolean} anchorToTarget True to anchor the tooltip to the target
  71. * element, false to anchor it relative to the mouse coordinates (defaults
  72. * to true). When <code>anchorToTarget</code> is true, use
  73. * <code>{@link #defaultAlign}</code> to control tooltip alignment to the
  74. * target element. When <code>anchorToTarget</code> is false, use
  75. * <code>{@link #anchorPosition}</code> instead to control alignment.
  76. */
  77. anchorToTarget : true,
  78. <div id="cfg-Ext.ToolTip-anchorOffset"></div>/**
  79. * @cfg {Number} anchorOffset A numeric pixel value used to offset the
  80. * default position of the anchor arrow (defaults to 0). When the anchor
  81. * position is on the top or bottom of the tooltip, <code>anchorOffset</code>
  82. * will be used as a horizontal offset. Likewise, when the anchor position
  83. * is on the left or right side, <code>anchorOffset</code> will be used as
  84. * a vertical offset.
  85. */
  86. anchorOffset : 0,
  87. <div id="cfg-Ext.ToolTip-delegate"></div>/**
  88. * @cfg {String} delegate <p>Optional. A {@link Ext.DomQuery DomQuery}
  89. * selector which allows selection of individual elements within the
  90. * <code>{@link #target}</code> element to trigger showing and hiding the
  91. * ToolTip as the mouse moves within the target.</p>
  92. * <p>When specified, the child element of the target which caused a show
  93. * event is placed into the <code>{@link #triggerElement}</code> property
  94. * before the ToolTip is shown.</p>
  95. * <p>This may be useful when a Component has regular, repeating elements
  96. * in it, each of which need a Tooltip which contains information specific
  97. * to that element. For example:</p><pre><code>
  98. var myGrid = new Ext.grid.gridPanel(gridConfig);
  99. myGrid.on('render', function(grid) {
  100. var store = grid.getStore(); // Capture the Store.
  101. var view = grid.getView(); // Capture the GridView.
  102. myGrid.tip = new Ext.ToolTip({
  103. target: view.mainBody, // The overall target element.
  104. delegate: '.x-grid3-row', // Each grid row causes its own seperate show and hide.
  105. trackMouse: true, // Moving within the row should not hide the tip.
  106. renderTo: document.body, // Render immediately so that tip.body can be
  107. // referenced prior to the first show.
  108. listeners: { // Change content dynamically depending on which element
  109. // triggered the show.
  110. beforeshow: function updateTipBody(tip) {
  111. var rowIndex = view.findRowIndex(tip.triggerElement);
  112. tip.body.dom.innerHTML = 'Over Record ID ' + store.getAt(rowIndex).id;
  113. }
  114. }
  115. });
  116. });
  117. *</code></pre>
  118. */
  119. // private
  120. targetCounter : 0,
  121. constrainPosition : false,
  122. // private
  123. initComponent : function(){
  124. Ext.ToolTip.superclass.initComponent.call(this);
  125. this.lastActive = new Date();
  126. this.initTarget(this.target);
  127. this.origAnchor = this.anchor;
  128. },
  129. // private
  130. onRender : function(ct, position){
  131. Ext.ToolTip.superclass.onRender.call(this, ct, position);
  132. this.anchorCls = 'x-tip-anchor-' + this.getAnchorPosition();
  133. this.anchorEl = this.el.createChild({
  134. cls: 'x-tip-anchor ' + this.anchorCls
  135. });
  136. },
  137. // private
  138. afterRender : function(){
  139. Ext.ToolTip.superclass.afterRender.call(this);
  140. this.anchorEl.setStyle('z-index', this.el.getZIndex() + 1).setVisibilityMode(Ext.Element.DISPLAY);
  141. },
  142. <div id="method-Ext.ToolTip-initTarget"></div>/**
  143. * Binds this ToolTip to the specified element. The tooltip will be displayed when the mouse moves over the element.
  144. * @param {Mixed} t The Element, HtmlElement, or ID of an element to bind to
  145. */
  146. initTarget : function(target){
  147. var t;
  148. if((t = Ext.get(target))){
  149. if(this.target){
  150. var tg = Ext.get(this.target);
  151. this.mun(tg, 'mouseover', this.onTargetOver, this);
  152. this.mun(tg, 'mouseout', this.onTargetOut, this);
  153. this.mun(tg, 'mousemove', this.onMouseMove, this);
  154. }
  155. this.mon(t, {
  156. mouseover: this.onTargetOver,
  157. mouseout: this.onTargetOut,
  158. mousemove: this.onMouseMove,
  159. scope: this
  160. });
  161. this.target = t;
  162. }
  163. if(this.anchor){
  164. this.anchorTarget = this.target;
  165. }
  166. },
  167. // private
  168. onMouseMove : function(e){
  169. var t = this.delegate ? e.getTarget(this.delegate) : this.triggerElement = true;
  170. if (t) {
  171. this.targetXY = e.getXY();
  172. if (t === this.triggerElement) {
  173. if(!this.hidden && this.trackMouse){
  174. this.setPagePosition(this.getTargetXY());
  175. }
  176. } else {
  177. this.hide();
  178. this.lastActive = new Date(0);
  179. this.onTargetOver(e);
  180. }
  181. } else if (!this.closable && this.isVisible()) {
  182. this.hide();
  183. }
  184. },
  185. // private
  186. getTargetXY : function(){
  187. if(this.delegate){
  188. this.anchorTarget = this.triggerElement;
  189. }
  190. if(this.anchor){
  191. this.targetCounter++;
  192. var offsets = this.getOffsets(),
  193. xy = (this.anchorToTarget && !this.trackMouse) ? this.el.getAlignToXY(this.anchorTarget, this.getAnchorAlign()) : this.targetXY,
  194. dw = Ext.lib.Dom.getViewWidth() - 5,
  195. dh = Ext.lib.Dom.getViewHeight() - 5,
  196. de = document.documentElement,
  197. bd = document.body,
  198. scrollX = (de.scrollLeft || bd.scrollLeft || 0) + 5,
  199. scrollY = (de.scrollTop || bd.scrollTop || 0) + 5,
  200. axy = [xy[0] + offsets[0], xy[1] + offsets[1]],
  201. sz = this.getSize();
  202. this.anchorEl.removeClass(this.anchorCls);
  203. if(this.targetCounter < 2){
  204. if(axy[0] < scrollX){
  205. if(this.anchorToTarget){
  206. this.defaultAlign = 'l-r';
  207. if(this.mouseOffset){this.mouseOffset[0] *= -1;}
  208. }
  209. this.anchor = 'left';
  210. return this.getTargetXY();
  211. }
  212. if(axy[0]+sz.width > dw){
  213. if(this.anchorToTarget){
  214. this.defaultAlign = 'r-l';
  215. if(this.mouseOffset){this.mouseOffset[0] *= -1;}
  216. }
  217. this.anchor = 'right';
  218. return this.getTargetXY();
  219. }
  220. if(axy[1] < scrollY){
  221. if(this.anchorToTarget){
  222. this.defaultAlign = 't-b';
  223. if(this.mouseOffset){this.mouseOffset[1] *= -1;}
  224. }
  225. this.anchor = 'top';
  226. return this.getTargetXY();
  227. }
  228. if(axy[1]+sz.height > dh){
  229. if(this.anchorToTarget){
  230. this.defaultAlign = 'b-t';
  231. if(this.mouseOffset){this.mouseOffset[1] *= -1;}
  232. }
  233. this.anchor = 'bottom';
  234. return this.getTargetXY();
  235. }
  236. }
  237. this.anchorCls = 'x-tip-anchor-'+this.getAnchorPosition();
  238. this.anchorEl.addClass(this.anchorCls);
  239. this.targetCounter = 0;
  240. return axy;
  241. }else{
  242. var mouseOffset = this.getMouseOffset();
  243. return [this.targetXY[0]+mouseOffset[0], this.targetXY[1]+mouseOffset[1]];
  244. }
  245. },
  246. getMouseOffset : function(){
  247. var offset = this.anchor ? [0,0] : [15,18];
  248. if(this.mouseOffset){
  249. offset[0] += this.mouseOffset[0];
  250. offset[1] += this.mouseOffset[1];
  251. }
  252. return offset;
  253. },
  254. // private
  255. getAnchorPosition : function(){
  256. if(this.anchor){
  257. this.tipAnchor = this.anchor.charAt(0);
  258. }else{
  259. var m = this.defaultAlign.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  260. if(!m){
  261. throw 'AnchorTip.defaultAlign is invalid';
  262. }
  263. this.tipAnchor = m[1].charAt(0);
  264. }
  265. switch(this.tipAnchor){
  266. case 't': return 'top';
  267. case 'b': return 'bottom';
  268. case 'r': return 'right';
  269. }
  270. return 'left';
  271. },
  272. // private
  273. getAnchorAlign : function(){
  274. switch(this.anchor){
  275. case 'top' : return 'tl-bl';
  276. case 'left' : return 'tl-tr';
  277. case 'right': return 'tr-tl';
  278. default : return 'bl-tl';
  279. }
  280. },
  281. // private
  282. getOffsets : function(){
  283. var offsets,
  284. ap = this.getAnchorPosition().charAt(0);
  285. if(this.anchorToTarget && !this.trackMouse){
  286. switch(ap){
  287. case 't':
  288. offsets = [0, 9];
  289. break;
  290. case 'b':
  291. offsets = [0, -13];
  292. break;
  293. case 'r':
  294. offsets = [-13, 0];
  295. break;
  296. default:
  297. offsets = [9, 0];
  298. break;
  299. }
  300. }else{
  301. switch(ap){
  302. case 't':
  303. offsets = [-15-this.anchorOffset, 30];
  304. break;
  305. case 'b':
  306. offsets = [-19-this.anchorOffset, -13-this.el.dom.offsetHeight];
  307. break;
  308. case 'r':
  309. offsets = [-15-this.el.dom.offsetWidth, -13-this.anchorOffset];
  310. break;
  311. default:
  312. offsets = [25, -13-this.anchorOffset];
  313. break;
  314. }
  315. }
  316. var mouseOffset = this.getMouseOffset();
  317. offsets[0] += mouseOffset[0];
  318. offsets[1] += mouseOffset[1];
  319. return offsets;
  320. },
  321. // private
  322. onTargetOver : function(e){
  323. if(this.disabled || e.within(this.target.dom, true)){
  324. return;
  325. }
  326. var t = e.getTarget(this.delegate);
  327. if (t) {
  328. this.triggerElement = t;
  329. this.clearTimer('hide');
  330. this.targetXY = e.getXY();
  331. this.delayShow();
  332. }
  333. },
  334. // private
  335. delayShow : function(){
  336. if(this.hidden && !this.showTimer){
  337. if(this.lastActive.getElapsed() < this.quickShowInterval){
  338. this.show();
  339. }else{
  340. this.showTimer = this.show.defer(this.showDelay, this);
  341. }
  342. }else if(!this.hidden && this.autoHide !== false){
  343. this.show();
  344. }
  345. },
  346. // private
  347. onTargetOut : function(e){
  348. if(this.disabled || e.within(this.target.dom, true)){
  349. return;
  350. }
  351. this.clearTimer('show');
  352. if(this.autoHide !== false){
  353. this.delayHide();
  354. }
  355. },
  356. // private
  357. delayHide : function(){
  358. if(!this.hidden && !this.hideTimer){
  359. this.hideTimer = this.hide.defer(this.hideDelay, this);
  360. }
  361. },
  362. <div id="method-Ext.ToolTip-hide"></div>/**
  363. * Hides this tooltip if visible.
  364. */
  365. hide: function(){
  366. this.clearTimer('dismiss');
  367. this.lastActive = new Date();
  368. if(this.anchorEl){
  369. this.anchorEl.hide();
  370. }
  371. Ext.ToolTip.superclass.hide.call(this);
  372. delete this.triggerElement;
  373. },
  374. <div id="method-Ext.ToolTip-show"></div>/**
  375. * Shows this tooltip at the current event target XY position.
  376. */
  377. show : function(){
  378. if(this.anchor){
  379. // pre-show it off screen so that the el will have dimensions
  380. // for positioning calcs when getting xy next
  381. this.showAt([-1000,-1000]);
  382. this.origConstrainPosition = this.constrainPosition;
  383. this.constrainPosition = false;
  384. this.anchor = this.origAnchor;
  385. }
  386. this.showAt(this.getTargetXY());
  387. if(this.anchor){
  388. this.anchorEl.show();
  389. this.syncAnchor();
  390. this.constrainPosition = this.origConstrainPosition;
  391. }else{
  392. this.anchorEl.hide();
  393. }
  394. },
  395. // inherit docs
  396. showAt : function(xy){
  397. this.lastActive = new Date();
  398. this.clearTimers();
  399. Ext.ToolTip.superclass.showAt.call(this, xy);
  400. if(this.dismissDelay && this.autoHide !== false){
  401. this.dismissTimer = this.hide.defer(this.dismissDelay, this);
  402. }
  403. if(this.anchor && !this.anchorEl.isVisible()){
  404. this.syncAnchor();
  405. this.anchorEl.show();
  406. }else{
  407. this.anchorEl.hide();
  408. }
  409. },
  410. // private
  411. syncAnchor : function(){
  412. var anchorPos, targetPos, offset;
  413. switch(this.tipAnchor.charAt(0)){
  414. case 't':
  415. anchorPos = 'b';
  416. targetPos = 'tl';
  417. offset = [20+this.anchorOffset, 2];
  418. break;
  419. case 'r':
  420. anchorPos = 'l';
  421. targetPos = 'tr';
  422. offset = [-2, 11+this.anchorOffset];
  423. break;
  424. case 'b':
  425. anchorPos = 't';
  426. targetPos = 'bl';
  427. offset = [20+this.anchorOffset, -2];
  428. break;
  429. default:
  430. anchorPos = 'r';
  431. targetPos = 'tl';
  432. offset = [2, 11+this.anchorOffset];
  433. break;
  434. }
  435. this.anchorEl.alignTo(this.el, anchorPos+'-'+targetPos, offset);
  436. },
  437. // private
  438. setPagePosition : function(x, y){
  439. Ext.ToolTip.superclass.setPagePosition.call(this, x, y);
  440. if(this.anchor){
  441. this.syncAnchor();
  442. }
  443. },
  444. // private
  445. clearTimer : function(name){
  446. name = name + 'Timer';
  447. clearTimeout(this[name]);
  448. delete this[name];
  449. },
  450. // private
  451. clearTimers : function(){
  452. this.clearTimer('show');
  453. this.clearTimer('dismiss');
  454. this.clearTimer('hide');
  455. },
  456. // private
  457. onShow : function(){
  458. Ext.ToolTip.superclass.onShow.call(this);
  459. Ext.getDoc().on('mousedown', this.onDocMouseDown, this);
  460. },
  461. // private
  462. onHide : function(){
  463. Ext.ToolTip.superclass.onHide.call(this);
  464. Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
  465. },
  466. // private
  467. onDocMouseDown : function(e){
  468. if(this.autoHide !== true && !this.closable && !e.within(this.el.dom)){
  469. this.disable();
  470. this.doEnable.defer(100, this);
  471. }
  472. },
  473. // private
  474. doEnable : function(){
  475. if(!this.isDestroyed){
  476. this.enable();
  477. }
  478. },
  479. // private
  480. onDisable : function(){
  481. this.clearTimers();
  482. this.hide();
  483. },
  484. // private
  485. adjustPosition : function(x, y){
  486. if(this.contstrainPosition){
  487. var ay = this.targetXY[1], h = this.getSize().height;
  488. if(y <= ay && (y+h) >= ay){
  489. y = ay-h-5;
  490. }
  491. }
  492. return {x : x, y: y};
  493. },
  494. beforeDestroy : function(){
  495. this.clearTimers();
  496. Ext.destroy(this.anchorEl);
  497. delete this.anchorEl;
  498. delete this.target;
  499. delete this.anchorTarget;
  500. delete this.triggerElement;
  501. Ext.ToolTip.superclass.beforeDestroy.call(this);
  502. },
  503. // private
  504. onDestroy : function(){
  505. Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
  506. Ext.ToolTip.superclass.onDestroy.call(this);
  507. }
  508. });
  509. Ext.reg('tooltip', Ext.ToolTip);</pre>
  510. </body>
  511. </html>