<@class name="SvgDraggable" inherit="SvgBehavior" hide="yes"> A draggable element behavior (c) SAP AG 2003-2006. All rights reserved. // constructor function SvgDraggable(peer, props) { this.board = BOARD; this.moving = false; this.attach(peer, props); if (this.target && typeof this.target == 'object') { if (!this.onDragStart) this.onDragStart = 'onDragStart'; if (!this.onDragMove) this.onDragMove = 'onDragMove'; if (!this.onDragEnd) this.onDragEnd = 'onDragEnd'; } } SVG.declareClass(SvgDraggable, SvgBehavior); ////////////////////////////////////////////////////////////////////////////////////// // PROPERTIES <@prop name="target:Object">Target object <@prop name="onDragStart" type="String|Function">The method/function to invoke when the drag operation is started <@prop name="onDragMove" type="String|Function">The method/function to invoke while the drag operation is going on <@prop name="onDragEnd" type="String|Function">The method/function to invoke when the drag operation is ended ////////////////////////////////////////////////////////////////////////////////////// // PRIVATE SvgDraggable.prototype.listeners = ['mousedown']; SvgDraggable.prototype.mousedown = function(evt) { SvgDraggable.glass = SVG.createElement(SVG.rootNode, 'rect', {x:0, y:0, width:'100%', height:'100%', fill:'none', 'xfill-opacity':0.5, 'pointer-events':'all'}); SvgDraggable.glass.addEventListener('mousemove', this, false); SvgDraggable.glass.addEventListener('mouseup', this, false); this.client = {x:evt.clientX, y:evt.clientY}; this.origin = {x:evt.clientX, y:evt.clientY}; this.offset = {x:0, y:0}; this.button = evt.button; this.moving = true; this.callTarget(this.onDragStart); } SvgDraggable.prototype.mousemove = function(evt) { if (!this.moving) return; this.client.x = evt.clientX; this.client.y = evt.clientY; this.offset.x = evt.clientX-this.origin.x; this.offset.y = evt.clientY-this.origin.y; this.callTarget(this.onDragMove); } SvgDraggable.prototype.mouseup = function(evt) { if (!this.moving) return; this.moving = false; this.callTarget(this.onDragEnd); SVG.removeElement(SvgDraggable.glass); focus(); }