Expand all

ve.EventSequencer

Constructor

new ve.EventSequencer() #

EventSequencer class with on-event and after-event listeners.

After-event listeners are fired as soon as possible after the corresponding native event. They are similar to the setTimeout(f, 0) idiom, except that they are guaranteed to execute before any subsequent on-event listener. Therefore, events are executed in the 'right order'.

This matters when many events are added to the task queue in one go. For instance, browsers often queue 'keydown' and 'keypress' in immediate sequence, so a setTimeout(f, 0) defined in the keydown listener will run after the keypress listener (i.e. in the 'wrong' order). EventSequencer ensures that this does not happen.

All these listeners receive the jQuery event as an argument. If an on-event listener needs to pass information to a corresponding after-event listener, it can do so by adding properties into the jQuery event itself.

There are also 'onLoop' and 'afterLoop' listeners, which only fire once per Javascript event loop iteration, respectively before and after all the other listeners fire.

There is special handling for sequences (keydown,keypress), where the keypress handler is called before the native keydown action happens. In this case, after-keydown handlers fire after on-keypress handlers.

For further event loop / task queue information, see: http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-loops

Source:
EventSequencer class with on-event and after-event listeners.

Properties

afterListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

afterLoopListeners #

Properties:

Type Description
Array.<function()>
Source:

afterLoopOneListeners #

Properties:

Type Description
Array.<function()>
Source:

afterLoopTimeoutId #

Properties:

Type Description
number
Source:

afterOneListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

doneOnLoop #

Properties:

Type Description
boolean
Source:

onListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

onLoopListeners #

Properties:

Type Description
Array.<function()>
Source:

pendingCalls #

Properties:

Name Type Description
Pending Array.<Object>

calls

  • id {number} Id for setTimeout
  • func {Function} Post-event listener
  • ev {jQuery.Event} Browser event
  • eventName {string} Name, such as keydown
Source:

Methods

