Class: Postcard

Postcard

new Postcard(element, options)

Represents a new Postcard instance
Parameters:
Name Type Description
element HTMLCanvasElement The Canvas element to render.
options Object Any options to overwrite the defaults.
Source:

Methods

addImage(id, url, zindex, options) → {PostcardImageObject}

Add an image
Parameters:
Name Type Argument Description
id String Unique identifier for the object
url Srting URL to the image
zindex Number <optional>
Z-index for the object. Defaults to 0
options Object <optional>
Defines placement and content. See PostcardObject contructor
Source:
Returns:
Reference to the newly created object
Type
PostcardImageObject

addObject(id, zindex, options) → {PostcardObject}

Add a generic object (shape)
Parameters:
Name Type Argument Description
id String Unique identifier for the object
zindex Number <optional>
Z-index for the object. Defaults to 0
options Object <optional>
Defines placement and content. See PostcardObject contructor
Source:
Returns:
Reference to the newly created object
Type
PostcardObject

addText(id, url, zindex, options) → {PostcardTextObject}

Add an image
Parameters:
Name Type Argument Description
id String Unique identifier for the object
url Srting URL to the image
zindex Number <optional>
Z-index for the object. Defaults to 0
options Object <optional>
Defines placement and content. See PostcardObject contructor
Source:
Returns:
Reference to the newly created object
Type
PostcardTextObject

clear()

Clears the canvas before rerendering.
Source:

clearMouseEvents()

Clear *user-defined* mouse events
Source:

export() → {dataURI}

Export the Postcard and get the Base64 data
Source:
Returns:
Type
dataURI

get(id) → {PostcardObject|Error}

Get an object on the postcard with its ID
Parameters:
Name Type Description
id String Unique identifier for the object
Source:
Returns:
- The object in question or an Error if not found
Type
PostcardObject | Error

getSelection() → {PostcardObject|null}

Get the current selection on the postcard, if there is one
Source:
Returns:
- The object in question or null
Type
PostcardObject | null

getSome(callback) → {PostcardObjectArray}

Get multiple objects on the postcard using a test function
Parameters:
Name Type Description
callback function Tests each element given arguments (key, zindex, value). Returning true keeps the element.
Source:
Returns:
- Array of elements which pass the test
Type
PostcardObjectArray

onMouseDown(userFunc)

Creates a wrapper function then stores a reference to it so we can clear it later
Parameters:
Name Type Description
userFunc function User defined function with x,y as params
Source:

onMouseMove(userFunc)

Creates a wrapper function then stores a reference to it so we can clear it later
Parameters:
Name Type Description
userFunc function User defined function with x,y as params
Source:

onMouseUp(userFunc)

Creates a wrapper function then stores a reference to it so we can clear it later
Parameters:
Name Type Description
userFunc function User defined function with x,y as params
Source:

remove(id)

Get an object on the postcard with its ID and remove it
Parameters:
Name Type Description
id String Unique identifier for the object
Source:

render()

Main rendering loop for the Postcard
Source:

save(event)

Export the Postcard and trigger a save prompt
Parameters:
Name Type Description
event Event The click event
Source:

triggerRefresh()

Triggers a refresh of the postcard. Use after changing the properties of any element.
Source:

<private, inner> getMouse(e)

Gets accurate mouse coordinates
Parameters:
Name Type Description
e Event the click event
Source:

<private, inner> selectionMouseDownEvent(e)

Mouse down event to use if selection is enabled
Parameters:
Name Type Description
e Event the click event
Source:

<private, inner> selectionMouseMoveEvent(e)

Mouse move event to use if selection is enabled
Parameters:
Name Type Description
e Event the click event
Source: