<@class name="SvgClickable" inherit="SvgBehavior" hide="yes"> A clickable element behavior (c) SAP AG 2003-2006. All rights reserved. // constructor function SvgClickable(peer, props) { if (!peer) return; this.board = BOARD; this.delay = 0; this.repeat = 0; this.tooltip = null; this.tooltipVis = false; this.attach(peer, props); if (this.target && typeof this.target == 'object') { if (!this.onClick) this.onClick = 'onClick'; } } SVG.declareClass(SvgClickable, SvgBehavior); ////////////////////////////////////////////////////////////////////////////////////// // PROPERTIES <@prop name="target:Object">Target object <@prop name="onClick" type="String|Function">The method/function to invoke when the element is clicked <@prop name="delay:i:0">The click delay period in ms (0 means no delay) <@prop name="repeat:i:0">The click repeat interval in ms (0 means no repeat) <@prop name="count:i:0">Number of repeated clicks during current button press <@prop name="glyph:s" default="">The behavior's styling glyph <@prop name="tooltip:s" default="">The tooltip to display when the mouse is over the element ////////////////////////////////////////////////////////////////////////////////////// // PRIVATE SvgClickable.prototype.listeners = ['mousedown', 'mouseup', 'mouseout', 'mouseover']; SvgClickable.prototype.mousedown = function(evt) { if (this.glyph) this.peer.setAttribute('class', this.glyph+'Pressed'); this.stopTimer(); if (!this.onClick) return; this.doclick(); if (this.delay || this.repeat) { this.timer = new SvgTimer({target:this, ontick:'doclick', delay:this.delay, repeat:this.repeat}); this.timer.start(); } } SvgClickable.prototype.mouseup = function(evt) { if (this.glyph) this.peer.setAttribute('class', this.glyph+'Hilight'); this.stopTimer(); } SvgClickable.prototype.mouseover = function(evt) { if (this.glyph) this.peer.setAttribute('class', this.glyph+'Hilight'); if (this.tooltip) { if (!this.tooltipVis) { this.board.canvas.showTooltip(this.tooltip, {clientX: evt.clientX+28, clientY: evt.clientY+24}); this.tooltipVis = true; } evt.stopPropagation(); } } SvgClickable.prototype.mouseout = function(evt) { if (this.tooltip) { this.board.canvas.hideTooltip(); this.tooltipVis = false; } if (this.glyph) this.peer.setAttribute('class', this.glyph+'Normal'); this.stopTimer(); } SvgClickable.prototype.doclick = function(timer) { this.count = (timer && timer.count || 0) + 1; this.callTarget(this.onClick); } SvgClickable.prototype.stopTimer = function() { if (this.timer) this.timer.stop(); this.timer = null; }