mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 12:46:09 +03:00
Provide a static method in OpenSeadragon to get an existing viewer
From limited testing, this method allows retrieval even when the viewer was instantiated in a different file. OpenSeadragon keeps internal private state in _viewers, following the convention of the underscore prefix for private members.
This commit is contained in:
parent
fd85d5e22f
commit
c639dd15e3
@ -749,7 +749,9 @@
|
||||
|
||||
/* eslint-disable no-redeclare */
|
||||
function OpenSeadragon( options ){
|
||||
return new OpenSeadragon.Viewer( options );
|
||||
var viewer = new OpenSeadragon.Viewer( options );
|
||||
OpenSeadragon._viewers.set(viewer.element, viewer);
|
||||
return viewer;
|
||||
}
|
||||
|
||||
(function( $ ){
|
||||
@ -1403,6 +1405,26 @@ function OpenSeadragon( options ){
|
||||
CHROMEEDGE: 7
|
||||
},
|
||||
|
||||
/**
|
||||
* Keep track of which {@link Viewer}s have been created.
|
||||
* - Key: {@link Element} to which a Viewer is attached.
|
||||
* - Value: {@link Viewer} of the element defined by the key.
|
||||
* @static
|
||||
* @type {Object}
|
||||
*/
|
||||
// eslint-disable-next-line no-undef
|
||||
_viewers: new Map(),
|
||||
|
||||
/**
|
||||
* Returns the {@link Viewer} attached to a given DOM element. If there is
|
||||
* no viewer attached to the provided element, undefined is returned.
|
||||
* @function
|
||||
* @param {String|Element} element Accepts an id or element.
|
||||
* @returns {Viewer} The viewer attached to the given element, or undefined.
|
||||
*/
|
||||
getViewer: function(element) {
|
||||
return $._viewers.get(this.getElement(element));
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a DOM Element for the given id or element.
|
||||
|
Loading…
Reference in New Issue
Block a user