Skip to content

Core Events

Chuck Lorenz edited this page Nov 21, 2016 · 15 revisions

Overview

Adapt has been built with a module approach and to keep modules separate Adapt uses events to pass information between modules and notify them of changes.

Backbone built-in events

To listen to changes on any core model use the Adapt collections or course model. Backbone automatically triggers an event when an attribute changes.

// List of collections
Adapt.contentObjects
Adapt.articles
Adapt.blocks
Adapt.components

// Course model
Adapt.course

// How to listen
Adapt.articles.on('change:_isComplete', function(model) {
    console.log('This article just changed complete status', model.get('_id'));
})

// If inside a view you can use listenTo
this.listenTo(Adapt.components, 'change', this.componentChangedAttribute);

// The model is passed into the componentChangedAttribute on the view
// Using 'change' listens to all changes on a model 

Adapt built-in events

Adapt also allows modules to plugin into events through events triggered by core views. These events can be listened to by using the following syntax:

Adapt.on('pageView:postRender', function(view) {
    // 'view' is the current view triggering the event
});

Core events

Event Argument Description
configModel:dataLoaded Triggered when the config model is loaded. This can be used to stop the course files from being fetched.
configModel:loadCourseData Triggered just before Adapt creates the main content collections and models. This can be used to load the course files if a plugin has stopped the default fetch.
app:dataReady Triggered when all the course data is loaded.
adapt:start Triggered before Adapt starts the router, gives the start controller an opportunity to set a custom start location.
adapt:initialize Triggered when Adapt is ready to start the router.
router:location Adapt.location Triggered when the location changes.
router:menu model Triggered when a route hits a menu.
router:page model Triggered when a route hits a page.
remove Is used by Adapt to trigger an event to remove all views.
preRemove Is used by Adapt to trigger an event that must occur immediately prior to remove.
postRemove Is used by Adapt to trigger an event that must occur immediately after remove.
device:resize Adapt.device.screenWidth Triggered when the window resizes.
device:changed Adapt.device.screenSize Triggered when the device size changes.

Core views

Event Argument Description
menuView:preRender view Triggered when a menu’s view has initialised.
menuView:postRender view Triggered when a menu’s view has rendered.
pageView:preRender view Triggered when a page’s view has initialised.
pageView:postRender view Triggered when a page’s view has rendered.
pageView:ready view Triggered when all the assets are loaded for a page.
articleView:preRender view Triggered when an article’s view has initialised.
articleView:postRender view Triggered when an article’s view has rendered.
blockView:preRender view Triggered when a block’s view has initialised.
blockView:postRender view Triggered when a block’s view has rendered.
componentView:preRender view Triggered when a component’s view has initalised.
componentView:postRender view Triggered when a component’s view has rendered.
navigationView:preRender view Triggered when navigation view has initialised.
navigationView:postRender view Triggered when navigation view has rendered.
questionView:showFeedback view Triggered when a question shows feedback. Question view automatically sets up feedbackTitle and feedbackMessage as attributes on the current view’s model.
questionView:disabledFeedback view Triggered when a question is meant to show feedback but _canShowFeedback is disabled on the model.

Navigation events

Event Argument Description
navigation:backButton Triggered when the menu button is pressed.
navigation:toggleDrawer Triggered when the drawer toggle button is clicked.
Clone this wiki locally