Scalar 2 User's Guide

ScalarAPI

The primary class in the Scalar API JavaScript library. Once the Scalar API JavaScript library is loaded, the ScalarAPI object is available through the globally-scoped variable “scalarapi”.

Methods

MethodReturn valueDescription
getNode( uriOrSlug )ScalarNodeReturns the ScalarNode in the current book identified by the specified URI or URI segment (also known as the “slug”), or null if no matching ScalarNode can be found.
loadBook( forceReload, successCallback, errorCallback )string

Load data about the current Scalar book. Returns a string indicating the current state of the request, whose possible values are “loading”, “queued”, or “loaded”.

Method parameters:

  • forceReload (boolean) - If true, any cached data for the book will be ignored, and a new request will be executed. If false, the method will return the string “loaded” if data for the book already exists.
     
  • successCallback (function) - A function to be executed when the request is completed successfully.
     
  • errorCallback (function) - A function to be executed when the request fails.
loadCurrentNode( forceReload, successCallback, errorCallback, [depth], [references], [relation] )string

Loads data about the Scalar node pointed to by the current URL. Returns a string indicating the current state of the request, whose possible values are “loading”, “queued”, or “loaded”.

Method parameters:

  • forceReload (boolean) - If true, any cached data for the node will be ignored, and a new request will be executed. If false, the method will return the string “loaded” if data for the requested node already exists.

  • successCallback (function) - A function to be executed when the request is completed successfully.

  • errorCallback (function) - A function to be executed when the request fails.

  • depth (number) - The number of degrees of separation between the requested node and any related nodes that should also be returned with this request. Higher numbers will result in longer load times; use with caution. Defaults to 0.

  • references (boolean) - If true, will return Scalar media linked from within the text of the requested node, if any. Defaults to false.

  • relation (string) - If not null, will only return nodes related to the requested node through the named relationship. Defaults to null, which returns nodes related through any relationship. Other possible values include “annotation”, “path”, “reply” (i.e. comment), and “tag”.
loadNode( uriSegment, forceReload, successCallback, errorCallback, [depth], [references], [relation], [start], [results], [provenance] )string

Loads data about the specified Scalar node in the current book. Returns a string indicating the current state of the request, whose possible values are “loading”, “queued”, or “loaded”.

Method parameters:

  • uriSegment (string) - The identifying URI segment (also known as the “slug”) for the node. For the home page of a Scalar book, this would be “index”.

  • forceReload (boolean) - If true, any cached data for the node will be ignored, and a new request will be executed. If false, the method will return the string “loaded” if data for the requested node already exists.

  • successCallback (function) - A function to be executed when the request is completed successfully.

  • errorCallback (function) - A function to be executed when the request fails.

  • depth (number) - The number of degrees of separation between the requested node and any related nodes that should also be returned with this request. Higher numbers will result in longer load times; use with caution. Defaults to 0.

  • references (boolean) - If true, will return Scalar media linked from within the text of the requested node, if any. Defaults to false.

  • relation (string) - If not null, will only return nodes related to the requested node through the named relationship. Defaults to null, which returns nodes related through any relationship. Other possible values include “annotation”, “path”, “reply” (i.e. comment), and “tag”.

  • start (number) - If specified, indicates the zero-based index of the first result to be returned.

  • results (number) - If specified, indicates the maximum number of results to be returned.
     
  • provenance (boolean) - If true, will return the provenance of the nodes.
loadNodesByType( type, forceReload, successCallback, errorCallback, [depth], [references], [relation], [start], [results], [hidden] )string

Loads all nodes of the specified type from the current Scalar book. Returns a string indicating the current state of the request, whose possible values are “loading” or “loaded”.

Method parameters:

  • type (string) - The type of ScalarNode to be retrieved. Possible values include “annotation”, “content” (i.e. all types—use with caution), “media”, “page”, “path”, “reply” (i.e. comment), or “tag”.

  • forceReload (boolean) - If true, any cached data for the nodes will be ignored, and a new request will be executed. If false, the method will return the string “loaded” if data for the type of nodes requested already exists.

  • successCallback (function) - A function to be executed when the request is completed successfully.

  • errorCallback (function) - A function to be executed when the request fails.

  • depth (number) - The number of degrees of separation between the requested nodes and any related nodes that should also be returned with this request. Higher numbers will result in longer load times; use with caution. Defaults to 0.

  • references (boolean) - If true, will return Scalar media linked from within the text of the requested nodes, if any. Defaults to false.

  • relation (string) - If not null, will only return nodes related to the requested nodes through the named relationship. Defaults to null, which returns nodes related through any relationship. Other possible values include “annotation”, “path”, “reply” (i.e. comment), and “tag”.

  • start (number) - If specified, indicates the zero-based index of the first result to be returned.

  • results (number) - If specified, indicates the maximum number of results to be returned.
     
  • hidden (boolean) - If true, will return results whose "live" property is set to 0
nodeSearch( sq, successCallback, errorCallback, [depth], [references], [relation], [start], [results], [hidden] )none

Loads all nodes matching the specified search query from the current Scalar book.

Method parameters:

  • sq (string) - The search query to be executed.

  • successCallback (function) - A function to be executed when the request is completed successfully.

  • errorCallback (function) - A function to be executed when the request fails.

  • depth (number) - The number of degrees of separation between the requested nodes and any related nodes that should also be returned with this request. Higher numbers will result in longer load times; use with caution. Defaults to 0.

  • references (boolean) - If true, will return Scalar media linked from within the text of the requested nodes, if any. Defaults to false.

  • relation (string) - If not null, will only return nodes related to the requested nodes through the named relationship. Defaults to null, which returns nodes related through any relationship. Other possible values include “annotation”, “path”, “reply” (i.e. comment), and “tag”.

  • start (number) - If specified, indicates the zero-based index of the first result to be returned.

  • results (number) - If specified, indicates the maximum number of results to be returned.
     
  • hidden (boolean) - If true, will return results whose "live" property is set to 0
setBook( scalarURL )noneSets the Scalar book referenced in the specified URI to be the target of future API requests.

Properties

PropertyTypeDescription
modelScalarModelObject containing all nodes for which the client has received data.

This page has paths: