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.

260 lines
8.3 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.dd.DragTracker"></div>/**
  16. * @class Ext.dd.DragTracker
  17. * @extends Ext.util.Observable
  18. * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
  19. * as well as during the drag. This is useful for components such as {@link Ext.slider.MultiSlider}, where there is
  20. * an element that can be dragged around to change the Slider's value.
  21. * DragTracker provides a series of template methods that should be overridden to provide functionality
  22. * in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd.
  23. * See {@link Ext.slider.MultiSlider}'s initEvents function for an example implementation.
  24. */
  25. Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
  26. <div id="cfg-Ext.dd.DragTracker-active"></div>/**
  27. * @cfg {Boolean} active
  28. * Defaults to <tt>false</tt>.
  29. */
  30. active: false,
  31. <div id="cfg-Ext.dd.DragTracker-tolerance"></div>/**
  32. * @cfg {Number} tolerance
  33. * Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>.
  34. */
  35. tolerance: 5,
  36. <div id="cfg-Ext.dd.DragTracker-autoStart"></div>/**
  37. * @cfg {Boolean/Number} autoStart
  38. * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
  39. * Specify a Number for the number of milliseconds to defer trigger start.
  40. */
  41. autoStart: false,
  42. constructor : function(config){
  43. Ext.apply(this, config);
  44. this.addEvents(
  45. <div id="event-Ext.dd.DragTracker-mousedown"></div>/**
  46. * @event mousedown
  47. * @param {Object} this
  48. * @param {Object} e event object
  49. */
  50. 'mousedown',
  51. <div id="event-Ext.dd.DragTracker-mouseup"></div>/**
  52. * @event mouseup
  53. * @param {Object} this
  54. * @param {Object} e event object
  55. */
  56. 'mouseup',
  57. <div id="event-Ext.dd.DragTracker-mousemove"></div>/**
  58. * @event mousemove
  59. * @param {Object} this
  60. * @param {Object} e event object
  61. */
  62. 'mousemove',
  63. <div id="event-Ext.dd.DragTracker-dragstart"></div>/**
  64. * @event dragstart
  65. * @param {Object} this
  66. * @param {Object} e event object
  67. */
  68. 'dragstart',
  69. <div id="event-Ext.dd.DragTracker-dragend"></div>/**
  70. * @event dragend
  71. * @param {Object} this
  72. * @param {Object} e event object
  73. */
  74. 'dragend',
  75. <div id="event-Ext.dd.DragTracker-drag"></div>/**
  76. * @event drag
  77. * @param {Object} this
  78. * @param {Object} e event object
  79. */
  80. 'drag'
  81. );
  82. this.dragRegion = new Ext.lib.Region(0,0,0,0);
  83. if(this.el){
  84. this.initEl(this.el);
  85. }
  86. Ext.dd.DragTracker.superclass.constructor.call(this, config);
  87. },
  88. initEl: function(el){
  89. this.el = Ext.get(el);
  90. el.on('mousedown', this.onMouseDown, this,
  91. this.delegate ? {delegate: this.delegate} : undefined);
  92. },
  93. destroy : function(){
  94. this.el.un('mousedown', this.onMouseDown, this);
  95. delete this.el;
  96. },
  97. onMouseDown: function(e, target){
  98. if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
  99. this.startXY = this.lastXY = e.getXY();
  100. this.dragTarget = this.delegate ? target : this.el.dom;
  101. if(this.preventDefault !== false){
  102. e.preventDefault();
  103. }
  104. Ext.getDoc().on({
  105. scope: this,
  106. mouseup: this.onMouseUp,
  107. mousemove: this.onMouseMove,
  108. selectstart: this.stopSelect
  109. });
  110. if(this.autoStart){
  111. this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this, [e]);
  112. }
  113. }
  114. },
  115. onMouseMove: function(e, target){
  116. // HACK: IE hack to see if button was released outside of window. */
  117. if(this.active && Ext.isIE && !e.browserEvent.button){
  118. e.preventDefault();
  119. this.onMouseUp(e);
  120. return;
  121. }
  122. e.preventDefault();
  123. var xy = e.getXY(), s = this.startXY;
  124. this.lastXY = xy;
  125. if(!this.active){
  126. if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
  127. this.triggerStart(e);
  128. }else{
  129. return;
  130. }
  131. }
  132. this.fireEvent('mousemove', this, e);
  133. this.onDrag(e);
  134. this.fireEvent('drag', this, e);
  135. },
  136. onMouseUp: function(e) {
  137. var doc = Ext.getDoc(),
  138. wasActive = this.active;
  139. doc.un('mousemove', this.onMouseMove, this);
  140. doc.un('mouseup', this.onMouseUp, this);
  141. doc.un('selectstart', this.stopSelect, this);
  142. e.preventDefault();
  143. this.clearStart();
  144. this.active = false;
  145. delete this.elRegion;
  146. this.fireEvent('mouseup', this, e);
  147. if(wasActive){
  148. this.onEnd(e);
  149. this.fireEvent('dragend', this, e);
  150. }
  151. },
  152. triggerStart: function(e) {
  153. this.clearStart();
  154. this.active = true;
  155. this.onStart(e);
  156. this.fireEvent('dragstart', this, e);
  157. },
  158. clearStart : function() {
  159. if(this.timer){
  160. clearTimeout(this.timer);
  161. delete this.timer;
  162. }
  163. },
  164. stopSelect : function(e) {
  165. e.stopEvent();
  166. return false;
  167. },
  168. <div id="method-Ext.dd.DragTracker-onBeforeStart"></div>/**
  169. * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
  170. * holds the mouse button down. Return false to disallow the drag
  171. * @param {Ext.EventObject} e The event object
  172. */
  173. onBeforeStart : function(e) {
  174. },
  175. <div id="method-Ext.dd.DragTracker-onStart"></div>/**
  176. * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
  177. * (e.g. the user has moved the tracked element beyond the specified tolerance)
  178. * @param {Ext.EventObject} e The event object
  179. */
  180. onStart : function(xy) {
  181. },
  182. <div id="method-Ext.dd.DragTracker-onDrag"></div>/**
  183. * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
  184. * @param {Ext.EventObject} e The event object
  185. */
  186. onDrag : function(e) {
  187. },
  188. <div id="method-Ext.dd.DragTracker-onEnd"></div>/**
  189. * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
  190. * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
  191. * @param {Ext.EventObject} e The event object
  192. */
  193. onEnd : function(e) {
  194. },
  195. <div id="method-Ext.dd.DragTracker-getDragTarget"></div>/**
  196. * Returns the drag target
  197. * @return {Ext.Element} The element currently being tracked
  198. */
  199. getDragTarget : function(){
  200. return this.dragTarget;
  201. },
  202. getDragCt : function(){
  203. return this.el;
  204. },
  205. getXY : function(constrain){
  206. return constrain ?
  207. this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
  208. },
  209. getOffset : function(constrain){
  210. var xy = this.getXY(constrain),
  211. s = this.startXY;
  212. return [s[0]-xy[0], s[1]-xy[1]];
  213. },
  214. constrainModes: {
  215. 'point' : function(xy){
  216. if(!this.elRegion){
  217. this.elRegion = this.getDragCt().getRegion();
  218. }
  219. var dr = this.dragRegion;
  220. dr.left = xy[0];
  221. dr.top = xy[1];
  222. dr.right = xy[0];
  223. dr.bottom = xy[1];
  224. dr.constrainTo(this.elRegion);
  225. return [dr.left, dr.top];
  226. }
  227. }
  228. });</pre>
  229. </body>
  230. </html>