Back

Web Sketchpad Document Event API

Version 4.8.0

 

Web Sketchpad Document Event API

Contents

Introduction

The Document Event API emits custom DOM events via the jQuery.trigger() API.

Document Events

Event Parameters

Each event generated by Document Event API is associated with two sets of parameters:

canvasDOMNode.on(events, handler)

handler(event, context, attributes) { ... }

event

This event object contains data on the event itself that was triggered.

type

The type of the event

context

A context object, containing various relevant WSP Objects, each of which might have its own set of callable methods.

  • document - the top-level document object

attributes

Various dumb-data string, numeric, or boolean values summarizing the event. This could, for example, be serialized and stored in a database.

  • timeStampISO 8601 Date and time

Events

Document Load

Events sent during Web Sketch creation.

Re-ordering, Adding, and Removing Tools

Events sent when tools are re-ordered, added, or removed.

context
  • document - The document object that contains the tools array.

Page Loading and Starting

Events sent during page change. The current page can change, but a given page can start and stop (even without page switch).

The event order switching from an old page to a new page is

  1. WillChangeCurrentPage
  2. StopCurrentPage (old page)
  3. UnloadPage (old page; implementation might delay unloading until anytime before document unload)
  4. LoadPage (new page; if the page isn't already loaded)
  5. StartCurrentPage (new page)
  6. DidChangeCurrentPage (new page)

Page Events

These are document-level events related to the current page.

context
  • sQuery - querying object for current sketch
  • sketch - the sketch object
attributes
  • pageId - current page ID as a string

Page Level sQuery events

These are document-level events related to sQuery sketch object events. sQuery events are used to monitor changes in sketch geometry (including objects not changing directly because of user interaction). sQuery events come in batches which conceptually happen at the same time, so we bracket those batches with document-level frame events, so that clients can know, for example, when a given batch of events is over.

context
  • sQuery - querying object for current sketch
  • sketch - the sketch object
attributes
  • pageId - current page ID as a string
  • frameIndex - index of this frame of events.

Interacting with Objects

Events sent when a user touches a sketch object, and taps, moves or changes it.

context
  • sQuery - querying object for current/new page
  • gobj - reference to the object in the sketch that generated this event
  • position - contains the mouse event for click events, and other similar data
  • touch - the event object containing coordinate information on the touch event
  • sketch - the sketch object
attributes
  • pageId - current page ID as a string
  • gobjId - the ID of the sketch object that generated the event
  • position - position of the event as a string/number form
  • touchIdentifier - each touch/click event has related mouse events(mouse down, mouse up, etc), this identifier is how you can identify the different mouse events as a single click
Tapping Objects

Events sent when a user taps a sketch object.

Dragging Objects

Events sent when a user touches a sketch object, and drags it around.

Manipulating Objects

Events sent when a user intereacts with an object and changes it or triggers object specific behavior, or when an Animate, Move, or Sequence button is activated (whether directly pressed by the user or indirectly activated by a Presentation button).

Button Activation and Deactivation

Events sent when Animate, Move, or Sequence buttons are activated or deactivated. The events have common properties for context and attributes:

context
  • sQuery - querying object for current/new page
  • button - the button that was activated or deactivated
  • id - the ID of the button
  • sketch - the sketch object
  • document - the top-level document object
attributes
  • pageId - current page ID as a string
  • timeStamp - the date and time of the event

Scrolling

Events sent when the user scrolls the sketch content area. The events have common properties for context and attributes:

context
  • sQuery - querying object for current/new page
  • position - contains the mouse event for click events, and other similar data
  • touch - the event object containing coordinate information on the touch event
  • sketch - the sketch object
attributes
  • pageId - current page ID as a string
  • position - position of the event as a string/number form
  • touchIdentifier - each touch/click event has related mouse events(mouse down, mouse up, etc), this identifier is how you can identify the different mouse events as a single click

Widget Events

Events sent when the user changes an object's properties (style, trace status, text/label, visibility, or existence) using the object widgets.

context
  • name - the name of the widget being used.
attributes
  • object(s) - one or more sketch objects whose properties were changed.

Examples of adding event handlers