PageRenderTime 30ms CodeModel.GetById 20ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 0ms

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