API Docs for: 0.0.7
Show:

$.mobile.toast Class

Extends Widget

A jQuery Mobile Android-like Toast Plugin.

Constructor

$.mobile.toast

() chainable

Example:

$.mobile.toast({ message: 'Live long and prosper!' });

Methods

_addToPage

() private

Add toast to page

_beforeEnd

() private

Called before end and handle close animation. Trigger "beforeClose" event.

_create

() private

Constructor method, called automaticly

_destroy

() private

Remove toast from page

_end

() private

Destroy toast and trigger "afterclose" event.

_getToastCoordinates

() Object private

Calculates top, left coordinates to postion toast

Returns:

Object:

Position object

_getWindowCoordinates

() Object private

Get position an size of page

Returns:

Object:

Position/size object

_parseDurationOption

() Number private

Parse function for "duration" option

Returns:

Number:

Duration in ms

_parseOptions

() private

Call parse functions for options

_renderText

() Object private

Render text method, render and style message in paragraph

Returns:

Object:

jQuery fragment

_renderToast

() Object private

Render toast method, render and style paragraph in container

Returns:

Object:

jQuery fragment

_setOption

(
  • key
  • value
)
private

Called from the _setOptions() method for each individual option. Widget state should be updated based on changes.

Parameters:

  • key String

    The name of the option to set.

  • value Object

    A value to set for the option.

_setOptions

() private

Called whenever the option() method is called, regardless of the form in which the option() method was called. Overriding this is useful if you can defer processor-intensive changes for multiple option changes.

open

() protected

Open method, open toast and auto-close it after duration

reposition

() protected

Reposition method, position toast during initialisation and later.

Properties

options

Object

Options of this widget

version

String

Version of the widget

Attributes

classOnClose

String

Optional class to overwrite styling of toast on close.

Default: ""

Example:

$.mobile.toast({
    message: 'Live long and prosper',
    classOnClose: 'pomegranate'
});
// Change default value
$.mobile.toast.prototype.options.classOnClose = 'pomegranate';

classOnOpen

String

Optional class to overwrite styling of toast on open.

Default: ""

Example:

$.mobile.toast({
    message: 'Live long and prosper',
    classOnOpen: 'pomegranate'
});
// Change default value
$.mobile.toast.prototype.options.classOnOpen = 'pomegranate';

duration

Number or String

Duration of message show to the user. Possible values: "short", "long" number in milliseconds.

Default: 2000

Example:

$.mobile.toast({
    message: 'Live long and prosper',
    duration: 2000
});
// Change default value
$.mobile.toast.prototype.options.duration = 2000;

message

String

The message of the toast.

Default: ""

Example:

$.mobile.toast({ message: 'Live long and prosper' });
// Change default value
$.mobile.toast.prototype.options.message = 'Live long and prosper';

position

Number or String

Position of message. Possible values: "top", "center", "bottom" or number in percent.

Default: 80

Example:

$.mobile.toast({
    message: 'Live long and prosper',
    position: 'top'
});
// Change default value
$.mobile.toast.prototype.options.postion = 'top';

Events

afterclose

Function

After close callback

Example:

$.mobile.toast({
    message: 'Live long and prosper!',
    afterclose: function( event, ui ){
        console.log('afterclose');
    }
});
$.mobile.toast.on('toastafterclose', function( event, ui ){});

afteropen

Function

After open callback

Example:

$.mobile.toast({
    message: 'Live long and prosper!',
    afteropen: function( event, ui ){
        console.log('afteropen');
    }
});
$.mobile.toast.on('toastafteropen', function( event, ui ){});

beforeclose

Function

Before close callback

Example:

$.mobile.toast({
    message: 'Live long and prosper!',
    beforeclose: function( event, ui ){
        console.log('beforeclose');
    }
});
$.mobile.toast.on('toastbeforeclose', function( event, ui ){});

beforeposition

Function

Before position callback

Example:

$.mobile.toast({
    message: 'Live long and prosper!',
    beforeposition: function( event, ui ){
        console.log('beforeposition');
    }
});
$.mobile.toast.on('toastbeforeposition', function( event, ui ){});

create

Create callback

Example:

$.mobile.toast({
    message: 'Live long and prosper!',
    create: function( event, ui ){
        console.log('create');
    }
});
$.mobile.toast.on('toastcreate', function( event, ui ){});