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.

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");

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

  • config object

    Configure options relating to the authoring experience and behavior of Author API.

  • mode string

    Start Author API in one of the four main user interface views for managing Items and Activities.

  • organisation_id number

    Specifies which Item bank to load Activity and Item content from.

  • reference string boolean

    Applies in item_edit and activity_edit modes only, denotes the reference of the Item or Activity you are creating/editing.

  • user object

    The current user's (author's) details.

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.

  • errorListener function

    This function is called when one of the preset Learnosity API errors are thrown.

  • readyListener function

    This function is called when the API has been successfully initialized.

  • assetRequest function

    Integrate your own digital asset management (DAM) system to use your own media content in Questions and Features.

  • customButtons array

    Allows you to add custom buttons to the rich text editor toolbar used in the Widget (Questions or Features) editor view.

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.