Initializer
.ojTree(options)
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
options |
Object |
<optional> |
a map of option-value pairs to set on the component |
- Source:
Example
Initialize the Tree with options:
$( ".selector" ).ojTree( {"selectionMode": "single", "data": [JSON objects]} );
Options
-
contextMenu :string|null
-
Identifies the JET Menu that the component should launch as a context menu on right-click or Shift-F10. If specified, the browser's native context menu will be replaced by the specified JET Menu.
To specify a JET context menu on a DOM element that is not a JET component, see the
ojContextMenu
binding.To make the page semantically accurate from the outset, applications are encouraged to specify the context menu via the standard HTML5 syntax shown in the below example. When the component is initialized, the context menu thus specified will be set on the component.
When defining a contextMenu, ojTree will provide built-in behavior for "edit" style functionality (e.g. cut/copy/paste) if the following format for menu <li> item's is used (no <a> elements are required):
- <li data-oj-command="oj-tree-cut" />
- <li data-oj-command="oj-tree-copy" />
- <li data-oj-command="oj-tree-paste" />
- <li data-oj-command="oj-tree-remove" />
- <li data-oj-command="oj-tree-rename" />
The JET Menu should be initialized before any component using it as a context menu.
- Default Value:
null
- Source:
Examples
Initialize a JET Tree with a context menu:
// via recommended HTML5 syntax: <div id="myTree" contextmenu="myMenu" data-bind="ojComponent: { ... }> // via JET initializer (less preferred) : $( ".selector" ).ojTree({ "contextMenu": "#myContextMenu" ... } });
Get or set the
contextMenu
option for an ojTree after initialization:// getter var menu = $( ".selector" ).ojTree( "option", "contextMenu" ); // setter $( ".selector" ).ojTree( "option", "contextMenu", "#myContextMenu"} );
-
data :Object|Array|string|null
-
Specifies the data source used to populate the tree. Currently supported data sources are a
JsonTreeDataSource
, or json, or html. The general format of thedata
option is one of the following:- data : oj.JsonTreeDataSource
- data : null (or omit) - ojTree will look at the containing <div> and use any existing html <ul> markup found
- data : " json string "
- data : [ array of json objects ]
- data : "<ul><li> ... html markup string </ul>"
- data : { "data" : ... or "ajax" : . . . } // retrieve json or html
"data"
property of thedata
option, specifies that the tree is to be populated from JSON or HTML (local or remote). The"data"
object contains one of two properties:- "data"
- "ajax"
"dataType"
property may also be specified, which can take the value"json"
or"html"
, and indicates what kind of data is being returned in the"data"
or"ajax"
method (default is "json"). When "data" is specified as an object, its "data" property may be specified as a function which receives two arguments: node, and fn. Example: Skeleton outline of a"data"
function:data : { "data" : function(node, fn) { // node - the jQuery wrapped node to be expanded for a lazy load, // or -1 if it is the initial call to load the tree. // fn - a function to call with the JSON to be applied. fn( new_json_node_data ) ; // return the JSON } }
"ajax"
property of the"data"
option allows remote JSON to be retrieved. It may be specified as an object (refer to the jQuery .ajax() settings object). If may also be specified asfalse
or omitted, if no AJAX operations are performed. When specified as an object, it should contain the following two properties:- type
- url
"ajax" : { "type": "GET", "url": "my_url" // some url to the content }
"url"
may also be specified as a function which should return a url string:"ajax" : { "type" : "GET", "url": function (node) { ... return a url string ... } )
- Default Value:
null
- Source:
Examples
Example 1: Skeleton outline of success and error functions
"ajax": { "type":"GET", "url": myurl <-- url to full tree JSON "success" : function(data, status, obj) { // data = the JSON data // status = "success" // obj = the AJAX object. trace("Ajax " + status) ; // return the data, can transform it first if required. // if no return value, the data is used untransformed. }, "error" : function(reason, feedback, obj) { // reason e.g. "parsererror" // feedback.message e.g. "unexpected string" // obj = the AJAX object. trace("Ajax error " + reason + " feedback=" + feedback.message) ; },
Example 2: Load the complete tree from locally defined JSON.
"data" : [ { "title": "Home", "attr": {"id": "home"}, }, { "title": "News", "attr": {"id": "news"} }, { "title": "Blogs", "attr": {"id": "blogs"}, "children": [ { "title": "Today", "attr": {"id": "today"} }, { "title": "Yesterday", "attr": {"id": "yesterday"} } ] } ]
Example 3: Load the complete tree with remotely served JSON.
"data" : { "ajax": { "type":"GET", "url": myurl <-- url to full tree JSON } }
Example 4: Load the complete tree with remotely served JSON via a function.
"data" : { "ajax": { "type":"GET", "url": function() { return (a url) ; } } }
Example 5: Load a partial tree, and retrieve node data when a parent node is expanded and needs to be populated.
"data" : { "ajax": { "type":"GET", "url": function(node) { if (node === -1) { // -1 indicates initial load return (url for for partial json) ; // the tree outline with parent nodes empty. } else { var id = node.attr("id") ; return (a url based on the node id to retrieve just the node children) ; } } } }
Example 6: Transform data received from server before passing to ojTree.
"data" : { "ajax": { "type":"GET", "url": function(node) { . . . }, "success" : function (data) { . . . // transform the received data into node JSON format return (transformed data) ; }, "error" : function () { // ajax call failed. } } }
Example 7: Use own mechanism to load a partial tree and retrieve node data when a parent is expanded.
// Sample outline of a tree. Note that the parent nodes "Node2" and "Node3" have // their "children" property specifed, but no children are actually defined. { "title" : Node1", "attr" : {"id" : "n1"} }, { "title" : Node2", "attr" : {"id" : "n2"}, "children" : [] }, { "title" : Node3", "attr" : {"id" : "n3"}, "children" : [] }, "data" : { "data": function(node, fn) { // node = the node whose children are to be retrieved // fn = the function to call with the retrieved node json if (node === -1) { // initial tree load fn( acquired node json for the tree) ; } else { // node lazy load var id = node.attr("id") ; // get the node id, will be "n2" // or "n3", in this example. fn( acquired node json for the expanded node ) ; } } } }
When an option call is made to reset the data property of a tree, the application does not need to call refresh. -
disabled :boolean
-
Disables the tree if set to
true
.- Default Value:
false
- Source:
Examples
Initialize the tree with the
disabled
option specified:$( ".selector" ).ojTree( { "disabled": true } );
Get or set the
disabled
option, after initialization:// getter var disabled = $( ".selector" ).ojTree( "option", "disabled" ); // setter $( ".selector" ).ojTree( "option", "disabled", true );
-
dnd :Object
-
Specifies whether the user is permitted to reorder the nodes within the same tree using drag and drop. Specify an object with the property "reorder" set to
"enable"
to enable reordering. Setting the"reorder"
property to"disable"
, or omitting the"reorder"
property disables reordering support.- Default Value:
{reorder:'disable'}
- Source:
Example
Example: Enable drag and drop for tree node reordering
dnd : ( "reorder" : "enable" }
-
emptyText :string|null
-
The text to display when there are no data in the Tree. If not specified, default text is extracted from the resource bundle. Specify an empty string if this default behavior is not required.
- Default Value:
"No data"
- Source:
Example
Initialize the tree with text set to 'no data':
$( ".selector" ).ojTree({ "data":data, "emptyText": "no data" });
-
expandParents :boolean
-
Specify true if expanding a node programatically should also expand its parents (i.e all parent nodes down to this node will be expanded).
- Default Value:
false
- Source:
-
icons :boolean
-
Specifies whether node icons are to be displayed. Specify true to display icons, or false to suppress node icons.
- Default Value:
true
- Source:
-
initExpanded :Array|null
-
Specifies whether any nodes should be initially expanded on start-up. Specify an array of node id's, or the string "all" if all parent nodes should be expanded. The value may optionally be specified as an empty array.
- Default Value:
null
- Source:
-
rootAttributes :Object
-
Attributes specified here will be set on the component's root DOM element at creation time. This is particularly useful for components like Dialog that wrap themselves in a new root element at creation time.
The supported attributes are
id
, which overwrites any existing value, andclass
andstyle
, which are appended to the current class and style, if any.Setting this option after component creation has no effect. At that time, the root element already exists, and can be accessed directly via the
widget
method, per the second example below.- Default Value:
null
- Inherited From:
- Source:
Examples
Initialize a JET component, specifying a set of attributes to be set on the component's root DOM element:
// Foo is the component, e.g., Menu, Button, InputText, InputNumber, Select, etc. $( ".selector" ).ojFoo({ "rootAttributes": { "id": "myId", "style": "max-width:100%; color:blue;", "class": "my-class" }});
After initialization,
rootAttributes
should not be used. It is not needed at that time, as attributes of the root DOM element can simply be set directly, usingwidget
:// Foo is the component, e.g., Menu, Button, InputText, InputNumber, Select, etc. $( ".selector" ).ojFoo( "widget" ).css( "height", "100px" ); $( ".selector" ).ojFoo( "widget" ).addClass( "my-class" );
-
selectedParentCollapse :boolean|string
-
Specifies what action is to be taken when a selected node's parent is collapsed. Specify false if nothing is to be done. Specify "selectParent" if the node's closed parent is to be selected, or specify "deselect" if the node is to be deselected.
- Default Value:
false
- Source:
-
selectedParentExpand :boolean
-
Specifies what action is to be taken when a node is programmatically expanded. Specify true if all of the node's closed parents should be opened automatically. If false is specified, the node is selected but will remain invisible if its parents are currently collapsed.
- Default Value:
true
- Source:
-
selection :Array
-
An array of node elements that are currently selected. If the array is modified by an application, the selected node status of the tree is modified to match the array (nodes may be defined as elements, jQuery wrapped nodes, or selectors pointing to the elements that should be selected).
- Default Value:
Array
- Source:
-
selectionMode :string
-
Specifies whether selection is permitted, and whether more than one node can be selected at a time. Values are "single" for single selection, "multiple" to allow multiple concurrent selections, and "none" to inhibit selection.
- Default Value:
"single"
- Source:
-
selectPrevOnDelete :boolean
-
Specifies the action to take when a selected node is deleted. If set to true, its previous sibling (or parent, if no previous siblings) is selected. If false is specified, no action is taken.
- Default Value:
false
- Source:
-
translations :Object
-
A collection of translated resources from the translation bundle, or
null
if this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.If this component has (or inherits) translations, their documentation immediately follows this doc entry.
- Default Value:
- an object containing all resources relevant to the component and all its superclasses, or
null
if none
- an object containing all resources relevant to the component and all its superclasses, or
- Inherited From:
- Source:
Examples
Initialize the component, overriding some translated resources. This syntax leaves the other translations intact at create time, but not if called after create time:
// Foo is InputDate, InputNumber, etc. $( ".selector" ).ojFoo({ "translations": { someKey: "someValue", someOtherKey: "someOtherValue" } });
Get or set the
translations
option, after initialization:// Get one. (Foo is InputDate, InputNumber, etc.) var value = $( ".selector" ).ojFoo( "option", "translations.someResourceKey" ); // Get all. (Foo is InputDate, InputNumber, etc.) var values = $( ".selector" ).ojFoo( "option", "translations" ); // Set one, leaving the others intact. (Foo is InputDate, InputNumber, etc.) $( ".selector" ).ojFoo( "option", "translations.someResourceKey", "someValue" ); // Set many. Any existing resource keys not listed are lost. (Foo is InputDate, InputNumber, etc.) $( ".selector" ).ojFoo( "option", "translations", { someKey: "someValue", someOtherKey: "someOtherValue" } );
-
translations.labelCopy :string
-
Context menu text used for copying a node.
See the translations option for usage examples.
- Default Value:
"Copy"
- Source:
-
translations.labelCreate :string
-
Context menu text used for creating a new node).
See the translations option for usage examples.
- Default Value:
"Create"
- Source:
-
translations.labelCut :string
-
Context menu text used for cutting a node.
See the translations option for usage examples.
- Default Value:
"Cut"
- Source:
-
translations.labelEdit :string
-
Context menu text used for the submenu containing the editing context menu entries.
See the translations option for usage examples.
- Default Value:
"Edit"
- Source:
-
translations.labelMultiSelection :string
-
.
/**Used as the dragged text when multiple nodes have been selected and are being dragged during a reorder operation.
See the translations option for usage examples.
- Default Value:
"Multiple Selection"
- Source:
-
translations.labelNewNode :string
-
Used as node text when a new node has been added to a Tree and no node text has been supplied.
See the translations option for usage examples.
- Default Value:
"New Node"
- Source:
-
translations.labelNoData :string
-
Text shown when a tree contains no nodes.
See the translations option for usage examples.
- Default Value:
"No Data"
- Source:
-
translations.labelPaste :string
-
Context menu text used for pasting a node.
See the translations option for usage examples.
- Default Value:
"Paste"
- Source:
-
translations.labelRemove :string
-
Context menu text used for removing a node.
See the translations option for usage examples.
- Default Value:
"Remove"
- Source:
-
translations.labelRename :string
-
Context menu text used for renaming a node.
See the translations option for usage examples.
- Default Value:
"Rename"
- Source:
-
translations.stateLoading :string
-
Used as node placeholder text when a node is being loaded.
See the translations option for usage examples.
- Default Value:
"Loading..."
- Source:
-
types :Object|null
-
The 'types' option allow nodes to be classified and their appearance and behavior modified. Typical uses are to define a specific icon for a particular node, or to inhibit certain operations on a particular type of folder (e.g. the root node cannot be deleted or moved).
A node type has the following properties:
- "image" - specifies the location of the icon to be used (optional). May also be specified as false to suppress the image.
- "position" - position of sprite in the image in the format "left top", e.g. "-36px -16px". Optional - omit if icon is not contained within a multi-sprite image.
- method name - specify a function or a boolean. Optional. Any node operation method (that is, takes a node as its first argument) can be redefined (e.g. select, expand, collapse, etc). Alternatively, the method can be defined as true or false to permit or inhibit the operation, or a function that returns a boolean value. The default value if omitted is true (i.e. the operation is permitted).
- Default Value:
true
- Source:
Examples
Example 1: Add custom appearance and node behavior.
"types": { "myroot" : { "image" : baseurl + "/img/root.png", "select" : function() { return false; }, "remove" : function() { return false; }, "move" : function() { return false; }, }, "myfolder" : { "image" : baseurl + "/img/folder.png" }, "myleaf" : { "image" : "baseurl + "/img/leaf.png" }, "default" : { <-- optional redefinition of the default behavior "image" : "baseurl + "/img/leaf.png", "remove" : function() { return false; } } } }
User-defined types are specified as an attribute of the node. The default node type attribute is "type", but this could be changed if desired using the "attr" property. Thus, for the node types in example 1 above, the node type attribute values in the node definitions could be set as in example 2:Example 2: Using node types in the tree JSON.
[ { "title": "Root", "attr": { "id": "root", "type": "myroot" <--- node type }, "children": [ { "title": "Home", "attr": {"id": "home", "type": "myleaf"} <--- node type }, { "title": "News", "attr": { "id": "news", "type": "myleaf" <--- node type } }, { "title": "Blogs", "attr": { "id": "blogs", "type": "myfolder" <--- node type }, "children": [ { "title": "Today", "attr": { "id": "today", "type": "myleaf" } }, { <--- default node type "title": "Yesterday", "attr": {"id": "yesterday"} } ] } ] } ]
As described above, the node type attribute used on the corresponding tree <li> element defaults to "type", but this can be redefined using the attr property as in the following example:Example 2: Using node types in the tree JSON.
"types": { "attr" : "mytype", <--- node type attribute is now "mytype" "types": { "myroot" : { "image" : . . . . . . } }
Events
-
before
-
Triggered prior to an event.
The following events can be vetoed during
before
event processing by returning false from thebefore
event handler (omitting a return value or returningtrue
permits the event processing to continue):collapse
,expand
,hover
,select
,remove
,rename
.- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description func
string the event causing this before
event to be triggered.item
Object the node that is the subject of the event Examples
Initialize the Tree with the
before
callback specified:$( ".selector" ).ojTree({ "before": function(event, ui) { console.log("Before event " + ui.func); } });
Bind an event listener to the
ojbefore
event:$( ".selector" ).on( "ojbefore", function( event, ui ) { console.log("Before event " + ui.func); });
-
collapse
-
Triggered when a tree node is collapsed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been collapsed Examples
Initialize the Tree with the
collapse
callback specified:$( ".selector" ).ojTree({ "collapse": function( event, ui ) {. . .} });
Bind an event listener to the
ojcollapse
event:$( ".selector" ).on( "ojcollapse", function(event, ui) {. . .} );
-
collapseAll
-
Triggered when all nodes of a parent node, or the complete tree, have been collapsed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node(s) that were collapsed. targ
Object the node that was targeted for collapseAll, or -1 if the complete tree is collapsed. Examples
Initialize the Tree with the
collapseAll
callback specified:$( ".selector" ).ojTree({ "collapseAll": function( event, ui ) {. . .} });
Bind an event listener to the
ojcollapseall
event:$( ".selector" ).on( "ojcollapseall", function( event, ui ) {. . .} );
-
create
-
Triggered when a tree node has been created and added to the tree.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been created Examples
Initialize the Tree with the
create
callback specified:$( ".selector" ).ojTree({ "create": function( event, ui ) {. . .} });
Bind an event listener to the
ojcreate
event:$( ".selector" ).on( "ojcreate", function(event, ui) {. . .} );
-
cut
-
Triggered when a tree node has been cut from the tree via the context menu.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that was cut Examples
Initialize the Tree with the
cut
callback specified:$( ".selector" ).ojTree({ "cut": function( event, ui ) {. . .} });
Bind an event listener to the
ojcut
event:$( ".selector" ).on( "ojcut", function( event, ui ) {. . .} );
-
dehover
-
Triggered when a tree node is no longer hovered over.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that is no longer hovered over Examples
Initialize the Tree with the
dehover
callback specified:$( ".selector" ).ojTree({ "dehover": function( event, ui ) {. . .} });
Bind an event listener to the
ojdehover
event:$( ".selector" ).on( "ojdehover", function( event, ui ) {. . .} );
-
destroy
-
Triggered when a tree is destroyed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Examples
Initialize the Tree with the
destroy
callback specified:$( ".selector" ).ojTree({ "destroy": function( event, ui ) {} });
Bind an event listener to the
ojdestroy
event:$( ".selector" ).on( "ojdestroy", function( event, ui ) {} );
-
expand
-
Triggered when a tree node is expanded.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been expanded Examples
Initialize the Tree with the
expand
callback specified:$( ".selector" ).ojTree({ "expand": function( event, ui ) {. . .} });
Bind an event listener to the
ojexpand
event:$( ".selector" ).on( "ojexpand", function( event, ui ) {. . .} );
-
expandAll
-
Triggered when all nodes of a parent node, or the complete tree, have been expanded.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node(s) that were expanded. targ
Object the node that was targeted for expandAll, or -1 if the complete tree is collapsed. Examples
Initialize the Tree with the
expandAll
callback specified:$( ".selector" ).ojTree({ "expandAll": function( event, ui ) {. . .} });
Bind an event listener to the
ojexpandall
event:$( ".selector" ).on( "ojexpandall", function( event, ui ) {. . .} );
-
hover
-
Triggered when a tree node is hovered over.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that is hovered over Examples
Initialize the Tree with the
hover
callback specified:$( ".selector" ).ojTree({ "hover": function( event, ui ) {. . .} });
Bind an event listener to the
ojhover
event:$( ".selector" ).on( "ojhover", function( event, ui ) {. . .} );
-
loaded
-
Triggered when a tree has been loaded and the node data has been applied.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Examples
Initialize the Tree with the
loaded
callback specified:$( ".selector" ).ojTree({ "loaded": function( event, ui ) {} });
Bind an event listener to the
ojloaded
event:$( ".selector" ).on( "ojloaded", function( event, ui ) {} );
-
move
-
Triggered when a tree node has been moved within the tree.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that was moved position
string the moved node's new position relative to the reference node. Can be "before", "after", or "inside". reference
Object the reference node that ui.position refers to. Examples
Initialize the Tree with the
move
callback specified:$( ".selector" ).ojTree({ "move": function(event, ui) {. . .} });
Bind an event listener to the
ojmove
event:$( ".selector" ).on( "ojmove", function(event, ui) {. . .} );
-
optionChange
-
Triggered whenever a supported component option changes, whether due to user interaction or programmatic intervention. If the new value is the same as the previous value, no event will be fired. Currently there is one supported option,
"selection"
, which reflects the current selection status of the Tree. Additional options may be supported in the future, so listeners should verify which option is changing before taking any action.- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description option
string the name of the option that is changing previousValue
Array the previous value of the option value
Array the current value of the option optionMetadata
Object information about the option that is changing Properties
Name Type Description writeback
string "shouldWrite"
or"shouldNotWrite"
. For use by the JET writeback mechanism. -
paste
-
Triggered when a tree node has been pasted into the tree via the context menu.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that was pasted Examples
Initialize the Tree with the
paste
callback specified:$( ".selector" ).ojTree({ "paste": function( event, ui ) {. . .} });
Bind an event listener to the
ojpaste
event:$( ".selector" ).on( "ojpaste", function( event, ui ) {. . .} );
-
refresh
-
Triggered when a tree node, or the complete tree, has been refreshed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been refreshed, or -1 if the whole tree has been refreshed. Examples
Initialize the Tree with the
refresh
callback specified:$( ".selector" ).ojTree({ "refresh": function( event, ui ) {. . .} });
Bind an event listener to the
ojrefresh
event:$( ".selector" ).on( "ojrefresh", function( event, ui ) {. . .} );
-
remove
-
Triggered when a tree node has been removed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been removed. parent
Object the parent of the node that was removed. prev
Object the previous sibling, or if ui.item is the first child of its parent, the parent node. Examples
Initialize the Tree with the
remove
callback specified:$( ".selector" ).ojTree({ "remove": function( event, ui ) {. . .} });
Bind an event listener to the
ojremove
event:$( ".selector" ).on( "ojremove", function( event, ui ) {. . .} );
-
rename
-
Triggered when a tree node has been renamed.
- Source:
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Description item
Object the node that has been renamed title
string the new node text title. prevTitle
string the node title prior to the rename. Examples
Initialize the Tree with the
rename
callback specified:$( ".selector" ).ojTree({ "rename": function( event, ui ) {. . .} });
Bind an event listener to the
ojrename
event:$( ".selector" ).on( "ojrename", function( event, ui ) {. . .} );
Methods
-
collapse(node, skipAnim)
-
Collapses an expanded node, so that its children are not visible. Triggers a "collapse" event.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be collapsed. skipAnim
boolean <optional>
Set to true to suppress node collapse animation (if a non-zero duration is defined or defaulted). Default is false. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
collapseAll(node, anim)
-
Collapses a node and all its descendants. Triggers a "collapseall" event.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element whose descendants are to be collapsed. If omitted , or set to -1, all nodes in the tree are collapsed. anim
boolean <optional>
Set to true (or omit) if all nodes are to be collapsed with animation (if a non-zero duration is defined or defaulted). Default is true. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
create(refnode, position, data) → {Object}
-
Creates a new node and adds it to the tree. Triggers a "create" event.
Parameters:
Name Type Description refnode
HTMLElement | Object | string specifies the node that the new node will be placed in, or next to, depending on the "position" argument. Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. If there is no reference node (because the tree is empty), specify null or undefined (or -1) may be specified. position
string | number specifies the position of the newly created node in relation to the "refnode" specified by the first argument. Can be a string : "before", "after", "inside", "first",, "last", or a zero-based index to position the new node at a specific point among the childfren of "refnode". data
Object An object literal containing data to create a new node. The object properties are the same as for defining a JSON node:
"attr" - an object of attribute name/value pairs (at least an "id" property should be defined).
"title" - a string used for the visible text of the node.
var new Node = { "title" : "My Title", "attr" : { "id": "myid" } };
- Source:
Returns:
Returns the jQuery wrapped node created from the 'data' argument.- Type
- Object
-
dehover()
-
Removes the "hover" state of the currently hovered (i.e. active) node. Triggers a "dehover" event.
- Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
deselect(node)
-
Deselects a node. Triggers an "optionChange" event for options property "selection".
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be deselected. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
deselectAll(context)
-
Deselects all selected nodes. If optional argument "context" is specified, only the selected nodes within that context will be selected. Triggers an "optionChange" event for options property "selection".
Parameters:
Name Type Argument Description context
HTMLElement | Object | string <optional>
Can be a DOM element, a jQuery wrapped node, or a selector pointing to an element within the tree. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
destroy()
-
Removes the Tree from the DOM. If the tree was constructed from original user <ul> markup defined in the Tree's containing <div>, this markup is reinstated.
This method does not accept any arguments.
- Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining.Example
Invoke the
destroy
method:$( ".selector" ).ojTree( "destroy" );
-
expand(node, skipAnim)
-
Expands a collapsed parent node, so that its children are visible. Triggers an "expand" event.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be expanded. skipAnim
boolean <optional>
Set to true to suppress node expansion animation (if a non-zero duration is defined or defaulted). Default is false. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
expandAll(node, anim)
-
Expands a node and all its descendants. Triggers an "expandall" event.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element whose descendants are to be expanded. If omitted , or set to -1, all nodes in the tree are expanded. anim
boolean <optional>
Set to true (or omit) if all nodes are to expanded with animation (if a non-zero duration is defined or defaulted). Default is true. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
expanded(nodes, skipAnim) → {Object|null}
-
May be used as a getter of setter. If no argument is supplied, the method returns an array of nodes currently expanded. (An empty array implies that no nodes are expanded.) If an array of nodes is supplied as an argument, the specified nodes are expanded.
Parameters:
Name Type Argument Description nodes
Array <optional>
Omit to use as a getter, or specify an array of nodes to be expanded. Nodes may be defined as elements, id strings, jQuery wrapped nodes, or selectors pointing to the elements to be expanded. skipAnim
boolean <optional>
Set to true to suppress node expansion animation (if a non-zero duration is defined or defaulted). Default is false. - Source:
Returns:
A jQuery wrapped array of nodes if used as a getter, else null if used as a setter.- Type
- Object | null
-
getChildren(node) → {Object|null}
-
Returns the children of the node specified.
Parameters:
Name Type Description node
HTMLElement | Object | string | number Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. May also be specified as -1 or omitted to indicate the tree, in which case the top level children of the tree are returned. - Source:
Returns:
The jQuery wrapped array of child nodes, or null if there are no children.- Type
- Object | null
-
getNextSibling(node) → {Object|null}
-
Returns the next sibling of the node specified.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
The jQuery wrapped sibling node, or null if there is no next sibling.- Type
- Object | null
-
getNodeBySubId(locator) → {Element|null}
-
Returns the subcomponent node element represented by the locator object subId property.
Parameters:
Name Type Description locator
Object An Object containing at minimum a "subId" property whose value is a string. The general format of a subId string is: "oj-tree-node['node id']['request']"
Request Description "icon" Returns the <ins> element for the node icon. "disclosure" Returns the <ins> element for the disclosure (expand/collapse) icon of a parent node. "link" Returns the <a> element for the node. "title" Returns the <span> element for the node's title text. - Source:
Returns:
the subcomponent element located by the subId string passed in locator, or null if not found.- Type
- Element | null
-
getParent(node) → {Object|null}
-
Returns the parent node of the node specified.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
The jQuery wrapped parent node, or null if node is a top level node.- Type
- Object | null
-
getPath(node, idMode) → {Array|boolean}
-
Returns the full path to a node, either as an array of ID's or node names, depending on the value of the "idMode" argument.
e.g. Given a node with Id 'Node1' at the root level, with a child 'Node2' which has a child 'Node3', then:
$tree.ojTree("getPath", "#Node3", true) ;
will return:
["Node1", "Node2", "Node3"]
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. idMode
boolean <optional>
Set to true (or omit) to return ID's from the node attribute "id"), or false to return the names (i.e. text titles). Default is true. - Source:
Returns:
An array of node ID's or names.- Type
- Array | boolean
-
getPrevSibling(node) → {Object|null}
-
Returns the previous sibling of the node specified.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
The jQuery wrapped sibling node, or null if there is no previous sibling.- Type
- Object | null
-
getRoot() → {Object}
-
Returns the jQuery wrapped top outer <ul> element of the tree.
- Source:
Returns:
The jQuery wrapped <ul> element of the tree.- Type
- Object
-
getText(node) → {string|boolean}
-
Returns the title of the specified node
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
The text string title of the node.- Type
- string | boolean
-
getType() → {string|boolean}
-
Returns the user classified node type applied to the node in the "types" option.
- Source:
Returns:
The node's type. If no types have been defined in the tree options, false is returned.- Type
- string | boolean
-
hover(node)
-
Sets the specifed node as the current node of interest (e.g. a mouse-over). Triggers a "hover" event.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
isCollapsed(node) → {boolean}
-
Returns true if the node is collapsed, else false.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
true if the node is collapsed, else false.- Type
- boolean
-
isExpanded(node) → {boolean}
-
Returns true if the node is expanded, else false.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
true if the node is expanded, else false.- Type
- boolean
-
isLeaf(node) → {boolean}
-
Returns true if the node is a leaf node (that is, it has no children), else false.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
true if the node is a leaf node, else false.- Type
- boolean
-
isSelected(node) → {boolean}
-
Returns true if the node is selected, else false.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
true if the node is selected, else false.- Type
- boolean
-
move(node, refnode, position, iscopy)
-
Moves (or copies) a node within a tree, or from one tree to a different tree.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string | number The node to be moved. Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. refnode
HTMLElement | Object | string | number The reference node for the move (see "position" argument below). Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. If the receiving tree ie empty and there can be no reference node, null or undefined (or -1) may be specified. position
string | number The position of the moved node relative to the reference node refnode. Can be "before", "after", "inside", "first", "last", or the zero-based index to position the node at a specific point among the reference node's current children. iscopy
boolean <optional>
Omit or specify false for a move operation, or true for a copy. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
option(optionName, value) → {Object|undefined}
-
This method has several overloads, which get and set component options and their fields. The functionality is unchanged from that provided by JQUI. See the examples for details on each overload.
Parameters:
Name Type Argument Description optionName
string | Object <optional>
the option name (string, first two overloads), or the map (Object, last overload). Omitted in the third overload. value
Object <optional>
a value to set for the option. Second overload only. - Inherited From:
- Source:
Returns:
The getter overloads return the retrieved value(s). When called via the public jQuery syntax, the setter overloads return the object on which they were called, to facilitate method chaining.- Type
- Object | undefined
Examples
First overload: get one option:
This overload accepts a (possibly dot-separated)
optionName
param as a string, and returns the current value of that option.var isDisabled = $( ".selector" ).ojFoo( "option", "disabled" ); // Foo is Button, Menu, etc. // For object-valued options, dot notation can be used to get the value of a field or nested field. var startIcon = $( ".selector" ).ojButton( "option", "icons.start" ); // icons is object with "start" field
Second overload: set one option:
This overload accepts two params: a (possibly dot-separated)
optionName
string, and a new value to which that option will be set.$( ".selector" ).ojFoo( "option", "disabled", true ); // Foo is Button, Menu, etc. // For object-valued options, dot notation can be used to set the value // of a field or nested field, without altering the rest of the object. $( ".selector" ).ojButton( "option", "icons.start", myStartIcon ); // icons is object with "start" field
Third overload: get all options:
This overload accepts no params, and returns a map of key/value pairs representing all the component options and their values.
var options = $( ".selector" ).ojFoo( "option" ); // Foo is Button, Menu, etc.
Fourth overload: set one or more options:
This overload accepts a single map of option-value pairs to set on the component. Unlike the first two overloads, dot notation cannot be used.
$( ".selector" ).ojFoo( "option", { disabled: true, bar: 42 } ); // Foo is Button, Menu, etc.
-
refresh(node)
-
Refreshes the tree or a node.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string | number <optional>
If -1 is specified (or the argument is omitted), the whole tree is refreshed. Alternatively, a specific node to be refreshed can be supplied. Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
remove(node) → {Object|boolean}
-
Removes a node. Triggers a "remove" event.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. - Source:
Returns:
The jQuery wrapped node used as an argument.- Type
- Object | boolean
-
rename(node, text)
-
Renames a node title.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. text
string <optional>
The new text string. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
select(node)
-
Selects a node. Triggers an "optionChange event for options property "selection".
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be selected. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
setType(node, str) → {boolean}
-
Sets the "type" attribute of the node using a type defined in the "types" option.
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element. str
string The type. - Source:
Returns:
true if the change was successful, else false.- Type
- boolean
-
toggleExpand(node, skipAnim)
-
Expands a node if collapsed, or collapses a node if expanded. Triggers an "expand" or "collapse" event.
Parameters:
Name Type Argument Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be expanded/collapsed. skipAnim
boolean <optional>
Set to true to suppress node expand/collapse animation (if a non-zero duration is defined or defaulted). Default is false. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
toggleSelect(node)
-
Selects a node if deselected, or deselects a node if selected. Triggers an "optionChange" event for options property "selection".
Parameters:
Name Type Description node
HTMLElement | Object | string Can be a DOM element, a jQuery wrapped node, or a selector pointing to the element to be expanded/collapsed. - Source:
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining.
Non-public Methods
Note: Extending JET components is not currently supported. Thus, non-public methods are for internal use only.
-
<protected> _AfterCreate()
-
This method is called after _ComponentCreate, but before the
create
event is fired. The JET base component does tasks here that must happen after the component (subclass) has created itself in its override of _ComponentCreate. Notably, the base component handles the rootAttributes and contextMenu options here, since those options operate on the component root node, which for some components is created in their override of _ComponentCreate.Subclasses should override this method only if they have tasks that must happen after a superclass's implementation of this method, e.g. tasks that must happen after the context menu is set on the component.
Overrides of this method should call
this._super
first.- Inherited From:
- Source:
-
<protected> _AfterCreateEvent()
-
This method is called after the
create
event is fired. Components usually should not override this method, as it is rarely correct to wait until after thecreate
event to perform a create-time task.An example of a correct usage of this method is Dialog's auto-open behavior, which needs to happen after the
create
event.Only behaviors (like Dialog auto-open behavior) should occur in this method. Component initialization must occur earlier, before the
create
event is fired, so thatcreate
listeners see a fully inited component.Overrides of this method should call
this._super
first.Do not confuse this method with the _AfterCreate method, which is more commonly used.
- Inherited From:
- Source:
-
<protected> _CompareOptionValues(option, value1, value2) → {boolean}
-
Compares 2 option values for equality and returns true if they are equal; false otherwise.
Parameters:
Name Type Description option
String the name of the option value1
Object first value value2
Object another value - Inherited From:
- Source:
Returns:
- Type
- boolean
-
<protected> _ComponentCreate()
-
All component create-time initialization lives in this method, except the logic that specifically needs to live in _InitOptions, _AfterCreate, or _AfterCreateEvent, per the documentation for those methods. All DOM creation must happen here, since the intent of _AfterCreate, which is called next, is to contain superclass logic that must run after that DOM is created.
Overrides of this method should call
this._super
first.Summary of create-time methods that components can override, in the order that they are called:
- _InitOptions
- _ComponentCreate (this method)
- _AfterCreate
- (The
create
event is fired here.) - _AfterCreateEvent
For all of these methods, the contract is that overrides must call
this._super
first, so e.g., the_ComponentCreate
entry meansbaseComponent._ComponentCreate
, then_ComponentCreate
in any intermediate subclasses, then_ComponentCreate
in the leaf subclass.- Inherited From:
- Source:
-
<protected> _create()
-
This method is final in JET. Components should instead override one or more of the overridable create-time methods listed in _ComponentCreate.
- Inherited From:
- Source:
-
<protected> _getCreateOptions()
-
This method is not used in JET. Components should instead override _InitOptions.
- Inherited From:
- Source:
-
<protected> _GetReadingDirection() → {string}
-
Determines whether the component is LTR or RTL.
Component responsibilities:
- All components must determine directionality exclusively by calling this protected superclass method. (So that any future updates to the logic can be made in this one place.)
- Components that need to know the directionality must call this method at create-time
and from
refresh()
, and cache the value. - Components should not call this at other times, and should instead use the cached value. (This avoids constant DOM queries, and avoids any future issues with component reparenting (i.e. popups) if support for directional islands is added.)
App responsibilities:
- The app specifies directionality by setting the HTML
"dir"
attribute on the<html>
node. When omitted, the default is"ltr"
. (Per-component directionality / directional islands are not currently supported due to inadequate CSS support.) - As with any DOM change, the app must
refresh()
the component if the directionality changes dynamically. (This provides a hook for component housekeeping, and allows caching.)
- Default Value:
"ltr"
- Inherited From:
- Source:
Returns:
the reading direction, either"ltr"
or"rtl"
- Type
- string
-
<protected> _GetSavedAttributes(element) → {Object|null}
-
Gets the saved attributes for the provided element.
If you don't override _SaveAttributes and _RestoreAttributes, then this will return null.
If you override _SaveAttributes to call _SaveAllAttributes, then this will return all the attributes. If you override _SaveAttributes/_RestoreAttributes to do your own thing, then you may also have to override _GetSavedAttributes to return whatever you saved if you need access to the saved attributes.
Parameters:
Name Type Description element
Object jQuery selection, should be a single entry - Inherited From:
- Source:
Returns:
savedAttributes - attributes that were saved for this element in _SaveAttributes, or null if none were saved.- Type
- Object | null
-
<protected> _init()
-
JET components should almost never implement this JQUI method. Please consult an architect if you believe you have an exception. Reasons:
- This method is called at create time, after the
create
event is fired. It is rare for that to be the appropriate time to perform a create-time task. For those rare cases, we have the _AfterCreateEvent method, which is preferred over this method since it is called only at that time, not also at re-init time (see next). - This method is also called at "re-init" time, i.e. when the initializer is called after the component has already been created. JET has not yet identified any desired semantics for re-initing a component.
- Inherited From:
- Source:
- This method is called at create time, after the
-
<protected> _InitOptions(originalDefaults, constructorOptions)
-
This method is called before _ComponentCreate, at which point the component has not yet been rendered. Component options should be initialized in this method, so that their final values are in place when _ComponentCreate is called.
This includes getting option values from the DOM, where applicable, and coercing option values (however derived) to their appropriate data type if needed.
No work other than setting options should be done in this method. In particular, nothing should be set on the DOM until _ComponentCreate, e.g. setting the
disabled
DOM attribute from thedisabled
option.A given option (like
disabled
) appears in theconstructorOptions
param iff the app set it in the constructor:- If it appears in
constructorOptions
, it should win over what's in the DOM (e.g.disabled
DOM attribute). If for some reason you need to tweak the value that the app set, then enable writeback when doing so:this.option('foo', bar, {'_context': {writeback: true, internalSet: true}})
. - If it doesn't appear in
constructorOptions
, then that option definitely is not bound, so writeback is not needed. So if you need to set the option (e.g. from a DOM attribute), usethis.option('foo', bar, {'_context': {internalSet: true}})
.
Overrides of this method should call
this._super
first.Parameters:
Name Type Argument Description originalDefaults
Object original default options defined on the component and its ancestors constructorOptions
Object <nullable>
options passed into the widget constructor - Inherited From:
- Source:
- If it appears in
-
<protected> _IsEffectivelyDisabled() → {boolean}
-
Determines whether this component is effectively disabled, i.e. it has its 'disabled' attribute set to true or it has been disabled by its ancestor component.
- Inherited From:
- Source:
Returns:
true if the component has been effectively disabled, false otherwise- Type
- boolean
-
<protected> _NotifyAttached()
-
Notifies the component that its subtree has been connected to the document programmatically after the component has been created.
- Inherited From:
- Source:
-
<protected> _NotifyContextMenuGesture(menu, event, eventType)
-
When the contextMenu option is set, this method is called when the user invokes the context menu via the default gestures: right-click, Press & Hold, and Shift-F10. Components should not call this method directly.
The default implementation simply calls this._OpenContextMenu(event, eventType). Overrides of this method should call that same method, perhaps with additional params, not menu.open().
This method may be overridden by components needing to do things like the following:
- Customize the launcher or position passed to _OpenContextMenu(). See that method for guidance on these customizations.
- Customize the menu contents. E.g. some components need to enable/disable built-in commands like Cut and Paste, based on state at launch time.
- Bail out in some cases. E.g. components with UX approval to use PressHoldRelease rather than Press & Hold can override this method
to say
if (eventType !== "touch") this._OpenContextMenu(event, eventType);
. When those components detect the alternate context menu gesture (e.g. PressHoldRelease), that separate listener should call this._OpenContextMenu(), not this method (_NotifyContextMenuGesture()
), and not menu.open().
Components needing to do per-launch setup like the above tasks should do so in an override of this method, not in a beforeOpen listener or an _OpenContextMenu() override. This is discussed more fully here.
Parameters:
Name Type Description menu
Object The JET Menu to open as a context menu. Always non- null
.event
Event What triggered the menu launch. Always non- null
.eventType
string "mouse", "touch", or "keyboard". Never null
.- Inherited From:
- Source:
-
<protected> _NotifyDetached()
-
Notifies the component that its subtree has been removed from the document programmatically after the component has been created.
- Inherited From:
- Source:
-
<protected> _NotifyHidden()
-
Notifies the component that its subtree has been made hidden programmatically after the component has been created.
- Inherited From:
- Source:
-
<protected> _NotifyShown()
-
Notifies the component that its subtree has been made visible programmatically after the component has been created.
- Inherited From:
- Source:
-
<protected> _OpenContextMenu(event, eventType, openOptions, submenuOpenOptions, shallow)
-
The only correct way for a component to open its context menu is by calling this method, not by calling Menu.open() or _NotifyContextMenuGesture(). This method should be called in two cases:
- This method is called by _NotifyContextMenuGesture() and its overrides. That method is called when the baseComponent detects the default context menu gestures: right-click, Press & Hold, and Shift-F10.
- Components with UX-approved support for alternate context menu gestures like PressHoldRelease should call this method directly when those gestures are detected.
Components needing to customize how the context menu is launched, or do any per-launch setup, should do so in the caller of this method, (which is one of the two callers listed above), often by customizing the params passed to this method (
_OpenContextMenu
) per the guidance below. This setup should not be done in the following ways:- Components should not perform setup in a beforeOpen listener, as this can cause a race
condition where behavior depends on who got their listener registered first: the component or the app. The only correct component use
of a
beforeOpen
listener is when there's a need to detect whether something else launched the menu. - Components should not override this method (
_OpenContextMenu
), as this method is final. Instead, customize the params that are passed to it.
Guidance on setting OpenOptions fields:
Launcher:
Depending on individual component needs, any focusable element within the component can be the appropriate launcher for this launch.
Browser focus returns to the launcher on menu dismissal, so the launcher must at least be focusable. Typically a tabbable (not just focusable) element is safer, since it just focuses something the user could have focused on their own.
By default (i.e. if
openOptions
is not passed, or if it lacks alauncher
field), the component init node is used as the launcher for this launch. If that is not focusable or is suboptimal for a given component, that component should pass something else. E.g. components with a "roving tabstop" (like Toolbar) should typically choose the current tabstop as their launcher.The :focusable and :tabbable selectors may come in handy for choosing a launcher, e.g. something like
this.widget().find(".my-class:tabbable").first()
.Position:
By default, this method applies positioning that differs from Menu's default in the following ways: (The specific settings are subject to change.)
- For mouse and touch events, the menu is positioned relative to the event, not the launcher.
- For touch events,
"my"
is set to"start>40 center"
, to avoid having the context menu obscured by the user's finger.
Usually, if
position
needs to be customized at all, the only thing that needs changing is its"of"
field, and only for keyboard launches (since mouse/touch launches should almost certainly keep the default"event"
positioning). This situation arises anytime the element relative to which the menu should be positioned for keyboard launches is different than thelauncher
element (the element to which focus should be returned upon dismissal). For this case,{ "position": {"of": eventType==="keyboard" ? someElement : "event"} }
can be passed as theopenOptions
param.Be careful not to clobber useful defaults by specifying too much. E.g. if you only want to customize
"of"
, don't pass other fields like"my"
, since your value will be used for all modalities (mouse, touch, keyboard), replacing the modality-specific defaults that are usually correct. Likewise, don't forget theeventType==="keyboard"
check if you only want to customize"of"
for keyboard launches.InitialFocus:
This method forces initialFocus to
"menu"
for this launch, so the caller needn't specify it.Parameters:
Name Type Argument Description event
Event What triggered the context menu launch. Must be non- null
.eventType
string "mouse", "touch", or "keyboard". Must be non- null
. Passed explicitly since caller knows what it's listening for, and since events likecontextmenu
andclick
can be generated by various input modalities, making it potentially error-prone for this method to determine how they were generated.openOptions
Object <optional>
Options to merge with this method's defaults, which are discussed above. The result will be passed to Menu.open(). May be null
or omitted. See also theshallow
param.submenuOpenOptions
Object <optional>
Options to be passed through to Menu.open(). May be null
or omitted.shallow
boolean <optional>
Whether to perform a deep or shallow merge of openOptions
with this method's default value. The default and most commonly correct / useful value isfalse
.- If
true
, a shallow merge is performed, meaning that the caller'sposition
object, if passed, will completely replace this method's defaultposition
object. - If
false
or omitted, a deep merge is performed. For example, if the caller wishes to tweakposition.of
while keeping this method's defaults forposition.my
,position.at
, etc., it can pass{"of": anOfValue}
as theposition
value.
The
shallow
param is n/a forsubmenuOpenOptions
, since this method doesn't apply any defaults to that. (It's a direct pass-through.)- Inherited From:
- Source:
-
<protected> _RestoreAllAttributes()
-
Restores all the element's attributes which were saved in _SaveAllAttributes. This method is final in JET.
If a subclass wants to save/restore all attributes on create/destroy, then the subclass can override _SaveAttributes and call _SaveAllAttributes and also override _RestoreAttributes and call _RestoreAllAttributes.
- Inherited From:
- Source:
-
<protected> _RestoreAttributes()
-
Restore the attributes saved in _SaveAttributes.
_SaveAttributes is called during _create. And _RestoreAttributes is called during _destroy.
This base class default implementation does nothing.
We also have _SaveAllAttributes and _RestoreAllAttributes methods that save and restore all the attributes on an element. Component subclasses can opt into these _SaveAllAttributes/_RestoreAllAttributes implementations by overriding _SaveAttributes and _RestoreAttributes to call _SaveAllAttributes/_RestoreAllAttributes. If the subclass wants a different implementation (like save only the 'class' attribute), it can provide the implementation itself in _SaveAttributes/_GetSavedAttributes/_RestoreAttributes.
- Inherited From:
- Source:
-
<protected> _SaveAllAttributes(element)
-
Saves all the element's attributes within an internal variable. _RestoreAllAttributes will restore the attributes from this internal variable.
This method is final in JET. Subclasses can override _RestoreAttributes and call _RestoreAllAttributes.
The JSON variable will be held as:
[ { "element" : element[i], "attributes" : { attributes[m]["name"] : {"attr": attributes[m]["value"], "prop": $(element[i]).prop(attributes[m]["name"]) } } ]
Parameters:
Name Type Description element
Object jQuery selection to save attributes for - Inherited From:
- Source:
-
<protected> _SaveAttributes(element)
-
Saves the element's attributes. This is called during _create. _RestoreAttributes will restore all these attributes and is called during _destroy.
This base class default implementation does nothing.
We also have _SaveAllAttributes and _RestoreAllAttributes methods that save and restore all the attributes on an element. Component subclasses can opt into these _SaveAllAttributes/_RestoreAllAttributes implementations by overriding _SaveAttributes and _RestoreAttributes to call _SaveAllAttributes/_RestoreAllAttributes. If the subclass wants a different implementation (like save only the 'class' attribute), it can provide the implementation itself in _SaveAttributes/_RestoreAttributes.
Parameters:
Name Type Description element
Object jQuery selection to save attributes for - Inherited From:
- Source:
-
<protected> _SetRootAttributes()
-
Reads the
rootAttributes
option, and sets the root attributes on the component's root DOM element. See rootAttributes for the set of supported attributes and how they are handled.- Inherited From:
- Source:
Throws:
if unsupported attributes are supplied. -
<protected> _UnregisterChildNode()
-
Remove all listener references that were attached to the element which includes _activeable, _focusable and hoverable.
- Inherited From:
- Source: