X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/docs/source/DragTracker.html diff --git a/docs/source/DragTracker.html b/docs/source/DragTracker.html index 2e834a26..5097e8bf 100644 --- a/docs/source/DragTracker.html +++ b/docs/source/DragTracker.html @@ -1,4 +1,21 @@ -Sencha Documentation Project
/**
+
+
+
+  
+  The source code
+  
+  
+  
+  
+
+
+  
/**
  * @class Ext.dd.DragTracker
  * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
  * as well as during the drag. This is useful for components such as {@link Ext.slider.Multi}, where there is
@@ -15,7 +32,7 @@ Ext.define('Ext.dd.DragTracker', {
         observable: 'Ext.util.Observable'
     },
 
-    /**
+    /**
      * @property active
      * @type Boolean
      * Read-only property indicated whether the user is currently dragging this
@@ -23,7 +40,7 @@ Ext.define('Ext.dd.DragTracker', {
      */
     active: false,
 
-    /**
+    /**
      * @property dragTarget
      * @type HtmlElement
      * <p><b>Only valid during drag operations. Read-only.</b></p>
@@ -31,7 +48,7 @@ Ext.define('Ext.dd.DragTracker', {
      * <p>If the {@link #delegate} option is used, this will be the delegate element which was mousedowned.</p>
      */
 
-    /**
+    /**
      * @cfg {Boolean} trackOver
      * <p>Defaults to <code>false</code>. Set to true to fire mouseover and mouseout events when the mouse enters or leaves the target element.</p>
      * <p>This is implicitly set when an {@link #overCls} is specified.</p>
@@ -39,47 +56,47 @@ Ext.define('Ext.dd.DragTracker', {
      */
     trackOver: false,
 
-    /**
+    /**
      * @cfg {String} overCls
      * <p>A CSS class to add to the DragTracker's target element when the element (or, if the {@link #delegate} option is used,
      * when a delegate element) is mouseovered.</p>
      * <b>If the {@link #delegate} option is used, these events fire only when a delegate element is entered of left.</b>.
      */
 
-    /**
+    /**
      * @cfg {Ext.util.Region/Element} constrainTo
      * <p>A {@link Ext.util.Region Region} (Or an element from which a Region measurement will be read) which is used to constrain
      * the result of the {@link #getOffset} call.</p>
      * <p>This may be set any time during the DragTracker's lifecycle to set a dynamic constraining region.</p>
      */
 
-    /**
+    /**
      * @cfg {Number} tolerance
      * Number of pixels the drag target must be moved before dragging is
      * considered to have started. Defaults to <code>5</code>.
      */
     tolerance: 5,
 
-    /**
+    /**
      * @cfg {Boolean/Number} autoStart
      * Defaults to <code>false</code>. Specify <code>true</code> to defer trigger start by 1000 ms.
      * Specify a Number for the number of milliseconds to defer trigger start.
      */
     autoStart: false,
 
-    /**
+    /**
      * @cfg {String} delegate
      * Optional. <p>A {@link Ext.DomQuery DomQuery} selector which identifies child elements within the DragTracker's encapsulating
      * Element which are the tracked elements. This limits tracking to only begin when the matching elements are mousedowned.</p>
      * <p>This may also be a specific child element within the DragTracker's encapsulating element to use as the tracked element.</p>
      */
 
-    /**
+    /**
      * @cfg {Boolean} preventDefault
      * Specify <code>false</code> to enable default actions on onMouseDown events. Defaults to <code>true</code>.
      */
 
-    /**
+    /**
      * @cfg {Boolean} stopEvent
      * Specify <code>true</code> to stop the <code>mousedown</code> event from bubbling to outer listeners from the target element (or its delegates). Defaults to <code>false</code>.
      */
