Class: Events

Events

Events is a system to plug in callbacks to specific events in CGView. Use on to add a callback and off to remove it.

See individual record types for a list of event names.

Here are a list of additional events supported in CGView:

Event Description
cgv-load-json Called when IO.loadJSON() is executed
mousemove Called when mouse moves on the Viewer. Returns event-like object
click Called when mouse clicks on the Viewer. Returns event-like object
zoom-start Called once before the viewer is zoomed or moved
zoom Called every frame of the zoom or move
zoom-end Called once after the viewer is zoomed or moved
click Called when a click occurs in the viewer
mousemove Calleed when the mouse moves in the viewer
bookmarks-shortcut Called when a bookmark shortcut key is clicked

new Events()

Creats holder for events. Accessible via Viewer.events.

Methods

off(event, callback)

Remove a callback function from a specific CGView event. If no callback is provided, then all callbacks for the event will be removed. Namespaced events can and should be used to avoid unintentionally removing callbacks attached by other plugins. Accessible via Viewer.off().

// Remove all callbacks attached to the 'drag-start' event.
// This includes any namespaced events.
cgv.off('zoom-start');

// Remove all callbacks attached to the 'drag-start' event namespaced to 'my_plugin'
cgv.off('zoom-start.my_plugin');

// Remove all callbacks attached to any events namespaced to 'my_plugin'
cgv.off('.my_plugin');
Name Type Description
event String

Name of event. Events can be namespaced.

callback function

Specfic function to remove

on(event, callback)

Attach a callback function to a specific CGView event. Accessible via Viewer.on().

cgv = new CGV.Viewer('#my-viewer');
cgv.on('zoom-start', function() { console.log('Zooming has begun!') };

// The event can be namespaced for easier removal later
cgv.on('zoom-start.my_plugin', function() { console.log('Zooming has begun!') };
Name Type Description
event String

Name of event. Events can be namespaced.

callback function

Function to call when event is triggered

trigger(event, object)

Trigger a callback function for a specific event. Accessible via Viewer.trigger().

// Triggers all callback functions associated with zoom-start
cgv.trigger('zoom-start');

// Triggers can also be namespaced
cgv.trigger('zoom-start.my_plugin');
Name Type Description
event String

Name of event. Events can be namespaced.

object Object

Object to be passed back to 'on'.