Author API Initialization
This article details the properties that are passed as parameters to the window.LearnosityAuthor.init()
method to initialize Author API.
This method is the starting point to initializing and rendering Author API, and as you can see in the example below, takes three key parameters:
The Initialization object is mandatory. Further detail on getting started and initializing Author API can also be found in the Quick Start guide.
Example
var initializationObject = {
"security": {
"consumer_key": "INSERT_CONSUMER_KEY_HERE",
"domain": "my.domain.com",
"timestamp": "20120202-1234",
"signature": "SHA256-HASH - See Security"
},
"request": {
"mode": "item_edit",
"reference": "my-item-reference",
"config": {
"global": {
"disable_onbeforeunload": true,
// All tags of type "internal_category_uuid" are hidden in the UI
"hide_tags":
[
{
"type": "internal_category_uuid"
}
]
},
"item_edit": {
"item": {
"back": true,
"columns": true,
"answers": true,
"scoring": true,
"reference": {
"edit": false,
"show": false,
"prefix": "LEAR_" // The reference for a new item will start with LEAR_
},
"save": true,
"status": false,
"dynamic_content": true,
"shared_passage": true
},
"widget": {
"delete": false,
"edit": true
}
},
"item_list": {
"item": {
"status": true,
"url": "http://myApp.com/items/:reference/edit"
},
"toolbar": {
"add": true,
"browse": {
"controls": [
{
"type": "hierarchy",
"hierarchies": [
{
"reference": "CCSS_Math_Hierarchy",
"label": "CCSS Math"
},
{
"reference": "CCSS_ELA_Hierarchy",
"label": "CCSS ELA"
},
{
"reference": "Demo_Items_Hierarchy",
"label": "Demo Items"
}
]
},
{
"type": "tag",
"tag": {
"type": "difficulty",
"label": "Difficulty"
}
},
{
"type": "tag",
"tag": {
"type": "content_provider",
"label": "Source"
}
}
]
}
},
"filter": {
"restricted": {
"current_user": true,
"tags": {
"all": [
{
"type": "Alignment",
"name": ["def456", "abc123"]
},
{
"type": "Course"
}
],
"either": [
{
"type": "Grade",
"name": "4"
},
{
"type": "Grade",
"name": "5"
},
{
"type": "Subject",
"name": ["Math", "Science"]
}
],
"none": [
{
"type": "Grade",
"name": "6"
}
]
}
}
}
},
"dependencies": {
"question_editor_api": {
"init_options": {}
},
"questions_api": {
"init_options": {}
}
},
"widget_templates": {
"back": true,
"save": true,
"widget_types": {
"default": "questions",
"show": true
}
},
"container": {
"height": "auto",
"fixed_footer_height": 0,
"scroll_into_view_selector": "body"
},
"label_bundle": { // German translation and date/time format changes
// Generic components and partials
"backButton": "Zurück",
"loadingText": "Wird geladen",
"modalClose": "Schließen",
"saveButton": "Speichern",
"duplicateButton": "Duplikat",
// itemList > dates (using Moment.js)
"dateTimeLocale": "",
"toolTipDateTimeSeparator": "um",
"toolTipDateFormat": "DD-MM-YYYY",
"toolTipTimeFormat": "HH:MM:SS",
}
},
}
}
var callbacks = {
"readyListener": function () {
console.log("Learnosity Author API is ready");
},
"errorListener": function (e) {
//callback to occur on error
console.log("Error code ", e.code);
console.log("Error message ", e.message);
console.log("Error name ", e.name);
console.log("Error name ", e.title);
}
};
var authorApp = LearnosityAuthor.init(initializationObject, callbacks, "learnosity-author");
Initialization
The Initialization
object is a JSON object which is passed as the first parameter into
the window.LearnosityAuthor.init() method. It includes all the information needed to initialize the API.
It contains the following two top-level properties:
Security Object
The Security object is a property generated by the Learnosity server-side SDKs to ensure that the APIs are only initialized from a secured, allowed source, using your consumer key and secret.
This is handled by our SDKs in:
For other languages, please see our Security & Authentication page on how to sign your requests.
Request Object
The request object contains all of configuration properties of authoring items and activities as well as user identification
Properties= mandatory property
Properties | |
---|---|
config |
object Optional configuration for each of the components that make up the Author API. This includes:
|
mode |
string The mode of component to be loaded. This attribute is required. Currently we support:
item_edit mode, users cannot navigate to the Item list. Thus, this mode is useful for integrating a custom CMS instead of using Learnosity's. |
organisation_id |
number Optional parameter to specify which Item Bank Items/Activities are loaded from/saved to. If this is not provided, then the consumer's primary Item Bank will be used. This will render the Item/Activity list with Items/Activities from requested the Item Bank, allowing Authors to view, create and modify (assuming the consumer has write access) Items/Activities. |
reference |
string | boolean Applies in item_edit and activity_edit modes only, denotes the reference of the Item or Activity you are creating/editing.If the Item or Activity already exists, it will be loaded from the Item bank. Otherwise, a new item/activity will be created with the provided reference, and will be stored in the Item bank once saved. If using Author API v1.20.0 or later, do not encode the reference by calling encodeURIComponent or any other encoding method since Author API already encodes it.Keep track of your Item references and Activity references in your CMS, or use the list view ( item_list and activity_list modes) for easier management of Items and Activities.For item_edit mode, you can also pass false (Boolean), will simply initialize Author API without fetching and loading an Item or creating a new Item. The UI will be empty, and a reference can be set later.
|
user |
object Required user object to ensure that any content changes are properly tracked in an audit trail. |
Callbacks
The callbacks object contains optional callback functions that allow detection of the 'ready' status of a Author API instance and any errors encountered.
These events can be handled by defining a readyListener
function and an errorListener
function respectively.
Properties | |
---|---|
errorListener |
function Function to be called on an error event. |
readyListener |
function Function to be called when the API has been successfully initialized or reset. See available events for more information. |
assetRequest |
function Use assetRequest to integrate a custom asset loader into author API. If defined, Question Editor API will
display a directory/file icon (i.e. "...") in fields where media is supported, as well as binding to the
"insert image" button in the HTML WYSIWYG editor. If the icon is clicked by an author the function is called.
|
customButtons |
array[] Use customButtons for custom behavior, e.g. adding an embedded video into a field. If customButtons are defined,
Question Editor API will display a custom button in its toolbar. When the button is clicked by an author, the "func" function is called.
|
HTML Element Selector
The second parameter passed to window.LearnosityAuthor.init() is a string
, containing a full CSS selector to an element on the HTML page. Each example below could be a valid value:
#learnosity_author // CSS selector based on id of an element
.learnosity_author // CSS selector based on a class of an element
This value tells Author API where to render itself on the page.
Note
If the HTML element selector is not provided, Author API will attempt to look for the element with a id "learnosity-author"
.
Note See the quick start guide for more information on how to build an example HTML page.