Events

The LiterallyCanvas() object allows you to subscribe to several events. Here’s how:

var unsubscribe = lc.on('eventName', function(arguments) {
  // do stuff
});
unsubscribe();  // stop listening

See Event subscription for details.

Definition format

eventName (function signature)

Description

Drawing changes

drawingChange ()

The drawing just changed in some way. This is a catch-all event that is fired after each of the other events in this section except for primaryColorChange and secondaryColorChange, which don’t actually change the drawing.

shapeSave ({shape, previousShapeId})

A new shape was just added to the drawing above previousShapeId.

snapshotLoad ()

A snapshot was just loaded.

clear ()

The drawing was just cleared.

undo ()

The last action was undone.

redo ()

An undone action was reapplied.

primaryColorChange (newColor)

The primary color was just changed.

secondaryColorChange (newColor)

The secondary color was just changed.

backgroundColorChange (newColor)

The background color was just changed.

Tool state

drawStart ({tool})

Deprecated since version 0.4.9.

This event only fires for tools that use the “simple” version of the tool API. It will go away in version 0.5.

drawContinue ({tool})

Deprecated since version 0.4.9.

This event only fires for tools that use the “simple” version of the tool API. It will go away in version 0.5.

drawEnd ({tool})

Deprecated since version 0.4.9.

This event only fires for tools that use the “simple” version of the tool API. It will go away in version 0.5.

toolChange ({tool})

The given tool has just been made active.

View changes

pan ({x, y})

The view has been panned to the given coordinates.

zoom ({oldScale, newScale})

The view has been zoomed from oldScale to newScale.

repaint ({layerKey})

The layerKey layer has just been repainted. The actual value of layerKey is not stable, but interpreting it won’t kill you.

Pointer

Note

These didn’t have the lc- prefix from v.4.5-0.4.7, until someone realized they conflict with Internet Explorer’s one-browser-wonder pointer events standard.

lc-pointerdown ({x, y})

The mouse button has just pressed down or a touch has begun.

lc-pointerup ({x, y})

The mouse button has just released or a touch has ended.

lc-pointermove ({x, y})

The mouse moved while the mouse button was not pressed.

lc-pointerdrag ({x, y})

The mouse moved while the mouse button was pressed, or a touch moved.