after(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired as soon as possible after the native action

Parameters:

Name Type Description
listeners Object.<string, function()>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired as soon as possible after the native action

afterEvent(eventName, ev)private #

Generic after listener method which gets queued

Parameters:

Name Type Description
eventName string

Javascript name of the event, e.g. 'keydown'

ev jQuery.Event

The browser event

Source:
Generic after listener method which gets queued

afterLoop(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired at the end of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired at the end of the Javascript event loop iteration

afterLoopOne(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired once, at the end of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired once, at the end of the Javascript event loop iteration

afterOne(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired once, as soon as possible after the native action

Parameters:

Name Type Description
listeners Object.<string, Array.<function()>>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired once, as soon as possible after the native action

attach($node) → {ve.EventSequencer}chainable #

Attach to a node, to listen to its jQuery events

Parameters:

Name Type Description
$node jQuery

The node to attach to

Source:

Returns:

Type
ve.EventSequencer
Attach to a node, to listen to its jQuery events

callListener(timing, eventName, i, listener, ev) #

Single method to perform all listener calls, for ease of debugging

Parameters:

Name Type Description
timing string

on|after|afterOne|onLoop|afterLoop|afterLoopOne

eventName string

Name of the event

i number

The sequence of the listener

listener function

The listener to call

ev jQuery.Event

The browser event

Source:
Single method to perform all listener calls, for ease of debugging

cancelPostponed(timeoutId) #

Cancel a postponed call.

This is a separate function because that makes it easier to replace when testing

Parameters:

Name Type Description
timeoutId number

Unique postponed timeout id

Source:
Cancel a postponed call.

detach() → {ve.EventSequencer}chainable #

Detach from a node (if attached), to stop listen to its jQuery events

Source:

Returns:

Type
ve.EventSequencer
Detach from a node (if attached), to stop listen to its jQuery events

doAfterLoop(myTimeoutId)private #

Call each afterLoopListener once, unless the setTimeout is already cancelled

Parameters:

Name Type Description
myTimeoutId number

The calling setTimeout id

Source:
Call each afterLoopListener once, unless the setTimeout is already cancelled

doOnLoop()private #

Call each onLoopListener once

Source:
Call each onLoopListener once

on(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired just before the browser native action

Parameters:

Name Type Description
listeners Object.<string, function()>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired just before the browser native action

onEvent(eventName, ev)private #

Generic listener method which does the sequencing

Parameters:

Name Type Description
eventName string

Javascript name of the event, e.g. 'keydown'

ev jQuery.Event

The browser event

Source:
Generic listener method which does the sequencing

onLoop(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired at the start of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired at the start of the Javascript event loop iteration

postpone(callback) → {number} #

Make a postponed call.

This is a separate function because that makes it easier to replace when testing

Parameters:

Name Type Description
callback function

The function to call

Source:

Returns:

Unique postponed timeout id

Type
number
Make a postponed call.

resetAfterLoopTimeout()private #

Push any pending doAfterLoop to end of task queue (cancel, then re-set)

Source:
Push any pending doAfterLoop to end of task queue (cancel, then re-set)

runPendingCalls(eventName)private #

Run any pending listeners, and clear the pending queue

Parameters:

Name Type Description
eventName string

The name of the event currently being triggered

Source:
Run any pending listeners, and clear the pending queue

makeEventHandler(name) → {function}privateinner #

Generate an event handler for a specific event

Parameters:

Name Type Description
name string

The event's name

Source:

Returns:

An event handler

Type
function
Generate an event handler for a specific event
Expand all

ve.EventSequencer

Constructor

new ve.EventSequencer(eventNames) #

To fire after-event listeners promptly, the EventSequencer may need to listen to some events for which it has no registered on-event or after-event listeners. For instance, to ensure an after-keydown listener is be fired before the native keyup action, you must include both 'keydown' and 'keyup' in the eventNames Array.

Parameters:

Name Type Description
eventNames Array.<string>

List of event Names to listen to

Source:

To fire after-event listeners promptly, the EventSequencer may need to listen to some events for which it has no registered on-event or after-event listeners.

Properties

afterListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

afterLoopListeners #

Properties:

Type Description
Array.<function()>
Source:

afterLoopOneListeners #

Properties:

Type Description
Array.<function()>
Source:

afterLoopTimeoutId #

Properties:

Type Description
number
Source:

afterOneListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

doneOnLoop #

Properties:

Type Description
boolean
Source:

onListenersForEvent #

Properties:

Type Description
Object.<string, Array.<function()>>
Source:

onLoopListeners #

Properties:

Type Description
Array.<function()>
Source:

pendingCalls #

Properties:

Name Type Description
Pending Array.<Object>

calls

  • id {number} Id for setTimeout
  • func {Function} Post-event listener
  • ev {jQuery.Event} Browser event
  • eventName {string} Name, such as keydown
Source:

Methods

after(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired as soon as possible after the native action

Parameters:

Name Type Description
listeners Object.<string, function()>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired as soon as possible after the native action

afterEvent(eventName, ev)private #

Generic after listener method which gets queued

Parameters:

Name Type Description
eventName string

Javascript name of the event, e.g. 'keydown'

ev jQuery.Event

The browser event

Source:
Generic after listener method which gets queued

afterLoop(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired at the end of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired at the end of the Javascript event loop iteration

afterLoopOne(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired once, at the end of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired once, at the end of the Javascript event loop iteration

afterOne(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired once, as soon as possible after the native action

Parameters:

Name Type Description
listeners Object.<string, Array.<function()>>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired once, as soon as possible after the native action

attach($node) → {ve.EventSequencer}chainable #

Attach to a node, to listen to its jQuery events

Parameters:

Name Type Description
$node jQuery

The node to attach to

Source:

Returns:

Type
ve.EventSequencer
Attach to a node, to listen to its jQuery events

callListener(timing, eventName, i, listener, ev) #

Single method to perform all listener calls, for ease of debugging

Parameters:

Name Type Description
timing string

on|after|afterOne|onLoop|afterLoop|afterLoopOne

eventName string

Name of the event

i number

The sequence of the listener

listener function

The listener to call

ev jQuery.Event

The browser event

Source:
Single method to perform all listener calls, for ease of debugging

cancelPostponed(timeoutId) #

Cancel a postponed call.

This is a separate function because that makes it easier to replace when testing

Parameters:

Name Type Description
timeoutId number

Unique postponed timeout id

Source:
Cancel a postponed call.

detach() → {ve.EventSequencer}chainable #

Detach from a node (if attached), to stop listen to its jQuery events

Source:

Returns:

Type
ve.EventSequencer
Detach from a node (if attached), to stop listen to its jQuery events

doAfterLoop(myTimeoutId)private #

Call each afterLoopListener once, unless the setTimeout is already cancelled

Parameters:

Name Type Description
myTimeoutId number

The calling setTimeout id

Source:
Call each afterLoopListener once, unless the setTimeout is already cancelled

doOnLoop()private #

Call each onLoopListener once

Source:
Call each onLoopListener once

on(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired just before the browser native action

Parameters:

Name Type Description
listeners Object.<string, function()>

Function for each event

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired just before the browser native action

onEvent(eventName, ev)private #

Generic listener method which does the sequencing

Parameters:

Name Type Description
eventName string

Javascript name of the event, e.g. 'keydown'

ev jQuery.Event

The browser event

Source:
Generic listener method which does the sequencing

onLoop(listeners) → {ve.EventSequencer}chainable #

Add listeners to be fired at the start of the Javascript event loop iteration

Parameters:

Name Type Description
listeners function | Array.<function()>

Listener(s) that take no arguments

Source:

Returns:

Type
ve.EventSequencer
Add listeners to be fired at the start of the Javascript event loop iteration

postpone(callback) → {number} #

Make a postponed call.

This is a separate function because that makes it easier to replace when testing

Parameters:

Name Type Description
callback function

The function to call

Source:

Returns:

Unique postponed timeout id

Type
number
Make a postponed call.

resetAfterLoopTimeout()private #

Push any pending doAfterLoop to end of task queue (cancel, then re-set)

Source:
Push any pending doAfterLoop to end of task queue (cancel, then re-set)

runPendingCalls(eventName)private #

Run any pending listeners, and clear the pending queue

Parameters:

Name Type Description
eventName string

The name of the event currently being triggered

Source:
Run any pending listeners, and clear the pending queue

makeEventHandler(name) → {function}privateinner #

Generate an event handler for a specific event

Parameters:

Name Type Description
name string

The event's name

Source:

Returns:

An event handler

Type
function
Generate an event handler for a specific event