/ext-4.1.0_b3/src/draw/SpriteDD.js

https://bitbucket.org/srogerf/javascript · JavaScript · 87 lines · 59 code · 13 blank · 15 comment · 1 complexity · de4754ade4da29097a1f55605990249e MD5 · raw file

  1. /**
  2. * DD implementation for Panels.
  3. * @private
  4. */
  5. Ext.define('Ext.draw.SpriteDD', {
  6. extend: 'Ext.dd.DragSource',
  7. constructor : function(sprite, cfg){
  8. var me = this,
  9. el = sprite.el;
  10. me.sprite = sprite;
  11. me.el = el;
  12. me.dragData = {el: el, sprite: sprite};
  13. me.callParent([el, cfg]);
  14. me.sprite.setStyle('cursor', 'move');
  15. },
  16. showFrame: Ext.emptyFn,
  17. createFrame : Ext.emptyFn,
  18. getDragEl : function(e){
  19. return this.el;
  20. },
  21. getRegion: function() {
  22. var me = this,
  23. el = me.el,
  24. pos, x1, x2, y1, y2, t, r, b, l, bbox, sprite;
  25. sprite = me.sprite;
  26. bbox = sprite.getBBox();
  27. try {
  28. pos = Ext.Element.getXY(el);
  29. } catch (e) { }
  30. if (!pos) {
  31. return null;
  32. }
  33. x1 = pos[0];
  34. x2 = x1 + bbox.width;
  35. y1 = pos[1];
  36. y2 = y1 + bbox.height;
  37. return new Ext.util.Region(y1, x2, y2, x1);
  38. },
  39. /*
  40. TODO(nico): Cumulative translations in VML are handled
  41. differently than in SVG. While in SVG we specify the translation
  42. relative to the original x, y position attributes, in VML the translation
  43. is a delta between the last position of the object (modified by the last
  44. translation) and the new one.
  45. In VML the translation alters the position
  46. of the object, we should change that or alter the SVG impl.
  47. */
  48. startDrag: function(x, y) {
  49. var me = this,
  50. attr = me.sprite.attr;
  51. me.prev = me.sprite.surface.transformToViewBox(x, y);
  52. },
  53. onDrag: function(e) {
  54. var xy = e.getXY(),
  55. me = this,
  56. sprite = me.sprite,
  57. attr = sprite.attr, dx, dy;
  58. xy = me.sprite.surface.transformToViewBox(xy[0], xy[1]);
  59. dx = xy[0] - me.prev[0];
  60. dy = xy[1] - me.prev[1];
  61. sprite.setAttributes({
  62. translate: {
  63. x: attr.translation.x + dx,
  64. y: attr.translation.y + dy
  65. }
  66. }, true);
  67. me.prev = xy;
  68. },
  69. setDragElPos: function () {
  70. // Disable automatic DOM move in DD that spoils layout of VML engine.
  71. return false;
  72. }
  73. });