openseadragon/openseadragon — pull request #28 by houseofyin (2013-03-04 21:39:52+00:00)
Title: Issue 23: Initial attempt a this feature along with a demo page

Folks,

I took a crack at implementing Issue 23, the "expose original event in handlers". I think the code works, but I am not confident on the testing/verification code. I wanted to pass along what I had to get some feedback.

* There is one question that I had about the behavior for touch interfaces onMouseOver and onMouseDown are both expecting an event for the second parameter. This is passing a Touch point instead. Although a Touch object is very similar to an event object that are not identical, and isn't exactly passing the original event. That said, I am not sure if this is a problem. May need to include a comment in the API notes, since this object as passed here is getting passed along. Alternately, should there be some way to still pass the original touch event along.

```javascript
function onTouchStart( tracker, event ) {
//snip
onMouseOver( tracker, event.changedTouches[ 0 ] );
onMouseDown( tracker, event.touches[ 0 ] );
//snip
}
```

I don't have a good touch-based environment to test with, so I wasn't able to explore this beyond looking at the code.

* I didn't have any luck writing a test using QUnit. The top call of the stack in mouse tracker is not publicly visible, and I didn't have much luck simulating the events in QUnit. (In reading the QUnit documentation, it seems like folks augment QUnit with another framework to provide event simulation)

* Instead of an automated test, I wrote a demo page that logs the event information.
* There are a couple issues with this demo:
* The demo assumes you have one of the example images available.
* The demo actually disables the normal operations of the viewer. I had a more complex version that kept the original behavior, but I stripped it out to keep it simple
* I had success inserting the event handler using this style (i.e. replacing the original handler):

```javascript
viewer.innerTracker.clickHandler = function(tracker, position, delta, shift,event)
{// Blah, blah, blah }
```

but not using this style (i.e. using the addHandler method):

```javascript
viewer.addHandler("click", function(tracker, position, delta, shift,event)
{// Blah, blah, blah });
```

Although I left both in. Perhaps I am doing something wrong with the addHandler method.

* Because the viewer is not a traditional HTML input field, I couldn't figure out a way to force it to receive focus for keyboard input, so the demo does not successfully trigger those. (I thought about trying to grab the events for the navigator portion, because I know that is doing some sort of keyboard handling, but I wasn't sure how to navigate to that object to manipulate it's event handlers)

* I wasn't sure how to force the viewer to acquire a scrollbar, so that handler is in the demo, but I never figured out how to trigger it.

David