Bellhop Class

Defined in: Bellhop:6

Abstract the communication layer between the iframe and the parent DOM

connect

(
  • [iframe]
  • [origin="*"]
)
Bellhop

Defined in connect:193

Setup the connection

Parameters:

  • [iframe] DOM optional

    The iframe to communicate with. If no value is set, the assumption is that we're the child trying to communcate with our window.parent

  • [origin="*"] String optional

    The domain to communicate with if different from the current.

Returns:

Bellhop:

Return instance of current object

destroy

()

Inherited from BellhopEventDispatcher but overwritten in destroy:379

Destroy and don't user after this

disconnect

()

Defined in disconnect:263

Disconnect if there are any open connections

fetch

(
  • event
  • callback
  • [data]
  • [runOnce=false]
)
Bellhop

Defined in fetch:325

A convenience method for sending and the listening to create a singular link to fetching data. This is the same calling send and then getting a response right away with the same event.

Parameters:

  • event String

    The name of the event

  • callback Function

    The callback to call after, takes event object as one argument

  • [data] Object optional

    Optional data to pass along

  • [runOnce=false] Boolean optional

    If we only want to fetch once and then remove the listener

Returns:

Bellhop:

Return instance of current object

include

(
  • classname
)
private

Defined in include:423

Simple return function

Parameters:

  • classname String

    Qualified class name as a string. for example "cloudkid.MyClass" would return a reference to the function window.cloudkid.MyClass.

off

(
  • type
  • [callback]
)
Bellhop

Inherited from BellhopEventDispatcher: off:71

Remove an event listener

Parameters:

  • type String
    The type of event to listen for. If undefined, remove all listeners.
  • [callback] Function optional
    The optional handler when an event is triggered, if no callback is set then all listeners by type are removed

Returns:

Bellhop: Return instance of current object

on

(
  • type
  • callback
  • [priority=0]
)
Bellhop

Inherited from BellhopEventDispatcher: on:20

Add an event listener to the listen to an event from either the parent or iframe

Parameters:

  • type String | Object
    The type of event to listen for or a map of events to callbacks. Multiple events can be added by separating events with spaces.
  • callback Function
    The handler when an event is triggered
  • [priority=0] Int optional
    The priority of the event listener. Higher numbers are handled first.

Returns:

Bellhop: Return instance of current object

receive

()
private

Defined in receive:100

Handle messages in the window

respond

(
  • event
  • data
  • [runOnce=false]
)
Bellhop

Defined in respond:356

A convience method for listening to an event and then responding with some data right away. Automatically removes the listener

Parameters:

  • event String

    The name of the event

  • data Object

    The object to pass back. May also be a function; the return value will be sent as data in this case.

  • [runOnce=false] Boolean optional

    If we only want to respond once and then remove the listener

Returns:

Bellhop:

Return instance of current object

reviver

(
  • key
  • value
)
Object
static

Defined in reviver:390

When restoring from JSON via JSON.parse, we may pass a reviver function. In our case, this will check if the object has a specially-named property (__classname). If it does, we will attempt to construct a new instance of that class, rather than using a plain old Object. Note that this recurses through the object. See JSON.parse()

Parameters:

  • key String

    each key name

  • value Object

    Object that we wish to restore

Returns:

Object:

The object that was parsed - either cast to a class, or not

send

(
  • event
  • [data]
)
Bellhop

Defined in send:288

Send an event to the connected instance

Parameters:

  • event String

    The event type to send to the parent

  • [data] Object optional

    Additional data to send along with event

Returns:

Bellhop:

Return instance of current object

toString

() String

Defined in toString:169

And override for the toString built-in method

Returns:

String:

Representation of this instance

trigger

(
  • event
)
Trigger any event handlers for an event type

Parameters:

  • event Object
    The event to send

_listeners

Object private
The collection of event listeners

_sendLater

Array private

Defined in _sendLater:62

Save any sends to wait until after we're done

connected

Boolean private

Defined in connected:23

If we are connected to another instance of the bellhop

Default: false

connecting

Boolean private

Defined in connecting:46

If we are current trying to connec

Default: false

iframe

DOMElement private

Defined in iframe:77

The iframe element

isChild

Boolean private

Defined in isChild:38

If this instance represents an iframe instance

Default: true

onReceive

Function private

Defined in onReceive:16

Bound handler for the window message event

origin

Boolean private

Defined in origin:54

If using cross-domain, the domain to post to

Default: "*"

supported

Boolean

Defined in supported:69

Do we have something to connect to, should be called after attempting to connect()

target

DOM private

Defined in target:179

The target where to send messages

connected

Defined in connected:90

The connection has been established successfully

failed

Defined in failed:95

Connection could not be established