API Documentation for: 1.1.2
Show:

Canteen.Site Class

Namespace: Canteen

The Canteen Site is the client wrapper for the server API. Here's an example of how to initialize on your site:

$(function(){
    var site = Canteen.Site.instance;
    site.on('ready', function(){
        // Site is ready!
    });
});

Methods

_callbackIndex

(
  • name
  • callback
)
Int private

Inherited from Canteen.EventDispatcher:

Returns callback array index.

Parameters:

Returns:

Int:

Callback array index, or -1 if isn't registered.

_enableHistory

(
  • enable
)
private

Enable the history

Parameters:

  • enable Boolean

    If the history state change should be on

_enterPage

() private

Get the page for the current state

_gatewayReady

(
  • succes
)
private

Callback when a gateway is finished setting up

Parameters:

  • succes Boolean

    If gateway initialization was successfully

_onStateChanged

() private

Handler for the history state change

_updatePageContent

(
  • uri
  • [params]
)
private

Update the page content

Parameters:

  • uri String

    The uri to request page for

  • [params] Dictionary optional

    Post parameters to pass to the page

addPage

(
  • uriOrRegExp
  • pageInstance
)

Bind a uri to a page class

Parameters:

  • uriOrRegExp String | RegExp

    The page uri or regular expression of uri

  • pageInstance Canteen.Page

    The Page object to use for uri

getPageByUri

(
  • uri
)
Canteen.Page

Get a specific page by a uri

Parameters:

  • uri String

    The uri to fetch page for

Returns:

Canteen.Page:

The page object or null, if no page is found

off

(
  • name
  • callback
)

Inherited from Canteen.EventDispatcher:

Remove the event listener

Parameters:

  • name String*

    The type of event string separated by spaces, if no name is specifed remove all listeners.

  • callback Function | Array*

    The listener function or collection of callback functions

on

(
  • name
  • callback
)
cloudkid.EventDispatcher

Inherited from Canteen.EventDispatcher:

Add an event listener

Parameters:

  • name String | Object

    The type of event (can be multiple events separated by spaces), or a map of events to handlers

  • callback Function | Array*

    The callback function when event is fired or an array of callbacks.

Returns:

cloudkid.EventDispatcher:

Return this EventDispatcher

redirect

(
  • uri
  • [replaceInHistory=false]
  • [allowRefresh=false]
  • [asyncRefresh=true]
)

Redirect the page to a URI (about/overview)

Parameters:

  • uri String

    The site uri, without the base url

  • [replaceInHistory=false] Boolean optional

    If we should replace the current page in the history

  • [allowRefresh=false] Boolean optional

    If we should allow page refreshes if the user redirects to the current page (default is false)

  • [asyncRefresh=true] Boolean optional

    If the refresh should be asyncronous

refresh

(
  • [async=true]
  • [params]
)

Do a refresh of the page content

Parameters:

  • [async=true] Boolean optional

    If the refresh should be asyncronous

  • [params] Mixed optional

    If async, some optional post parameters

resize

()

Called whenever the window resizes, pass along to page

trigger

(
  • type
  • params
)

Inherited from Canteen.EventDispatcher:

Dispatch an event

Parameters:

  • type String

    The event string name,

  • params

    Additional parameters

type

(
  • value
)
String private

Inherited from Canteen.EventDispatcher:

Return type of the value.

Parameters:

  • value

Returns:

String:

The type

Properties

_currentId

Int private

The current state count

_currentPage

Canteen.Page private

If there's a page for the current state

_currentState

String private

The string of the current state

_instance

Site private

The singleton instance of the site

_lastRequest

String private

The last uri page request made, helps clear up traffic jams

_listeners

Array private

Inherited from Canteen.EventDispatcher:

The collection of listeners

_pages

Array private

An array of the pages

currentPage

Canteen.Page

Get the current page object

currentState

String

The current state URI

gateway

Gateway

The instancee of the gateway

instance

Site static

Get the singleton instance of the site

options

Dictionary

The current setup options

options.contentId

String

The jQuery selector for target of the page content

Default: "#content"

options.loadingClass

String

The name of the class to show page or site loading

Default: "loading"

options.pageLoadingId

String

The jQuery selector to add loading class for page loading

Default: "article"

options.pageTitleId

String

The jquery selector for the target of the page title

Default: "h1"

options.siteLoadingId

String

The jQuery selector to add loading class for site

Default: "body"

parameters

Dictionary

The collection of query string parameters

VERSION

String

The current site version

Events

enter

A Canteen Page has entered

Event Payload:

  • uri String

    The page URI being entered

exit

A Canteen Page has exited completed

Event Payload:

  • uri String

    The page URI being exited

loading

The page is starting load

loadingDone

The page loading is done

ready

The entire site is ready