From 6285a779f393a72463ff80789a535cc9922500eb Mon Sep 17 00:00:00 2001 From: thatcher Date: Wed, 6 Mar 2013 17:34:12 -0500 Subject: [PATCH] cleaning up event names, reducing demo cases to just addHandler interface, normalizing event data to express more idiomatic javascript pattern of passing object instead of invoking callback with positional parameters --- src/button.js | 89 ++++++++++--- src/viewer.js | 49 ++++--- test/demo.html | 356 +++++++++++++++++-------------------------------- 3 files changed, 218 insertions(+), 276 deletions(-) diff --git a/src/button.js b/src/button.js index 4b98faf3..cec5d1f2 100644 --- a/src/button.js +++ b/src/button.js @@ -141,41 +141,81 @@ $.Button = function( options ) { clickTimeThreshold: this.clickTimeThreshold, clickDistThreshold: this.clickDistThreshold, - enterHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { + enterHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) { if ( buttonDownElement ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "onEnter", _this ); + _this.raiseEvent( "enter", { + button: _this, + tracker: tracker, + position: position, + buttonDownElement: buttonDownElement, + buttonDownAny: buttonDownAny, + originalEvent: event + }); } else if ( !buttonDownAny ) { inTo( _this, $.ButtonState.HOVER ); } }, - focusHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { - this.enterHandler( tracker, position, buttonDownElement, buttonDownAny ); - _this.raiseEvent( "onFocus", _this ); + focusHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) { + this.enterHandler( tracker, position, buttonDownElement, buttonDownAny, event ); + _this.raiseEvent( "focus", { + button: _this, + tracker: tracker, + position: position, + buttonDownElement: buttonDownElement, + buttonDownAny: buttonDownAny, + originalEvent: event + }); }, - exitHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { + exitHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) { outTo( _this, $.ButtonState.GROUP ); if ( buttonDownElement ) { - _this.raiseEvent( "onExit", _this ); + _this.raiseEvent( "exit", { + button: _this, + tracker: tracker, + position: position, + buttonDownElement: buttonDownElement, + buttonDownAny: buttonDownAny, + originalEvent: event + }); } }, - blurHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { - this.exitHandler( tracker, position, buttonDownElement, buttonDownAny ); - _this.raiseEvent( "onBlur", _this ); + blurHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) { + this.exitHandler( tracker, position, buttonDownElement, buttonDownAny, event ); + _this.raiseEvent( "blur", { + button: _this, + tracker: tracker, + position: position, + buttonDownElement: buttonDownElement, + buttonDownAny: buttonDownAny, + originalEvent: event + }); }, - pressHandler: function( tracker, position ) { + pressHandler: function( tracker, position, event ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "onPress", _this ); + _this.raiseEvent( "press", { + button: _this, + tracker: tracker, + position: position, + originalEvent: event + }); }, - releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ) { + releaseHandler: function( tracker, position, insideElementPress, insideElementRelease, event ) { if ( insideElementPress && insideElementRelease ) { outTo( _this, $.ButtonState.HOVER ); - _this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "release", { + button: _this, + tracker: tracker, + position: position, + insideElementPress: insideElementPress, + insideElementRelease: insideElementRelease, + originalEvent: event + }); } else if ( insideElementPress ) { outTo( _this, $.ButtonState.GROUP ); } else { @@ -183,17 +223,28 @@ $.Button = function( options ) { } }, - clickHandler: function( tracker, position, quick, shift ) { + clickHandler: function( tracker, position, quick, shift, event ) { if ( quick ) { - _this.raiseEvent("onClick", _this); + _this.raiseEvent("click", { + button: _this, + tracker: tracker, + position: position, + quick: quick, + shift: shift, + originalEvent: event + }); } }, - keyHandler: function( tracker, key ){ + keyHandler: function( tracker, key, event ){ //console.log( "%s : handling key %s!", _this.tooltip, key); if( 13 === key ){ - _this.raiseEvent( "onClick", _this ); - _this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "keypress", { + button: _this, + tracker: tracker, + key: key, + originalEvent: event + }); return false; } return true; diff --git a/src/viewer.js b/src/viewer.js index 2a6cf9dc..16cd3210 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1169,7 +1169,7 @@ function onBlur(){ } -function onCanvasClick( tracker, position, quick, shift ) { +function onCanvasClick( tracker, position, quick, shift, event ) { var zoomPreClick, factor; if ( this.viewport && quick ) { // ignore clicks where mouse moved @@ -1181,15 +1181,16 @@ function onCanvasClick( tracker, position, quick, shift ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-click', { + this.raiseEvent( 'click', { tracker: tracker, position: position, quick: quick, - shift: shift + shift: shift, + originalEvent: event }); } -function onCanvasDrag( tracker, position, delta, shift ) { +function onCanvasDrag( tracker, position, delta, shift, event ) { if ( this.viewport ) { if( !this.panHorizontal ){ delta.x = 0; @@ -1206,27 +1207,29 @@ function onCanvasDrag( tracker, position, delta, shift ) { this.viewport.applyConstraints(); } } - this.raiseEvent( 'canvas-click', { + this.raiseEvent( 'drag', { tracker: tracker, position: position, delta: delta, - shift: shift + shift: shift, + originalEvent: event }); } -function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) { +function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease, event ) { if ( insideElementPress && this.viewport ) { this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-release', { + this.raiseEvent( 'release', { tracker: tracker, position: position, insideElementPress: insideElementPress, - insideElementRelease: insideElementRelease + insideElementRelease: insideElementRelease, + originalEvent: event }); } -function onCanvasScroll( tracker, position, scroll, shift ) { +function onCanvasScroll( tracker, position, scroll, shift, event ) { var factor; if ( this.viewport ) { factor = Math.pow( this.zoomPerScroll, scroll ); @@ -1236,54 +1239,58 @@ function onCanvasScroll( tracker, position, scroll, shift ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-scroll', { + this.raiseEvent( 'scroll', { tracker: tracker, position: position, scroll: scroll, - shift: shift + shift: shift, + originalEvent: event }); //cancels event return false; } -function onContainerExit( tracker, position, buttonDownElement, buttonDownAny ) { +function onContainerExit( tracker, position, buttonDownElement, buttonDownAny, event ) { if ( !buttonDownElement ) { THIS[ this.hash ].mouseInside = false; if ( !THIS[ this.hash ].animating ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'container-exit', { + this.raiseEvent( 'exit', { tracker: tracker, position: position, buttonDownElement: buttonDownElement, - buttonDownAny: buttonDownAny + buttonDownAny: buttonDownAny, + originalEvent: event }); } -function onContainerRelease( tracker, position, insideElementPress, insideElementRelease ) { +function onContainerRelease( tracker, position, insideElementPress, insideElementRelease, event ) { if ( !insideElementRelease ) { THIS[ this.hash ].mouseInside = false; if ( !THIS[ this.hash ].animating ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'container-release', { + this.raiseEvent( 'release', { tracker: tracker, position: position, insideElementPress: insideElementPress, - insideElementRelease: insideElementRelease + insideElementRelease: insideElementRelease, + originalEvent: event }); } -function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny ) { +function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny, event ) { THIS[ this.hash ].mouseInside = true; abortControlsAutoHide( this ); - this.raiseEvent( 'container-enter', { + this.raiseEvent( 'enter', { tracker: tracker, position: position, buttonDownElement: buttonDownElement, - buttonDownAny: buttonDownAny + buttonDownAny: buttonDownAny, + originalEvent: event }); } diff --git a/test/demo.html b/test/demo.html index e38b9b51..9022d115 100644 --- a/test/demo.html +++ b/test/demo.html @@ -5,290 +5,174 @@
-
- Simple demo page to verify that event handlers pass along the original source event -
-
-
- -
+
+ Simple demo page to verify that event handlers pass along the original source event +
+
+
+ +