Scalar 2 User's Guide

ScalarModel

The ScalarModel class stores local Scalar API data. Once the Scalar API JavaScript library is loaded, the ScalarModel object is available through the “model” property of the globally-scoped variable “scalarapi”.

Methods

MethodTypeDescription
getBookNode()ScalarNodeReturns the node representing the current book, if it can be found.
getCurrentPageNode()ScalarNodeReturns the node representing the current page, if it can be found.
getMainMenuNode()ScalarNodeReturns the node representing the current book’s main menu, if it can be found.
getNodes( [sort] )arrayReturns an array of all nodes for which data has been loaded, sorted according to the specified criteria (currently the only option is “alphabetical”).
getNodesWithProperty( property, value, [sort] )array

Returns an array of all nodes for which data has been loaded, that match the specified criteria.

Method parameters:

  • property (string) - The property to be matched. Any named property can be used, plus a few special options:

    • “scalarType” - Test for nodes with matching types like “page,” “media,” “annotation,” “tag”, etc.

    • “dominantScalarType” - Test for the node’s most specialized type—for example: every path is also a page, but with this test all paths will only match the “path” type and not the “page” type.

    • “mediaSource” - Test for media nodes whose whose source files match the named types specified in scalarapi.mediaSources, such as “JPEG”, “WAV”, etc.
    • “contentType” - Test for media nodes whose source files match the named content types specified in scalarapi.mediaSources, such as “audio”, “video”, etc.
       
  • value (*) - The value to be matched.

  • sort (string) - Sort method to be applied to the results (currently the only option is “alphabetical”).
getPublisherNode()ScalarNodeReturns the node representing the current book’s publisher, if it can be found.

This page has paths: