[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/dd-ddm-base/ -> dd-ddm-base-debug.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('dd-ddm-base', function (Y, NAME) {
   9  
  10  
  11      /**
  12       * Provides the base Drag Drop Manager required for making a Node draggable.
  13       * @module dd
  14       * @submodule dd-ddm-base
  15       */
  16       /**
  17       * Provides the base Drag Drop Manager required for making a Node draggable.
  18       * @class DDM
  19       * @extends Base
  20       * @constructor
  21       * @namespace DD
  22       */
  23  
  24      var DDMBase = function() {
  25          DDMBase.superclass.constructor.apply(this, arguments);
  26      };
  27  
  28      DDMBase.NAME = 'ddm';
  29  
  30      DDMBase.ATTRS = {
  31          /**
  32          * The cursor to apply when dragging, if shimmed the shim will get the cursor.
  33          * @attribute dragCursor
  34          * @type String
  35          */
  36          dragCursor: {
  37              value: 'move'
  38          },
  39          /**
  40          * The number of pixels to move to start a drag operation, default is 3.
  41          * @attribute clickPixelThresh
  42          * @type Number
  43          */
  44          clickPixelThresh: {
  45              value: 3
  46          },
  47          /**
  48          * The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
  49          * @attribute clickTimeThresh
  50          * @type Number
  51          */
  52          clickTimeThresh: {
  53              value: 1000
  54          },
  55          /**
  56          * The number of milliseconds to throttle the mousemove event. Default: 150
  57          * @attribute throttleTime
  58          * @type Number
  59          */
  60          throttleTime: {
  61              //value: 150
  62              value: -1
  63          },
  64          /**
  65          * This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of all future Drag instances.
  66          * @attribute dragMode
  67          * @type String
  68          */
  69          dragMode: {
  70              value: 'point',
  71              setter: function(mode) {
  72                  this._setDragMode(mode);
  73                  return mode;
  74              }
  75          }
  76  
  77      };
  78  
  79      Y.extend(DDMBase, Y.Base, {
  80          _createPG: function() {},
  81          /**
  82          * flag set when we activate our first drag, so DDM can start listening for events.
  83          * @property _active
  84          * @type {Boolean}
  85          */
  86          _active: null,
  87          /**
  88          * Handler for dragMode attribute setter.
  89          * @private
  90          * @method _setDragMode
  91          * @param {String|Number} mode The Number value or the String for the DragMode to default all future drag instances to.
  92          * @return Number The Mode to be set
  93          */
  94          _setDragMode: function(mode) {
  95              if (mode === null) {
  96                  mode = Y.DD.DDM.get('dragMode');
  97              }
  98              switch (mode) {
  99                  case 1:
 100                  case 'intersect':
 101                      return 1;
 102                  case 2:
 103                  case 'strict':
 104                      return 2;
 105                  case 0:
 106                  case 'point':
 107                      return 0;
 108              }
 109              return 0;
 110          },
 111          /**
 112          * The PREFIX to attach to all DD CSS class names
 113          * @property CSS_PREFIX
 114          * @type {String}
 115          */
 116          CSS_PREFIX: Y.ClassNameManager.getClassName('dd'),
 117          _activateTargets: function() {},
 118          /**
 119          * Holder for all registered drag elements.
 120          * @private
 121          * @property _drags
 122          * @type {Array}
 123          */
 124          _drags: [],
 125          /**
 126          * A reference to the currently active draggable object.
 127          * @property activeDrag
 128          * @type {Drag}
 129          */
 130          activeDrag: false,
 131          /**
 132          * Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
 133          * @private
 134          * @method _regDrag
 135          * @param {Drag} d The Drag object
 136          */
 137          _regDrag: function(d) {
 138              if (this.getDrag(d.get('node'))) {
 139                  return false;
 140              }
 141  
 142              if (!this._active) {
 143                  this._setupListeners();
 144              }
 145              this._drags.push(d);
 146              return true;
 147          },
 148          /**
 149          * Remove this drag object from the DDM._drags array.
 150          * @private
 151          * @method _unregDrag
 152          * @param {Drag} d The drag object.
 153          */
 154          _unregDrag: function(d) {
 155              var tmp = [];
 156              Y.Array.each(this._drags, function(n) {
 157                  if (n !== d) {
 158                      tmp[tmp.length] = n;
 159                  }
 160              });
 161              this._drags = tmp;
 162          },
 163          /**
 164          * Add the document listeners.
 165          * @private
 166          * @method _setupListeners
 167          */
 168          _setupListeners: function() {
 169              this._createPG();
 170              this._active = true;
 171  
 172              var doc = Y.one(Y.config.doc);
 173              doc.on('mousemove', Y.throttle(Y.bind(this._docMove, this), this.get('throttleTime')));
 174              doc.on('mouseup', Y.bind(this._end, this));
 175          },
 176          /**
 177          * Internal method used by Drag to signal the start of a drag operation
 178          * @private
 179          * @method _start
 180          */
 181          _start: function() {
 182              this.fire('ddm:start');
 183              this._startDrag();
 184          },
 185          /**
 186          * Factory method to be overwritten by other DDM's
 187          * @private
 188          * @method _startDrag
 189          * @param {Number} x The x position of the drag element
 190          * @param {Number} y The y position of the drag element
 191          * @param {Number} w The width of the drag element
 192          * @param {Number} h The height of the drag element
 193          */
 194          _startDrag: function() {},
 195          /**
 196          * Factory method to be overwritten by other DDM's
 197          * @private
 198          * @method _endDrag
 199          */
 200          _endDrag: function() {},
 201          _dropMove: function() {},
 202          /**
 203          * Internal method used by Drag to signal the end of a drag operation
 204          * @private
 205          * @method _end
 206          */
 207          _end: function() {
 208              if (this.activeDrag) {
 209                  this._shimming = false;
 210                  this._endDrag();
 211                  this.fire('ddm:end');
 212                  this.activeDrag.end.call(this.activeDrag);
 213                  this.activeDrag = null;
 214              }
 215          },
 216          /**
 217          * Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
 218          * @method stopDrag
 219          * @chainable
 220          */
 221          stopDrag: function() {
 222              if (this.activeDrag) {
 223                  this._end();
 224              }
 225              return this;
 226          },
 227          /**
 228          * Set to true when drag starts and useShim is true. Used in pairing with _docMove
 229          * @private
 230          * @property _shimming
 231          * @see _docMove
 232          * @type {Boolean}
 233          */
 234          _shimming: false,
 235          /**
 236          * Internal listener for the mousemove on Document. Checks if the shim is in place to only call _move once per mouse move
 237          * @private
 238          * @method _docMove
 239          * @param {EventFacade} ev The Dom mousemove Event
 240          */
 241          _docMove: function(ev) {
 242              if (!this._shimming) {
 243                  this._move(ev);
 244              }
 245          },
 246          /**
 247          * Internal listener for the mousemove DOM event to pass to the Drag's move method.
 248          * @private
 249          * @method _move
 250          * @param {EventFacade} ev The Dom mousemove Event
 251          */
 252          _move: function(ev) {
 253              if (this.activeDrag) {
 254                  this.activeDrag._move.call(this.activeDrag, ev);
 255                  this._dropMove();
 256              }
 257          },
 258          /**
 259          * //TODO Private, rename??...
 260          * Helper method to use to set the gutter from the attribute setter.
 261          * CSS style string for gutter: '5 0' (sets top and bottom to 5px, left and right to 0px), '1 2 3 4' (top 1px, right 2px, bottom 3px, left 4px)
 262          * @private
 263          * @method cssSizestoObject
 264          * @param {String} gutter CSS style string for gutter
 265          * @return {Object} The gutter Object Literal.
 266          */
 267          cssSizestoObject: function(gutter) {
 268              var x = gutter.split(' ');
 269  
 270              switch (x.length) {
 271                  case 1: x[1] = x[2] = x[3] = x[0]; break;
 272                  case 2: x[2] = x[0]; x[3] = x[1]; break;
 273                  case 3: x[3] = x[1]; break;
 274              }
 275  
 276              return {
 277                  top   : parseInt(x[0],10),
 278                  right : parseInt(x[1],10),
 279                  bottom: parseInt(x[2],10),
 280                  left  : parseInt(x[3],10)
 281              };
 282          },
 283          /**
 284          * Get a valid Drag instance back from a Node or a selector string, false otherwise
 285          * @method getDrag
 286          * @param {String/Object} node The Node instance or Selector string to check for a valid Drag Object
 287          * @return {Object}
 288          */
 289          getDrag: function(node) {
 290              var drag = false,
 291                  n = Y.one(node);
 292              if (n instanceof Y.Node) {
 293                  Y.Array.each(this._drags, function(v) {
 294                      if (n.compareTo(v.get('node'))) {
 295                          drag = v;
 296                      }
 297                  });
 298              }
 299              return drag;
 300          },
 301          /**
 302          * Swap the position of 2 nodes based on their CSS positioning.
 303          * @method swapPosition
 304          * @param {Node} n1 The first node to swap
 305          * @param {Node} n2 The first node to swap
 306          * @return {Node}
 307          */
 308          swapPosition: function(n1, n2) {
 309              n1 = Y.DD.DDM.getNode(n1);
 310              n2 = Y.DD.DDM.getNode(n2);
 311              var xy1 = n1.getXY(),
 312                  xy2 = n2.getXY();
 313  
 314              n1.setXY(xy2);
 315              n2.setXY(xy1);
 316              return n1;
 317          },
 318          /**
 319          * Return a node instance from the given node, selector string or Y.Base extended object.
 320          * @method getNode
 321          * @param {Node/Object/String} n The node to resolve.
 322          * @return {Node}
 323          */
 324          getNode: function(n) {
 325              if (n instanceof Y.Node) {
 326                  return n;
 327              }
 328              if (n && n.get) {
 329                  if (Y.Widget && (n instanceof Y.Widget)) {
 330                      n = n.get('boundingBox');
 331                  } else {
 332                      n = n.get('node');
 333                  }
 334              } else {
 335                  n = Y.one(n);
 336              }
 337              return n;
 338          },
 339          /**
 340          * Swap the position of 2 nodes based on their DOM location.
 341          * @method swapNode
 342          * @param {Node} n1 The first node to swap
 343          * @param {Node} n2 The first node to swap
 344          * @return {Node}
 345          */
 346          swapNode: function(n1, n2) {
 347              n1 = Y.DD.DDM.getNode(n1);
 348              n2 = Y.DD.DDM.getNode(n2);
 349              var p = n2.get('parentNode'),
 350                  s = n2.get('nextSibling');
 351  
 352              if (s === n1) {
 353                  p.insertBefore(n1, n2);
 354              } else if (n2 === n1.get('nextSibling')) {
 355                  p.insertBefore(n2, n1);
 356              } else {
 357                  n1.get('parentNode').replaceChild(n2, n1);
 358                  p.insertBefore(n1, s);
 359              }
 360              return n1;
 361          }
 362      });
 363  
 364      Y.namespace('DD');
 365      Y.DD.DDM = new DDMBase();
 366  
 367      /**
 368      * Fires from the DDM before all drag events fire.
 369      * @event ddm:start
 370      * @type {CustomEvent}
 371      */
 372      /**
 373      * Fires from the DDM after the DDM finishes, before the drag end events.
 374      * @event ddm:end
 375      * @type {CustomEvent}
 376      */
 377  
 378  
 379  
 380  
 381  }, '3.17.2', {"requires": ["node", "base", "yui-throttle", "classnamemanager"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1