Classes / Ladybug.Application

EXTENDS

Ladybug.Class

OVERVIEW

This is the main Ladybug class, to create an App you will need to define your own App class by extending this one.

When extending this it is very important to override the onDomReady callback, as it is the place im which you'll bind your global events, plugins and so-on.

You may also want to override the init method but it's usually not required. If you do this, make sure to call this._super() with the options object for proper initialization.

BASIC USAGE

To create your own application object, extend this class and implement at least the OnDomReady method.

AppSample = Ladybug.Application.extend({
    init: function(options) {
        var obj = this;
        // Call parent's constructor
        obj._super(options);
    },
    onDomReady: function() {
        var obj = this;
        // Start the router
        obj.router.start();
    }
});

CLASS METHODS

function init(options)

Initization callback, this is run by the constructor

Available options

  • defaultRoute Default route to go when the router is started, defaults to /home
  • element The element to render the app in
  • onDomReady Document-ready callback

function onDomReady()

Document-ready callback, run from the jQuery(document).ready listener


function registerModule(name, module)

Register a module into the application

Available parameters

  • name Name of the module (slug)
  • module Instance of the module

function apiCall(options)

Call a Dragonfly API from the application context

Available options

  • endpoint Endpoint to call, defaults to /status
  • method Request method, defaults to get
  • data Hash with data to pass to the endpoint
  • success Success callback function
  • error Error callback function

See Ladybug.Class for inherited class members.

CLASS MEMBERS

defaultRoute

The default route, defaults to /home


element

The jQuery-wrapped element in which the application will be rendered.


modules

Hash with the registered modules


module

A reference to the current module instance


router

A reference to the application router instance


templates

Hash with the compiled templates


partials

Hash with the compiled partials


See Ladybug.Class for inherited class members.

Go back to previous page