~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/editor/draw2d/dragdrop.js

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This notice must be untouched at all times.
 
2
 
 
3
Open-jACOB Draw2D
 
4
The latest version is available at
 
5
http://www.openjacob.org
 
6
 
 
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
 
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
 
9
 
 
10
LICENSE: LGPL
 
11
 
 
12
This library is free software; you can redistribute it and/or
 
13
modify it under the terms of the GNU Lesser General Public
 
14
License (LGPL) as published by the Free Software Foundation; either
 
15
version 2.1 of the License, or (at your option) any later version.
 
16
 
 
17
This library is distributed in the hope that it will be useful,
 
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
Lesser General Public License for more details.
 
21
 
 
22
You should have received a copy of the GNU Lesser General Public
 
23
License along with this library; if not, write to the Free Software
 
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
 
25
or see http://www.gnu.org/copyleft/lesser.html
 
26
*/
 
27
 
 
28
draw2d.Drag=function()
 
29
{
 
30
}
 
31
 
 
32
/**
 
33
 * The item currently being dragged.
 
34
 * @scope private
 
35
 */
 
36
draw2d.Drag.current /*: Draggable */ = null;
 
37
draw2d.Drag.currentTarget /*:DropTarget */=null;
 
38
 
 
39
/**
 
40
 * Indicates whether or not an item is being dragged.
 
41
 * @scope private
 
42
 */
 
43
draw2d.Drag.dragging /*: boolean */ = false;
 
44
 
 
45
/**
 
46
 * Returns true if an item is being dragged.
 
47
 * @scope public
 
48
 * @return True if an item is being dragged, false if not.
 
49
 * @type boolean
 
50
 */
 
51
draw2d.Drag.isDragging = function () /*: boolean */ 
 
52
{
 
53
    return this.dragging;
 
54
}
 
55
 
 
56
/**
 
57
 * Sets the item being dragged.
 
58
 * @scope protected
 
59
 * @param {Draggable} oDraggable The draggable item.
 
60
 * @type void
 
61
 */
 
62
draw2d.Drag.setCurrent = function (oDraggable /*: Draggable */) 
 
63
{
 
64
    this.current = oDraggable;
 
65
    this.dragging = true;
 
66
}
 
67
 
 
68
/**
 
69
 * Returns the currently dragged item.
 
70
 * @scope public
 
71
 * @return The currently dragged item.
 
72
 * @type Draggable
 
73
 */
 
74
draw2d.Drag.getCurrent = function () /*: Draggable */ 
 
75
{
 
76
    return this.current;
 
77
}
 
78
 
 
79
/**
 
80
 * Clears the currently dragged item from memory and sets the dragging
 
81
 * flag to false.
 
82
 * @scope protected
 
83
 * @type void
 
84
 */
 
85
draw2d.Drag.clearCurrent = function () 
 
86
{
 
87
    this.current = null;
 
88
    this.dragging = false;
 
89
};
 
90
 
 
91
/**
 
92
 * Encapsulates the functionality for a draggable element.
 
93
 * @scope public
 
94
 * @extends EventTarget
 
95
 * @class
 
96
 */
 
97
draw2d.Draggable=function(oElement, iConstraints) 
 
98
{
 
99
 
 
100
    /*
 
101
     * Inherit properties from EventTarget.
 
102
     */
 
103
    draw2d.EventTarget.call(this);
 
104
 
 
105
    /*
 
106
     * Call constructor.
 
107
     */
 
108
    this.construct(oElement, iConstraints);  
 
109
 
 
110
    /**
 
111
     * The difference between the x cursor position and left edge of the element.
 
112
     * @scope private
 
113
     * @type int
 
114
     */  
 
115
    this.diffX /*: int */ = 0;
 
116
 
 
117
    /**
 
118
     * The difference between the y cursor position and top edge of the element.
 
119
     * @scope private
 
120
     * @type int
 
121
     */  
 
122
    this.diffY /*: int */ = 0;
 
123
 
 
124
    /**
 
125
     * Collection of drop targets for this item.
 
126
     * @scope private
 
127
     * @type Array
 
128
     */
 
129
    this.targets = new draw2d.ArrayList();
 
130
}
 
131
 
 
132
/*
 
133
 * Inherit methods from EventTarget.
 
134
 */
 
135
draw2d.Draggable.prototype = new draw2d.EventTarget;
 
136
 
 
137
/**
 
138
 * Adds a new drop target to the draggable item.
 
139
 * @scope public
 
140
 * @param {DropTarget} oDropTarget The drop target to register for this item.
 
141
 * @type void
 
142
 */
 
143
// draw2d.Draggable.prototype.addDropTarget = function (oDropTarget /*: DropTarget */) 
 
144
//{
 
145
//    this.targets.add(oDropTarget);
 
146
//}
 
147
 
 
148
/**
 
149
 * Creates a new instance based on the given element and the constraints.
 
150
 * @scope private
 
151
 * @constructor
 
152
 * @param {HTMLElement} oElement The DOM element to make draggable.
 
153
 * @param {int} iConstraints The rules for dragging.
 
154
 */
 
155
draw2d.Draggable.prototype.construct = function (oElement /*: HTMLElement */,  iConstraints /*: int */) 
 
156
{
 
157
    /**
 
158
     * The element to make draggable.
 
159
     * @private
 
160
     * @type HTMLElement
 
161
     */
 
162
    this.element /*: HTMLElement */ = oElement;
 
163
 
 
164
    /**
 
165
     * The constraints indicating the rules for dragging.
 
166
     * @private
 
167
     * @type int
 
168
     */
 
169
    this.constraints /*: int */ = iConstraints;
 
170
 
 
171
    /*
 
172
     * Create a pointer to this object.
 
173
     */
 
174
    var oThis = this;
 
175
 
 
176
    var dblTemp = function()
 
177
    {
 
178
        // Check if the user has made a "double click"
 
179
        /*
 
180
         * Create a dragstart event and fire it.
 
181
         */
 
182
        var oDragStartEvent = new draw2d.DragDropEvent();
 
183
        oDragStartEvent.initDragDropEvent("dblclick", true);
 
184
        oThis.dispatchEvent(oDragStartEvent);
 
185
        var oEvent = arguments[0] || window.event;
 
186
        oEvent.cancelBubble = true;
 
187
        oEvent.returnValue = false;
 
188
      }
 
189
 
 
190
    /*
 
191
     * Create a temporary function named fnTemp.
 
192
     */
 
193
    var fnTemp = function () {
 
194
 
 
195
        /*
 
196
        * Get the event objects, which is either the first
 
197
        * argument (for DOM-compliant browsers and Netscape 4.x)
 
198
        * or window.event (for IE).
 
199
        */
 
200
        var oEvent = arguments[0] || window.event;
 
201
 
 
202
        var oDragStartEvent = new draw2d.DragDropEvent();
 
203
        // dispatch Event benötigt eventuel die x/y Koordinate um zu bestimmen
 
204
        // ob dieses Even wirklich relevant ist. (z.b. Wo man in dem Object hinein geklickt hat)
 
205
        //
 
206
        var xOffset    = oThis.node.workflow.getAbsoluteX();
 
207
        var yOffset    = oThis.node.workflow.getAbsoluteY();
 
208
        var scrollLeft = oThis.node.workflow.getScrollLeft();
 
209
        var scrollTop  = oThis.node.workflow.getScrollTop();
 
210
        oDragStartEvent.x = oEvent.clientX - oThis.element.offsetLeft+scrollLeft-xOffset;
 
211
        oDragStartEvent.y = oEvent.clientY - oThis.element.offsetTop+scrollTop-yOffset;
 
212
 
 
213
        // Context menu
 
214
        //
 
215
        if(oEvent.button==2)
 
216
        {
 
217
           oDragStartEvent.initDragDropEvent("contextmenu", true);
 
218
           oThis.dispatchEvent(oDragStartEvent)
 
219
        }
 
220
        // Drag&Drop
 
221
        //
 
222
        else
 
223
        {
 
224
           oDragStartEvent.initDragDropEvent("dragstart", true);
 
225
           /*
 
226
            * If the event isn't cancelled, proceed.
 
227
            */
 
228
           if (oThis.dispatchEvent(oDragStartEvent)) 
 
229
           {
 
230
              /*
 
231
               * Get the difference between the clientX and clientY
 
232
               * and the position of the element.
 
233
               */
 
234
               oThis.diffX = oEvent.clientX - oThis.element.offsetLeft;
 
235
               oThis.diffY = oEvent.clientY - oThis.element.offsetTop;
 
236
 
 
237
              /*
 
238
               * Set the currently dragged item.
 
239
               */
 
240
               draw2d.Drag.setCurrent(oThis);
 
241
 
 
242
              // Error if the user drag the object outside the window and release the mouse button there.
 
243
              // The object glues at the mose pointer.
 
244
              if(oThis.isAttached==true)
 
245
                 oThis.detachEventHandlers();
 
246
 
 
247
              /*
 
248
               * Add all DOM event handlers
 
249
               */
 
250
               oThis.attachEventHandlers();
 
251
           }
 
252
        }
 
253
 
 
254
        oEvent.cancelBubble = true;
 
255
        oEvent.returnValue = false;
 
256
    };
 
257
 
 
258
    /*
 
259
     * Create a temporary function named fnTemp.
 
260
     */
 
261
    var fnMouseMove = function () 
 
262
    {
 
263
        // Falls man gerade beim Drag&Drop ist, ist die
 
264
        // MouseOver Anzeige ausgeschaltet
 
265
        //
 
266
        if(draw2d.Drag.getCurrent()==null)
 
267
        {
 
268
          /*
 
269
          * Get the event objects, which is either the first
 
270
          * argument (for DOM-compliant browsers and Netscape 4.x)
 
271
          * or window.event (for IE).
 
272
          */
 
273
          var oEvent = arguments[0] || window.event;
 
274
          if(draw2d.Drag.currentHover!=null && oThis!=draw2d.Drag.currentHover)
 
275
          {
 
276
             // this codes will be called if you move the cursor from one figure (the current hover figure)
 
277
             // to another figure without of "touch" the background.
 
278
             //
 
279
             var oDropEvent = new draw2d.DragDropEvent();
 
280
             oDropEvent.initDragDropEvent("mouseleave", false, oThis);
 
281
             draw2d.Drag.currentHover.dispatchEvent(oDropEvent);
 
282
          }
 
283
          if(oThis!=null && oThis!=draw2d.Drag.currentHover)
 
284
          {
 
285
              var oDropEvent = new draw2d.DragDropEvent();
 
286
              oDropEvent.initDragDropEvent("mouseenter", false, oThis);
 
287
              oThis.dispatchEvent(oDropEvent);
 
288
          }
 
289
          draw2d.Drag.currentHover = oThis;
 
290
        }
 
291
        else
 
292
        {
 
293
         // var oEvent = arguments[0] || window.event;
 
294
        }
 
295
    };
 
296
 
 
297
    /*
 
298
     * Determine which method to use to add the event handler.
 
299
     */
 
300
    if (this.element.addEventListener) {
 
301
        this.element.addEventListener("mousemove", fnMouseMove, false);
 
302
        this.element.addEventListener("mousedown", fnTemp, false);
 
303
        this.element.addEventListener("dblclick", dblTemp, false);
 
304
    } else if (this.element.attachEvent) {
 
305
        this.element.attachEvent("onmousemove", fnMouseMove);
 
306
        this.element.attachEvent("onmousedown", fnTemp);
 
307
        this.element.attachEvent("ondblclick", dblTemp);
 
308
    } else {
 
309
        throw new Error("Drag not supported in this browser.");
 
310
    }
 
311
};
 
312
 
 
313
/**
 
314
 * Attaches event handlers for the mousemove and mouseup events.
 
315
 * @scope private
 
316
 * @private
 
317
 * @type void
 
318
 */
 
319
draw2d.Draggable.prototype.attachEventHandlers = function () {
 
320
 
 
321
    /*
 
322
     * Create a pointer to this object.
 
323
     */
 
324
    var oThis = this;
 
325
    oThis.isAttached = true;
 
326
 
 
327
    /*
 
328
     * Create a temporary function named tempMouseMove.
 
329
     */
 
330
    this.tempMouseMove = function () {
 
331
 
 
332
        /*
 
333
         * Get the event objects, which is either the first
 
334
         * argument (for DOM-compliant browsers and Netscape 4.x)
 
335
         * or window.event (for IE).
 
336
         */
 
337
        var oEvent = arguments[0] || window.event;
 
338
 
 
339
        /*
 
340
         * Get the new x and y coordinates for the dragged element by
 
341
         * subtracting the difference in the x and y direction from 
 
342
         * the mouse position on the screen (clientX and clientY).
 
343
         */
 
344
        var newPos = new draw2d.Point(oEvent.clientX - oThis.diffX, oEvent.clientY - oThis.diffY);
 
345
 
 
346
        // Adjust the new location if the object can snap to a helper
 
347
        // like grid, geometry, ruler,...
 
348
        //
 
349
        if(oThis.node.getCanSnapToHelper())
 
350
        {
 
351
         newPos = oThis.node.getWorkflow().snapToHelper(oThis.node, newPos);
 
352
        }
 
353
 
 
354
        oThis.element.style.left = newPos.x+"px";
 
355
        oThis.element.style.top  = newPos.y+"px";
 
356
 
 
357
        var scrollLeft = oThis.node.workflow.getScrollLeft();
 
358
        var scrollTop  = oThis.node.workflow.getScrollTop();
 
359
        var xOffset = oThis.node.workflow.getAbsoluteX();
 
360
        var yOffset = oThis.node.workflow.getAbsoluteY();
 
361
        var oDropTarget  = oThis.getDropTarget(oEvent.clientX+scrollLeft-xOffset, oEvent.clientY+scrollTop-yOffset);
 
362
        var oCompartment = oThis.getCompartment(oEvent.clientX+scrollLeft-xOffset, oEvent.clientY+scrollTop-yOffset);
 
363
        if(draw2d.Drag.currentTarget!=null && oDropTarget!=draw2d.Drag.currentTarget)
 
364
        {
 
365
            var oDropEvent = new draw2d.DragDropEvent();
 
366
            oDropEvent.initDragDropEvent("dragleave", false, oThis);
 
367
            draw2d.Drag.currentTarget.dispatchEvent(oDropEvent);
 
368
        }
 
369
        if(oDropTarget!=null && oDropTarget!=draw2d.Drag.currentTarget)
 
370
        {
 
371
            var oDropEvent = new draw2d.DragDropEvent();
 
372
            oDropEvent.initDragDropEvent("dragenter", false, oThis);
 
373
            oDropTarget.dispatchEvent(oDropEvent);
 
374
        }
 
375
        draw2d.Drag.currentTarget      = oDropTarget;
 
376
 
 
377
 
 
378
        if(draw2d.Drag.currentCompartment!=null && oCompartment!=draw2d.Drag.currentCompartment)
 
379
        {
 
380
            var oDropEvent = new draw2d.DragDropEvent();
 
381
            oDropEvent.initDragDropEvent("figureleave", false, oThis);
 
382
            draw2d.Drag.currentCompartment.dispatchEvent(oDropEvent);
 
383
        }
 
384
        if(oCompartment!=null && oCompartment.node!=oThis.node && oCompartment!=draw2d.Drag.currentCompartment)
 
385
        {
 
386
            var oDropEvent = new draw2d.DragDropEvent();
 
387
            oDropEvent.initDragDropEvent("figureenter", false, oThis);
 
388
            oCompartment.dispatchEvent(oDropEvent);
 
389
        }
 
390
        draw2d.Drag.currentCompartment = oCompartment;
 
391
 
 
392
        /*
 
393
         * Create and fire a drag event.
 
394
         */
 
395
        var oDragEvent = new draw2d.DragDropEvent();
 
396
        oDragEvent.initDragDropEvent("drag", false);
 
397
        oThis.dispatchEvent(oDragEvent);
 
398
    };
 
399
 
 
400
    /*
 
401
     * Create a temporary function for the mouseup event.
 
402
     */
 
403
    oThis.tempMouseUp = function () {   
 
404
 
 
405
        /*
 
406
         * Detach all of the event handlers.
 
407
         */
 
408
        oThis.detachEventHandlers();
 
409
 
 
410
        /*
 
411
         * Get the event object.
 
412
         */
 
413
        var oEvent = arguments[0] || window.event;
 
414
 
 
415
        /*
 
416
         * Create and fire a dragend event.
 
417
         */
 
418
        var oDragEndEvent = new draw2d.DragDropEvent();
 
419
        oDragEndEvent.initDragDropEvent("dragend", false);
 
420
        oThis.dispatchEvent(oDragEndEvent);
 
421
 
 
422
        /*
 
423
         * Determine if the mouse is over a drop target.
 
424
         */
 
425
        var scrollLeft = oThis.node.workflow.getScrollLeft();
 
426
        var scrollTop  = oThis.node.workflow.getScrollTop();
 
427
        var xOffset = oThis.node.workflow.getAbsoluteX();
 
428
        var yOffset = oThis.node.workflow.getAbsoluteY();
 
429
        var oDropTarget = oThis.getDropTarget(oEvent.clientX+scrollLeft-xOffset, oEvent.clientY+scrollTop-yOffset);
 
430
        var oCompartment= oThis.getCompartment(oEvent.clientX+scrollLeft-xOffset, oEvent.clientY+scrollTop-yOffset);
 
431
        if (oDropTarget != null) 
 
432
        {
 
433
            var oDropEvent = new draw2d.DragDropEvent();
 
434
            oDropEvent.initDragDropEvent("drop", false, oThis);
 
435
            oDropTarget.dispatchEvent(oDropEvent);
 
436
        }
 
437
        if (oCompartment != null && oCompartment.node != oThis.node) 
 
438
        {
 
439
            var oDropEvent = new draw2d.DragDropEvent();
 
440
            oDropEvent.initDragDropEvent("figuredrop", false, oThis);
 
441
            oCompartment.dispatchEvent(oDropEvent);
 
442
        }
 
443
 
 
444
        if(draw2d.Drag.currentTarget!=null)
 
445
        {
 
446
            var oDropEvent = new draw2d.DragDropEvent();
 
447
            oDropEvent.initDragDropEvent("dragleave", false, oThis);
 
448
            draw2d.Drag.currentTarget.dispatchEvent(oDropEvent);
 
449
            draw2d.Drag.currentTarget=null;
 
450
        }
 
451
 
 
452
        draw2d.Drag.currentCompartment=null;
 
453
        draw2d.Drag.clearCurrent();
 
454
    };
 
455
 
 
456
    /*
 
457
     * Determine which method to use to add the event handlers for
 
458
     * the mousemove and mouseup events.
 
459
     */
 
460
    if (document.body.addEventListener) {
 
461
        document.body.addEventListener("mousemove", this.tempMouseMove, false);
 
462
        document.body.addEventListener("mouseup", this.tempMouseUp, false);
 
463
    } else if (document.body.attachEvent) {
 
464
        document.body.attachEvent("onmousemove", this.tempMouseMove);
 
465
        document.body.attachEvent("onmouseup", this.tempMouseUp);
 
466
    } else {
 
467
        throw new Error("Drag doesn't support this browser.");
 
468
    }
 
469
    
 
470
};
 
471
 
 
472
/**
 
473
 * Detaches event handlers for the mousemove and mouseup events.
 
474
 * @scope private
 
475
 */
 
476
draw2d.Draggable.prototype.detachEventHandlers = function () 
 
477
{
 
478
    this.isAttached = false;
 
479
    /*
 
480
     * Determine the method for removing the event handlers for the
 
481
     * mousemove and mouseup events.
 
482
     */
 
483
    if (document.body.removeEventListener) {
 
484
        document.body.removeEventListener("mousemove", this.tempMouseMove, false);
 
485
        document.body.removeEventListener("mouseup", this.tempMouseUp, false);
 
486
    } else if (document.body.detachEvent) {
 
487
        document.body.detachEvent("onmousemove", this.tempMouseMove);
 
488
        document.body.detachEvent("onmouseup", this.tempMouseUp);
 
489
    } else {
 
490
        throw new Error("Drag doesn't support this browser.");
 
491
    }
 
492
};
 
493
 
 
494
/**
 
495
 * Determines the drop target that the mouse is over.
 
496
 * @scope private
 
497
 * @param x The x-coordinate of the mouse.
 
498
 * @param y The y-coordinate of the mouse.
 
499
 * @return The drop target if the mouse is over one, null otherwise.
 
500
 */
 
501
draw2d.Draggable.prototype.getDropTarget = function (/*:int*/ x ,/*:int*/  y )
 
502
{
 
503
  for(var i=0;i<this.targets.getSize();i++)
 
504
  {
 
505
    var target = this.targets.get(i);
 
506
    if (target.node.isOver(x, y) && target.node!=this.node)
 
507
    {
 
508
        return target;
 
509
    }
 
510
  }
 
511
  return null;
 
512
}
 
513
 
 
514
/**
 
515
 * Determines the compartment target that the mouse is over.
 
516
 * @private
 
517
 * @param {int} x The x-coordinate of the mouse.
 
518
 * @param {int} y The y-coordinate of the mouse.
 
519
 * @return The drop target if the mouse is over one, null otherwise.
 
520
 */
 
521
draw2d.Draggable.prototype.getCompartment = function (x /*: int */, y /*: int */) /*: DropTarget */ 
 
522
{
 
523
  var result = null;
 
524
  for(var i=0;i<this.node.workflow.compartments.getSize();i++)
 
525
  {
 
526
    var target = this.node.workflow.compartments.get(i);
 
527
    if (target.isOver(x, y) && target!=this.node)
 
528
    {
 
529
        if(result==null)
 
530
           result = target;
 
531
        else if(result.getZOrder() < target.getZOrder())
 
532
           result = target;
 
533
    }
 
534
  }
 
535
  return result==null?null:result.dropable;
 
536
}
 
537
 
 
538
 
 
539
/**
 
540
 * Returns the left coordinate of the element.
 
541
 * @scope public
 
542
 * @return The left coordinate of the element.
 
543
 */
 
544
draw2d.Draggable.prototype.getLeft = function () /*: int */ 
 
545
{
 
546
    return this.element.offsetLeft;
 
547
}
 
548
 
 
549
/**
 
550
 * Returns the top coordinate of the element.
 
551
 * @scope public
 
552
 * @return The top coordinate of the element.
 
553
 */
 
554
draw2d.Draggable.prototype.getTop = function () /*: int */ 
 
555
{
 
556
    return this.element.offsetTop;
 
557
}
 
558
 
 
559
/**
 
560
 * Encapsulates information about a drag drop event.
 
561
 * @class
 
562
 * @scope public
 
563
 * @extends Event
 
564
 */
 
565
draw2d.DragDropEvent=function()
 
566
{
 
567
    /*
 
568
     * Inherit properties from Event.
 
569
     */
 
570
    draw2d.Event.call(this);
 
571
}
 
572
 
 
573
/*
 
574
 * Inherit methods from Event.
 
575
 */
 
576
draw2d.DragDropEvent.prototype = new draw2d.Event();
 
577
 
 
578
/**
 
579
 * Initializes the event object with information for the event.
 
580
 * @scope public
 
581
 * @param sType The type of event encapsulated by the object.
 
582
 * @param bCancelable True if the event can be cancelled.
 
583
 * @param oRelatedTarget The alternate target related to the event.
 
584
 */
 
585
draw2d.DragDropEvent.prototype.initDragDropEvent = function(sType /*: String */,
 
586
                                                      bCancelable /*: boolean */,
 
587
                                                      oRelatedTarget /*: EventTarget */) {
 
588
    /*
 
589
     * Call inherited method initEvent().
 
590
     */
 
591
    this.initEvent(sType, bCancelable);
 
592
 
 
593
    /*
 
594
     * Assign related target (may be null).
 
595
     */
 
596
    this.relatedTarget = oRelatedTarget;
 
597
}
 
598
 
 
599
/**
 
600
 * A target for a Draggable to be dropped.
 
601
 * @scope public
 
602
 * @class
 
603
 * @extends EventTarget
 
604
 */
 
605
draw2d.DropTarget=function(oElement)
 
606
{
 
607
    /*
 
608
     * Inherit properties from EventTarget.
 
609
     */
 
610
    draw2d.EventTarget.call(this);
 
611
 
 
612
    /*
 
613
     * Call constructor.
 
614
     */
 
615
    this.construct(oElement);
 
616
}
 
617
 
 
618
/*
 
619
 * Inherit methods from EventTarget.
 
620
 */
 
621
draw2d.DropTarget.prototype = new draw2d.EventTarget;
 
622
 
 
623
/**
 
624
 * Creates a new instance based on the given DOM element.
 
625
 * @constructor
 
626
 * @scope public
 
627
 * @param oElement The DOM element to make into a drop target.
 
628
 */
 
629
draw2d.DropTarget.prototype.construct = function (oElement /*: HTMLElement */) 
 
630
{
 
631
    /**
 
632
     * The DOM element to use as a drop target.
 
633
     * @scope private
 
634
     */
 
635
    this.element = oElement;
 
636
}
 
637
 
 
638
/**
 
639
 * Returns the left coordinate of the drop target.
 
640
 * @scope public
 
641
 * @return The left coordinate of the drop target.
 
642
 */
 
643
draw2d.DropTarget.prototype.getLeft = function () /*: int */ 
 
644
{
 
645
    var el = this.element;
 
646
    var ol=el.offsetLeft;
 
647
    while((el=el.offsetParent) != null)
 
648
    {
 
649
        ol += el.offsetLeft;
 
650
    }
 
651
    return ol;
 
652
}
 
653
 
 
654
/**
 
655
 * Returns the top coordinate of the drop target.
 
656
 * @scope public
 
657
 * @return The top coordinate of the drop target.
 
658
 */
 
659
draw2d.DropTarget.prototype.getTop = function () /*: int */
 
660
{
 
661
  var el = this.element;
 
662
  var ot=el.offsetTop;
 
663
  while((el=el.offsetParent) != null)
 
664
  {
 
665
     ot += el.offsetTop;
 
666
  }
 
667
  return ot;
 
668
}
 
669
 
 
670
/**
 
671
 * Returns the height of the drop target.
 
672
 * @scope public
 
673
 * @return The height of the drop target.
 
674
 */
 
675
draw2d.DropTarget.prototype.getHeight = function () /*: int */
 
676
{
 
677
    return this.element.offsetHeight;
 
678
}
 
679
 
 
680
/**
 
681
 * Returns the width of the drop target.
 
682
 * @scope public
 
683
 * @return The width of the drop target.
 
684
 */
 
685
draw2d.DropTarget.prototype.getWidth = function () /*: int */
 
686
{
 
687
    return this.element.offsetWidth;
 
688
}
 
 
b'\\ No newline at end of file'