@@ -87,7 +104,7 @@ Ext.define('Ext.dd.DragTracker', {
     constructor : function(config){
         Ext.apply(this, config);
         this.addEvents(
-            /**
+            /**
              * @event mouseover <p><b>Only available when {@link #trackOver} is <code>true</code></b></p>
              * <p>Fires when the mouse enters the DragTracker's target element (or if {@link #delegate} is
              * used, when the mouse enters a delegate element).</p>
@@ -97,7 +114,7 @@ Ext.define('Ext.dd.DragTracker', {
              */
             'mouseover',
 
-            /**
+            /**
              * @event mouseout <p><b>Only available when {@link #trackOver} is <code>true</code></b></p>
              * <p>Fires when the mouse exits the DragTracker's target element (or if {@link #delegate} is
              * used, when the mouse exits a delegate element).</p>
@@ -106,7 +123,7 @@ Ext.define('Ext.dd.DragTracker', {
              */
             'mouseout',
 
-            /**
+            /**
              * @event mousedown <p>Fires when the mouse button is pressed down, but before a drag operation begins. The
              * drag operation begins after either the mouse has been moved by {@link #tolerance} pixels, or after
              * the {@link #autoStart} timer fires.</p>
@@ -116,35 +133,42 @@ Ext.define('Ext.dd.DragTracker', {
              */
             'mousedown',
 
-            /**
+            /**
              * @event mouseup
              * @param {Object} this
              * @param {Object} e event object
              */
             'mouseup',
 
-            /**
+            /**
              * @event mousemove Fired when the mouse is moved. Returning false cancels the drag operation.
              * @param {Object} this
              * @param {Object} e event object
              */
             'mousemove',
 
-            /**
+            /**
+             * @event beforestart
+             * @param {Object} this
+             * @param {Object} e event object
+             */
+            'beforedragstart',
+
+            /**
              * @event dragstart
              * @param {Object} this
              * @param {Object} e event object
              */
             'dragstart',
 
-            /**
+            /**
              * @event dragend
              * @param {Object} this
              * @param {Object} e event object
              */
             'dragend',
 
-            /**
+            /**
              * @event drag
              * @param {Object} this
              * @param {Object} e event object
@@ -166,7 +190,7 @@ Ext.define('Ext.dd.DragTracker', {
 
     },
 
-    /**
+    /**
      * Initializes the DragTracker on a given element.
      * @param {Ext.core.Element/HTMLElement} el The element
      */
@@ -256,27 +280,30 @@ Ext.define('Ext.dd.DragTracker', {
         this.startXY = this.lastXY = e.getXY();
         this.startRegion = Ext.fly(this.dragTarget).getRegion();
 
-        if (this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false) {
+        if (this.fireEvent('mousedown', this, e) === false ||
+            this.fireEvent('beforedragstart', this, e) === false ||
+            this.onBeforeStart(e) === false) {
+            return;
+        }
 
-            // Track when the mouse is down so that mouseouts while the mouse is down are not processed.
-            // The onMouseOut method will only ever be called after mouseup.
-            this.mouseIsDown = true;
+        // Track when the mouse is down so that mouseouts while the mouse is down are not processed.
+        // The onMouseOut method will only ever be called after mouseup.
+        this.mouseIsDown = true;
 
-            // Flag for downstream DragTracker instances that the mouse is being tracked.
-            e.dragTracked = true;
+        // Flag for downstream DragTracker instances that the mouse is being tracked.
+        e.dragTracked = true;
 
-            if (this.preventDefault !== false) {
-                e.preventDefault();
-            }
-            Ext.getDoc().on({
-                scope: this,
-                mouseup: this.onMouseUp,
-                mousemove: this.onMouseMove,
-                selectstart: this.stopSelect
-            });
-            if (this.autoStart) {
-                this.timer =  Ext.defer(this.triggerStart, this.autoStart === true ? 1000 : this.autoStart, this, [e]);
-            }
+        if (this.preventDefault !== false) {
+            e.preventDefault();
+        }
+        Ext.getDoc().on({
+            scope: this,
+            mouseup: this.onMouseUp,
+            mousemove: this.onMouseMove,
+            selectstart: this.stopSelect
+        });
+        if (this.autoStart) {
+            this.timer =  Ext.defer(this.triggerStart, this.autoStart === true ? 1000 : this.autoStart, this, [e]);
         }
     },
 
@@ -329,7 +356,7 @@ Ext.define('Ext.dd.DragTracker', {
         this.endDrag(e);
     },
 
-    /**
+    /**
      * @private
      * Stop the drag operation, and remove active mouse listeners.
      */
@@ -369,7 +396,7 @@ Ext.define('Ext.dd.DragTracker', {
         return false;
     },
 
-    /**
+    /**
      * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
      * holds the mouse button down. Return false to disallow the drag
      * @param {Ext.EventObject} e The event object
@@ -378,7 +405,7 @@ Ext.define('Ext.dd.DragTracker', {
 
     },
 
-    /**
+    /**
      * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
      * (e.g. the user has moved the tracked element beyond the specified tolerance)
      * @param {Ext.EventObject} e The event object
@@ -387,7 +414,7 @@ Ext.define('Ext.dd.DragTracker', {
 
     },
 
-    /**
+    /**
      * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
      * @param {Ext.EventObject} e The event object
      */
@@ -395,7 +422,7 @@ Ext.define('Ext.dd.DragTracker', {
 
     },
 
-    /**
+    /**
      * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
      * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
      * @param {Ext.EventObject} e The event object
@@ -404,7 +431,7 @@ Ext.define('Ext.dd.DragTracker', {
 
     },
 
-    /**
+    /**
      * </p>Returns the drag target. This is usually the DragTracker's encapsulating element.</p>
      * <p>If the {@link #delegate} option is being used, this may be a child element which matches the
      * {@link #delegate} selector.</p>
@@ -414,7 +441,7 @@ Ext.define('Ext.dd.DragTracker', {
         return this.dragTarget;
     },
 
-    /**
+    /**
      * @private
      * @returns {Element} The DragTracker's encapsulating element.
      */
@@ -422,7 +449,7 @@ Ext.define('Ext.dd.DragTracker', {
         return this.el;
     },
 
-    /**
+    /**
      * @private
      * Return the Region into which the drag operation is constrained.
      * Either the XY pointer itself can be constrained, or the dragTarget element
@@ -445,10 +472,10 @@ Ext.define('Ext.dd.DragTracker', {
     },
 
     getXY : function(constrain){
-        return constrain ? this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
+        return constrain ? this.constrainModes[constrain](this, this.lastXY) : this.lastXY;
     },
 
-    /**
+    /**
      * <p>Returns the X, Y offset of the current mouse position from the mousedown point.</p>
      * <p>This method may optionally constrain the real offset values, and returns a point coerced in one
      * of two modes:</p><ul>
@@ -472,9 +499,9 @@ Ext.define('Ext.dd.DragTracker', {
 
     constrainModes: {
         // Constrain the passed point to within the constrain region
-        point: function(xy) {
-            var dr = this.dragRegion,
-                constrainTo = this.getConstrainRegion();
+        point: function(me, xy) {
+            var dr = me.dragRegion,
+                constrainTo = me.getConstrainRegion();
 
             // No constraint
             if (!constrainTo) {
@@ -489,10 +516,10 @@ Ext.define('Ext.dd.DragTracker', {
         },
 
         // Constrain the dragTarget to within the constrain region. Return the passed xy adjusted by the same delta.
-        dragTarget: function(xy) {
-            var s = this.startXY,
-                dr = this.startRegion.copy(),
-                constrainTo = this.getConstrainRegion(),
+        dragTarget: function(me, xy) {
+            var s = me.startXY,
+                dr = me.startRegion.copy(),
+                constrainTo = me.getConstrainRegion(),
                 adjust;
 
             // No constraint
@@ -503,7 +530,7 @@ Ext.define('Ext.dd.DragTracker', {
             // See where the passed XY would put the dragTarget if translated by the unconstrained offset.
             // If it overflows, we constrain the passed XY to bring the potential
             // region back within the boundary.
-            dr.translateBy.apply(dr, [xy[0]-s[0], xy[1]-s[1]]);
+            dr.translateBy(xy[0]-s[0], xy[1]-s[1]);
 
             // Constrain the X coordinate by however much the dragTarget overflows
             if (dr.right > constrainTo.right) {
@@ -514,7 +541,7 @@ Ext.define('Ext.dd.DragTracker', {
                 xy[0] += (constrainTo.left - dr.left);      // overflowed the left
             }
 
-            // Constrain the X coordinate by however much the dragTarget overflows
+            // Constrain the Y coordinate by however much the dragTarget overflows
             if (dr.bottom > constrainTo.bottom) {
                 xy[1] += adjust = (constrainTo.bottom - dr.bottom);  // overflowed the bottom
                 dr.top += adjust;
@@ -525,4 +552,6 @@ Ext.define('Ext.dd.DragTracker', {
             return xy;
         }
     }
-});
\ No newline at end of file +});
+ +