xh Class
These methods apply to the top level of the Xholon application. All of the methods in this class MUST be preceeded by "$wnd.xh." (ex: "$wnd.xh.app();") if they are run from within the Xholon application. The "$wnd." is a GWT requirement. They MUST be preceeded by "xh." (ex: "xh.app();") if they are run using a developer's tool such as Firebug or Developer Tools.
Constructor
xh
()
Item Index
Methods
app
()
IApplication
Get the single app-specific IApplication instance.
Returns:
An instance of a subclass of org.primordion.xholon.app.Application.
Example:
var app = $wnd.xh.app();
attrs
-
node
Log all attribute name/value pairs (JavaScript properties) of a node to the browser console. This is mostly intended for debugging.
Parameters:
-
nodeIXholonAn IXholon node.
Example:
var node = $wnd.xh.root();
$wnd.xh.attrs(node);
avatar
-
newAvatar
Get or set the system Avatar. Note: Avatar extends AbstractAvatar, which extends XholonWithPorts.
Parameters:
-
newAvatarAvatarOptional new system Avatar.
Returns:
An IXholon (Avatar) node, or null.
Example:
const ava = $wnd.xh.avatar();
ava.action("where;look");
$wnd.xh.avatar(newAvatar);
avatarKeyMap
-
keyMap
Get or set the Avatar key map.
Parameters:
-
keyMapStringOptional new key map.
Returns:
Current key map, or null.
Example:
const akmStr = xh.avatarKeyMap();
console.log(akmStr);
var json = xh.avatarKeyMap();
var obj = JSON.parse(json);
obj.X = "build Cat role Licorice";
obj.Y = "build Dog role Fido";
obj["1"] = "take *cat";
var newJson = JSON.stringify(obj);
$wnd.xh.avatarKeyMap(newJson);
css.style
-
content
Set styles for elements in the HTML page.
Parameters:
-
contentStrong
Example:
$wnd.xh.css.style(".d3cpnode circle {stroke-width: 0px;}");
html.popup
-
title -
htmlText -
autoHide -
modal -
left -
top
Generate a popup on the browser HTML page.
Parameters:
-
titleString -
htmlTextString -
autoHideBoolean -
modalBoolean -
leftIntger -
topInteger
Returns:
Example:
$wnd.xh.html.popup("Title", "<div><p>Hello Popup</p></div>");
html.toggle
-
elementId
Toggle the visibility of an existing HTML element, typically a div that starts with "xh".
Parameters:
-
elementIdStringAn HTML element id.
Example:
$wnd.xh.html.toggle("xhgui");
html.urlparam
-
a
Get a URL search param from the browser. For example, if the URL line includes the text "&one=two", then asking for param "one" will return "two".
Parameters:
-
aStringURL param
Returns:
a value, or null
Example:
console.log($wnd.xh.html.urlparam("one")); // "two"
html.xhElements
()
String
Get an array of top-level "xh" element id's.
Returns:
a comma-delimited list (ex: "xhtop,xhgui,xhappspecific,xhconsole,xhtabs,xhchart,xhcanvas,xhgraph,xhsvg,xhimg").
Example:
$wnd.xh.html.xhElements();
isXholonNode
-
obj
Determine if obj is an instance of a Java class that descends from Xholon.java.
Parameters:
-
objObjectAny JS object.
Returns:
true or false
Example:
$wnd.xh.isXholonNode(xh.root()); //returns true
$wnd.xh.isXholonNode(13); //returns false
isXholonNodeCanonical
-
obj
Determine if obj is an instance of a Java class that descends from Xholon.java.
Parameters:
-
objObjectAny JS object.
Returns:
true or false
Example:
$wnd.xh.isXholonNodeCanonical(xh.root()); //returns true
$wnd.xh.isXholonNodeCanonical(13); //returns false
matchGraph
-
graphStr -
subgraphStr -
separator
Match graph
Parameters:
-
graphStrString -
subgraphStrString -
separatorString
Returns:
Example:
// TODO
param
-
pName -
[pValue]
Get or set the value of an application parameter.
Parameters:
-
pNameStringThe name of the parameter.
-
[pValue]String optionalThe value of the parameter.
Returns:
The value of the parameter, or null, or undefined.
Example:
// set the interval between time steps as 200 milliseconds
// show the before and after values in the browser console
console.log($wnd.xh.param("TimeStepInterval"));
$wnd.xh.param("TimeStepInterval", "200");
console.log($wnd.xh.param("TimeStepInterval"));
random
()
Number
replacement for Javascript Math.random(), with a seed
Returns:
a random real number between 0 and 1
Example:
console.log($wnd.xh.random()); // 0.0138649232303234
require
-
scriptName -
[scriptPath]
Require a single named JavaScript library. If the script is located in the Xholon application library, then only the scriptName needs to be provided.
Parameters:
-
scriptNameStringThe name of a script.
-
[scriptPath]String optionalThe URL for the script.
Example:
$wnd.xh.require("d3.v2.min.js");
$wnd.xh.require("three.min.js", "http://threejs.org/build/");
root
()
IXholon
Get the app-specific root of the composite structure hierarchy.
Returns:
An instance of a subclass of org.primordion.xholon.base.Xholon.
Example:
var root = $wnd.xh.root();
seed
-
An
Seed the random number generator
Parameters:
-
AnNumberinteger. example $wnd.xh.seed(5297);
selectTab
-
index
Select a tab in #xhtabs .
Parameters:
-
indexNumberthe XXholon tab index
Returns:
Example:
$wnd.xh.html.selectTab(0); // "out"
$wnd.xh.html.selectTab(1); // "clipboard"
$wnd.xh.html.selectTab(2); // "notes"
service
-
serviceName
Get a Xholon Service.
Parameters:
-
serviceNameStringThe name of a service (ex: "TimelineService").
Returns:
An IXholon node, or null.
Example:
var service = $wnd.xh.service("TimelineService");
console.log(service);
services
()
Display a list of names of services and their activation status, in the out tab.
Example:
$wnd.xh.services();
showLocalStorage
()
Show contents of browser local storage. It prints this to the Xholon GUI out tab.
Returns:
null
Example:
var locstor = $wnd.xh.showLocalStorage();
console.log(locstor);
speechRecognition
-
lang
Set up speech recognition.
Parameters:
-
langString(ex: "en-GB")
Returns:
state
-
controllerState
Set controller state. The example below sets the controller state to CS_STEPPING, which causes the app to move forward one timestep, and then go into CS_PAUSE state.
Parameters:
-
controllerStateNumber5 is currently the only useful value.
Example:
$wnd.xh.state(5);
test
()
Run the Xholon JavaScript API unit tests, using QUnit. The tests are intended to run inside the Furcifer app: http://www.primordion.com/Xholon/gwt/XholonQUnit.html?app=Furcifer&gui=clsc See also the Information page for the Furcifer app (Help > Information).
Example:
$wnd.xh.test();
webRTC
-
id -
key -
debug
Enable external access through a new Avatar, using WebRTC PeerJS. This would typically be used from PeerjsChat.html
Parameters:
-
idStringoptional
-
keyStringpeerjs demo API key, or other
-
debugNumberdebug level (0 - 3)
Returns:
null
Example:
xh.webRTC();
xh.webRTC("Alligator", undefined, 3);
xpath
-
expression -
node
Evaluate an XPath 1.0 expression.
Parameters:
-
expressionStringAn XPath 1.0 String expression (ex: "ancestor::HelloWorldSystem/World");
-
nodeIXholonAn IXholon node.
Returns:
An IXholon node, or null.
Example:
var node = $wnd.xh.root().first(); // get the Hello node
$wnd.xh.xpath("ancestor::HelloWorldSystem/World", node);
xpathExpr
-
descendant -
ancestor
Get an XPath 1.0 compliant expression that uniquely identifies a path from an ancestor node to a descendant node.
Parameters:
-
descendantIXholonA Xholon node that is a descendant of ancestor.
-
ancestorIXholonA Xholon node that is an ancestor of descendant.
Returns:
Example:
console.log(xh.xpathExpr($wnd.xh.root().first(), xh.root())); // "HelloWorldSystem/Hello"
var ancestor = $wnd.xh.root().first().first(); // City
var descendant = ancestor.xpath("School[@roleName='Hilson']");
$wnd.console.log($wnd.xh.xpathExpr(descendant, ancestor)); // "City/School[@roleName='Hilson']"
xport
-
formatName -
node -
[efParams]
Export a node and its subtree to an external format. Because "export" is a JS keyword, we use "xport" instead.
Parameters:
-
formatNameStringThe name of an external format (ex: "MindMap").
-
nodeIXholonAn IXholon node.
-
[efParams]String optionalA JSON-formatted string containing one or more key/value pairs. To determine the possible parameters for a given external format, look at the efParams object in each ef source file.
Example:
var root = $wnd.xh.root();
$wnd.xh.xport("MindMap", root);
$wnd.xh.xport("Yaml", root);
$wnd.xh.xport("_other,Newick", root);
$wnd.xh.xport("_xholon,Xhn", root);
$wnd.xh.xport("_d3,CirclePack", root);
$wnd.xh.xport("Graphviz", root, '{"layout":"neato"}');
xports
()
Array
Get an array of external format names.
Returns:
An array of strings. Example: Csv GraphML Graphviz MindMap Yaml _other,ChapNetwork,ChapTree,Newick _xholon,Cd,Csh,Ih,Xhn _d3,CirclePack
Example:
var root = $wnd.xh.root();
var formatNamesArr = $wnd.xh.xports();
for (var i = 0; i < formatNamesArr.length; i++) {
root.println(formatNamesArr[i]);
}
