Adapt API
Finds ancestors of the current model and returns a model. Because of the way our menus system is setup findAncestor only works from components up to page level
var currentPage = Adapt.components[0].findAncestor('pages');
// returns the current page model that is an ancestor of the first component.
Finds descendants of the current model and returns a collection. Like findAncestor this only works from page level down to components.
var children = Adapt.pages[0].findDescendants('components');
// returns all the components that are in the first page.
Adapt's main course object can be accessed by using
Adapt.course
As this is inherited from Adapt model you can call the following methods
To tap into our internal event system you would need to require 'coreJS/adapt' and use the following methods.
#####- trigger Triggers a global event.
#####- on Listens to a global event and calls a callback when triggered.
#####- off Removes the callback from an object.
#####- once Similar to on but the callback is only fired once.
#####- listenTo This is used to listen to an event on another object. If the object is removed at anytime during Adapt running, listenTo should be used as these events are stored and removed when a view is removed.
#####- stopListening Stops listening to events on other objects so the callbacks will not be called.
#####- listenToOnce Similar to listenTo but only calls the callback once.
define(['coreJS/adapt'], function(Adapt) {
Adapt.on('pluginName:changed', function() {
console.log('callback fired');
});
Adapt.trigger('pluginName:changed');
// output - 'callback fired'
Adapt.off('pluginName:changed');
Adapt.trigger('pluginName:changed');
// output - no callback fired as event was removed with 'off'
var View = new Backbone.View.extend({
initialize: function() {
this.listenTo(Adapt, 'pluginName:updated', this.callbackFromEvent);
this.listenToOnce(Adapt, 'pluginName:stopListening', this.stopListeningToEvent);
},
callbackFromEvent: function() {
console.log('listenTo callback fired');
},
stopListeningToEvent: function() {
this.stopListening(Adapt, 'pluginName:updated');
}
});
Adapt.trigger('pluginName:updated');
// output - 'listenTo callback fired'
Adapt.trigger('pluginName:stopListening');
// output - calls the View.stopListeningToEvent method only once and removes the callback once fired
Adapt.trigger('pluginName:updated');
// output - nothing is called as the last event has remove the callback
});
More information on our internal events system can be viewed here
- Framework in Five Minutes
- Setting up Your Development Environment
- Manual Installation of the Adapt Framework
- Adapt Command Line Interface
- Common Issues
- Reporting Bugs
- Requesting Features
- Creating Your First Course
- Styling Your Course
- Configuring Your Project with config.json
- Content starts with course.json
- Course Localisation
- Compiling, testing and deploying your Adapt course
- Core Plugins in the Adapt Learning Framework
- Converting a Course from Framework Version 1 to Version 2
- Contributing to the Adapt Project
- Git Flow
- Adapt API
- Adapt Command Line Interface
- Core Events
- Core Model Attributes
- Core Modules
- Web Security Audit
- Peer Code Review
- Plugins
- Developing Plugins
- Developer's Guide: Components
- Developer's Guide: Theme
- Making a theme editable
- Developer's Guide: Menu
- Registering a Plugin
- Semantic Version Numbers
- Core Model Attributes
- Adapt Command Line Interface
- Accessibility v3
- Adapt Framework Right to Left (RTL) Support