From dab182757df2b6942a67c70d6a69667e7b6ba723 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Tue, 24 Sep 2013 13:36:13 -0700 Subject: [PATCH] Renamed EventHandler to EventSource (#225) --- Gruntfile.js | 2 +- src/button.js | 6 ++-- src/{eventhandler.js => eventsource.js} | 6 ++-- src/navigator.js | 4 +-- src/referencestrip.js | 2 +- src/tilesource.js | 6 ++-- src/viewer.js | 6 ++-- test/events.js | 40 +++++++++++++------------ 8 files changed, 37 insertions(+), 35 deletions(-) rename src/{eventhandler.js => eventsource.js} (98%) diff --git a/Gruntfile.js b/Gruntfile.js index 81f70b10..332f49d1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,7 +22,7 @@ module.exports = function(grunt) { sources = [ "src/openseadragon.js", "src/fullscreen.js", - "src/eventhandler.js", + "src/eventsource.js", "src/mousetracker.js", "src/control.js", "src/controldock.js", diff --git a/src/button.js b/src/button.js index f6aca329..86755a72 100644 --- a/src/button.js +++ b/src/button.js @@ -50,7 +50,7 @@ $.ButtonState = { * as fading the bottons out when the user has not interacted with them * for a specified period. * @class - * @extends OpenSeadragon.EventHandler + * @extends OpenSeadragon.EventSource * @param {Object} options * @param {String} options.tooltip Provides context help for the button we the * user hovers over it. @@ -83,7 +83,7 @@ $.Button = function( options ) { var _this = this; - $.EventHandler.call( this ); + $.EventSource.call( this ); $.extend( true, this, { @@ -238,7 +238,7 @@ $.Button = function( options ) { outTo( this, $.ButtonState.REST ); }; -$.extend( $.Button.prototype, $.EventHandler.prototype, { +$.extend( $.Button.prototype, $.EventSource.prototype, { /** * TODO: Determine what this function is intended to do and if it's actually diff --git a/src/eventhandler.js b/src/eventsource.js similarity index 98% rename from src/eventhandler.js rename to src/eventsource.js index 51fa54a1..012ce68f 100644 --- a/src/eventhandler.js +++ b/src/eventsource.js @@ -1,5 +1,5 @@ /* - * OpenSeadragon - EventHandler + * OpenSeadragon - EventSource * * Copyright (C) 2009 CodePlex Foundation * Copyright (C) 2010-2013 OpenSeadragon contributors @@ -44,11 +44,11 @@ * matches. * @class */ -$.EventHandler = function() { +$.EventSource = function() { this.events = {}; }; -$.EventHandler.prototype = { +$.EventSource.prototype = { /** * Add an event handler for a given event. diff --git a/src/navigator.js b/src/navigator.js index 7197776a..77119d0e 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -43,7 +43,7 @@ * @class * @name OpenSeadragon.Navigator * @extends OpenSeadragon.Viewer - * @extends OpenSeadragon.EventHandler + * @extends OpenSeadragon.EventSource * @param {Object} options * @param {String} options.viewerId */ @@ -196,7 +196,7 @@ $.Navigator = function( options ){ }; -$.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, { +$.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, { /** * @function diff --git a/src/referencestrip.js b/src/referencestrip.js index 47e7cf46..f821d2e3 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -219,7 +219,7 @@ $.ReferenceStrip = function ( options ) { }; -$.extend( $.ReferenceStrip.prototype, $.EventHandler.prototype, $.Viewer.prototype, { +$.extend( $.ReferenceStrip.prototype, $.EventSource.prototype, $.Viewer.prototype, { setFocus: function ( page ) { var element = $.getElement( this.element.id + '-' + page ), diff --git a/src/tilesource.js b/src/tilesource.js index 923806b2..e2ef8524 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -49,7 +49,7 @@ * side in M (in pixels), where N is the smallest integer which satisfies * 2^(N+1) >= M. * @class - * @extends OpenSeadragon.EventHandler + * @extends OpenSeadragon.EventSource * @param {Number|Object|Array|String} width * If more than a single argument is supplied, the traditional use of * positional parameters is supplied and width is expected to be the width @@ -104,7 +104,7 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve //Tile sources supply some events, namely 'ready' when they must be configured //by asyncronously fetching their configuration data. - $.EventHandler.call( this ); + $.EventSource.call( this ); //we allow options to override anything we dont treat as //required via idiomatic options or which is functionally @@ -412,7 +412,7 @@ $.TileSource.prototype = { }; -$.extend( true, $.TileSource.prototype, $.EventHandler.prototype ); +$.extend( true, $.TileSource.prototype, $.EventSource.prototype ); /** diff --git a/src/viewer.js b/src/viewer.js index 524e82f3..20e78a0d 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -51,7 +51,7 @@ var THIS = {}, * as arguments and we translate a positional call into an idiomatic call. * * @class - * @extends OpenSeadragon.EventHandler + * @extends OpenSeadragon.EventSource * @extends OpenSeadragon.ControlDock * @param {Object} options * @param {String} options.element Id of Element to attach to, @@ -170,7 +170,7 @@ $.Viewer = function( options ) { this._updateRequestId = null; //Inherit some behaviors and properties - $.EventHandler.call( this ); + $.EventSource.call( this ); this.addHandler( 'open-failed', function (source, args) { var msg = $.getString( "Errors.Open-Failed", args.source, args.message); @@ -356,7 +356,7 @@ $.Viewer = function( options ) { }; -$.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, { +$.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, { /** diff --git a/test/events.js b/test/events.js index c7608711..d99799be 100644 --- a/test/events.js +++ b/test/events.js @@ -61,15 +61,15 @@ } ); // ---------- - asyncTest( 'MouseTracker, EventHandler canvas-drag canvas-release canvas-click', function () { + asyncTest( 'MouseTracker, EventSource canvas-drag canvas-release canvas-click', function () { var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), mouseTracker = null, userData = { item1: 'Test user data', item2: Math.random() }, originalUserData = { item1: userData.item1, item2: userData.item2 }, dragCount = 10, - dragsHandledEventHandler = 0, - releasesHandledEventHandler = 0, - clicksHandledEventHandler = 0, + dragsHandledEventSource = 0, + releasesHandledEventSource = 0, + clicksHandledEventSource = 0, eventsHandledMouseTracker = 0, originalEventsPassedMouseTracker = 0, releasesExpected = 1, @@ -78,9 +78,9 @@ var onOpen = function ( eventSender, eventData ) { viewer.removeHandler( 'open', onOpen ); - viewer.addHandler( 'canvas-drag', onEventHandlerDrag ); - viewer.addHandler( 'canvas-release', onEventHandlerRelease ); - viewer.addHandler( 'canvas-click', onEventHandlerClick ); + viewer.addHandler( 'canvas-drag', onEventSourceDrag ); + viewer.addHandler( 'canvas-release', onEventSourceRelease ); + viewer.addHandler( 'canvas-click', onEventSourceClick ); mouseTracker = new OpenSeadragon.MouseTracker( { element: $canvas[0], @@ -115,20 +115,22 @@ $canvas.simulate( 'blur', event ); }; - var onEventHandlerDrag = function ( eventSender, eventData ) { - dragsHandledEventHandler++; + var onEventSourceDrag = function ( eventSender, eventData ) { + dragsHandledEventSource++; }; - var onEventHandlerRelease = function ( eventSender, eventData ) { - releasesHandledEventHandler++; + var onEventSourceRelease = function ( eventSender, eventData ) { + releasesHandledEventSource++; }; - var onEventHandlerClick = function ( eventSender, eventData ) { - clicksHandledEventHandler++; + var onEventSourceClick = function ( eventSender, eventData ) { + clicksHandledEventSource++; }; var checkOriginalEventReceived = function ( eventData ) { eventsHandledMouseTracker++; + //TODO Provide a better check for the original event...simulate doesn't currently extend the object + // with arbitrary user data. if ( eventData && eventData.originalEvent ) { originalEventsPassedMouseTracker++; } @@ -170,13 +172,13 @@ checkOriginalEventReceived( eventData ); mouseTracker.destroy(); - viewer.removeHandler( 'canvas-drag', onEventHandlerDrag ); - viewer.removeHandler( 'canvas-release', onEventHandlerRelease ); - viewer.removeHandler( 'canvas-click', onEventHandlerClick ); + viewer.removeHandler( 'canvas-drag', onEventSourceDrag ); + viewer.removeHandler( 'canvas-release', onEventSourceRelease ); + viewer.removeHandler( 'canvas-click', onEventSourceClick ); - equal( dragsHandledEventHandler, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); - equal( releasesHandledEventHandler, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); - equal( clicksHandledEventHandler, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); + equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); + equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); + equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' );