make event handler validation private

This commit is contained in:
Tom 2024-01-29 13:01:44 -05:00
parent a55071f67b
commit 024cee42f5
3 changed files with 22 additions and 4 deletions

View File

@ -65,6 +65,11 @@ class CanvasDrawer extends $.DrawerBase{
// Canvas default is "true", so this will only be changed if user specifies "false" in the options or via setImageSmoothinEnabled.
this._imageSmoothingEnabled = true;
// Since the tile-drawn and tile-drawing events are fired by this drawer, make sure handlers can be added for them
this.viewer.allowEventHandler("tile-drawn");
this.viewer.allowEventHandler("tile-drawing");
}
/**

View File

@ -51,7 +51,7 @@
*/
$.EventSource = function() {
this.events = {};
this.rejectedEventList = {};
this._rejectedEventList = {};
};
/** @lends OpenSeadragon.EventSource.prototype */
@ -95,8 +95,8 @@ $.EventSource.prototype = {
*/
addHandler: function ( eventName, handler, userData, priority ) {
if(Object.prototype.hasOwnProperty.call(this.rejectedEventList, eventName)){
$.console.error(`Error adding handler for ${eventName}. ${this.rejectedEventList[eventName]}`);
if(Object.prototype.hasOwnProperty.call(this._rejectedEventList, eventName)){
$.console.error(`Error adding handler for ${eventName}. ${this._rejectedEventList[eventName]}`);
return false;
}
@ -217,9 +217,20 @@ $.EventSource.prototype = {
* to be printed to the console
* @param {String} eventName - Name of the event
* @param {String} [errorMessage] - Optional string to print to the console
* @private
*/
rejectEventHandler(eventName, errorMessage = ''){
this.rejectedEventList[eventName] = errorMessage;
this._rejectedEventList[eventName] = errorMessage;
},
/**
* Explicitly allow an event handler to be added for this event type, undoing
* the effects of rejectEventHandler
* @param {String} eventName - Name of the event
* @private
*/
allowEventHandler(eventName){
delete this._rejectedEventList[eventName];
}
};

View File

@ -51,6 +51,8 @@ class HTMLDrawer extends $.DrawerBase{
// Reject listening for the tile-drawing event, which this drawer does not fire
this.viewer.rejectEventHandler("tile-drawing", "The HTMLDrawer does not raise the tile-drawing event");
// Since the tile-drawn event is fired by this drawer, make sure handlers can be added for it
this.viewer.allowEventHandler("tile-drawn");
}
/**