Skip to content

Item

Defined in: core/items/item.ts:84

An Item is rendered from a #core/Source Source and represents an object that is used as an item on the stage. Multiple items may be linked to a single source and any changes made to the source would affect all linked items.

Implements: #core/IItemLayout Core/IItemLayout

var xjs = require('xjs');
var Scene = xjs.Scene.getById(1);
Scene.getItems().then(function(items) {
if (items.length === 0) return;
// There's a valid item, let's use that
var item = items[items.length - 1];
return item.setKeepAspectRatio(true);
}).then(function(item) {
// Do something else here
});

All methods marked as Chainable resolve with the original Item instance. This allows you to perform sequential operations correctly:

var xjs = require('xjs');
var Source = xjs.Source;
// an item that sets its own properties on load
xjs.ready()
.then(Source.getCurrentSource)
.then(function(source) {
return source.getItemList()
}).then(function(items) {
return items[0].setEnhancedResizeEnabled(true)
}).then(function(items) {
return items[0].setPositionLocked(true)
}).then(function(items) {
//set more properties here
})
  • IItemLayout
  • ISource

new Item(props?): Item

Defined in: core/items/item.ts:88

Item

Source.constructor

bringForward: () => Promise<Item>

Defined in: core/items/item.ts:617

See: #core/IItemLayout#bringForward bringForward

Promise<Item>

IItemLayout.bringForward


bringToFront: () => Promise<Item>

Defined in: core/items/item.ts:622

See: #core/IItemLayout#bringToFront bringToFront

Promise<Item>

IItemLayout.bringToFront


getCanvasRotate: () => Promise<number>

Defined in: core/items/item.ts:642

See: #core/IItemLayout#getCanvasRotate getCanvasRotate

Promise<number>

IItemLayout.getCanvasRotate


getCropping: () => Promise<Object>

Defined in: core/items/item.ts:647

See: #core/IItemLayout#getCropping getCropping

Promise<Object>

IItemLayout.getCropping


getCustomName: () => Promise<string>

Defined in: core/items/item.ts:758

See: #core/Source#getCustomName getCustomName

Promise<string>

ISource.getCustomName

Source.getCustomName


getEnhancedRotate: () => Promise<number>

Defined in: core/items/item.ts:652

See: #core/IItemLayout#getEnhancedRotate getEnhancedRotate

Promise<number>

IItemLayout.getEnhancedRotate


getId: () => Promise<string>

Defined in: core/items/item.ts:267

return: Promise

Get the ID of the Item

item.getId().then(function(id) {
// The rest of your code here
});

Promise<string>

ISource.getId

Source.getId


getItemList: () => Promise<Item[]>

Defined in: core/items/item.ts:513

See: #core/Source#getItemList getItemList

Promise<Item[]>

ISource.getItemList

Source.getItemList


getKeepLoaded: () => Promise<boolean>

Defined in: core/items/item.ts:773

See: #core/Source#getKeepLoaded getKeepLoaded

Promise<boolean>

ISource.getKeepLoaded

Source.getKeepLoaded


getName: () => Promise<string>

Defined in: core/items/item.ts:748

See: #core/Source#getName getName

Promise<string>

ISource.getName

Source.getName


getPosition: () => Promise<Rectangle>

Defined in: core/items/item.ts:657

See: #core/IItemLayout#getPosition getPosition

Promise<Rectangle>

IItemLayout.getPosition


getRotateX: () => Promise<number>

Defined in: core/items/item.ts:667

See: #core/IItemLayout#getRotateX getRotateX

Promise<number>

IItemLayout.getRotateX


getRotateY: () => Promise<number>

Defined in: core/items/item.ts:662

See: #core/IItemLayout#getRotateY getRotateY

Promise<number>

IItemLayout.getRotateY


getRotateZ: () => Promise<number>

Defined in: core/items/item.ts:672

See: #core/IItemLayout#getRotateZ getRotateZ

Promise<number>

IItemLayout.getRotateZ


getType: () => Promise<ItemTypes>

Defined in: core/items/item.ts:786

See: #core/Source#getType getType

Promise<ItemTypes>

ISource.getType

Source.getType


getValue: () => Promise<string | XML>

Defined in: core/items/item.ts:763

See: #core/Source#getValue getValue

Promise<string | XML>

ISource.getValue

Source.getValue


isEnhancedResizeEnabled: () => Promise<boolean>

Defined in: core/items/item.ts:637

See: #core/IItemLayout#isEnhancedResizeEnabled isEnhancedResizeEnabled

Promise<boolean>

IItemLayout.isEnhancedResizeEnabled


isKeepAspectRatio: () => Promise<boolean>

Defined in: core/items/item.ts:627

See: #core/IItemLayout#isKeepAspectRatio isKeepAspectRatio

Promise<boolean>

IItemLayout.isKeepAspectRatio


isPositionLocked: () => Promise<boolean>

Defined in: core/items/item.ts:632

See: #core/IItemLayout#isPositionLocked isPositionLocked

Promise<boolean>

IItemLayout.isPositionLocked


refresh: () => Promise<Source>

Defined in: core/items/item.ts:783

See: #core/Source#refresh refresh

Promise<Source>

ISource.refresh

Source.refresh


sendBackward: () => Promise<Item>

Defined in: core/items/item.ts:677

See: #core/IItemLayout#sendBackward sendBackward

Promise<Item>

IItemLayout.sendBackward


sendToBack: () => Promise<Item>

Defined in: core/items/item.ts:682

See: #core/IItemLayout#sendToBack sendToBack

Promise<Item>

IItemLayout.sendToBack


setCanvasRotate: (value) => Promise<Item>

Defined in: core/items/item.ts:687

See: #core/IItemLayout#setCanvasRotate setCanvasRotate

number

Promise<Item>

IItemLayout.setCanvasRotate


setCropping: (value) => Promise<Item>

Defined in: core/items/item.ts:692

See: #core/IItemLayout#setCropping setCropping

Object

Promise<Item>

IItemLayout.setCropping


setCroppingEnhanced: (value) => Promise<Item>

Defined in: core/items/item.ts:697

See: #core/IItemLayout#setCroppingEnhanced setCroppingEnhanced

Object

Promise<Item>

IItemLayout.setCroppingEnhanced


setCustomName: () => Promise<Item>

Defined in: core/items/item.ts:753

See: #core/Source#setCustomName setCustomName

Promise<Item>

ISource.setCustomName

Source.setCustomName


setEnhancedResizeEnabled: (value) => Promise<Item>

Defined in: core/items/item.ts:717

See: #core/IItemLayout#setEnhancedResizeEnabled setEnhancedResizeEnabled

boolean

Promise<Item>

IItemLayout.setEnhancedResizeEnabled


setEnhancedRotate: (value) => Promise<Item>

Defined in: core/items/item.ts:702

See: #core/IItemLayout#setEnhancedRotate setEnhancedRotate

number

Promise<Item>

IItemLayout.setEnhancedRotate


setKeepAspectRatio: (value) => Promise<Item>

Defined in: core/items/item.ts:707

See: #core/IItemLayout#setKeepAspectRatio setKeepAspectRatio

boolean

Promise<Item>

IItemLayout.setKeepAspectRatio


setKeepLoaded: (value) => Promise<Item>

Defined in: core/items/item.ts:778

See: #core/Source#setKeepLoaded setKeepLoaded

boolean

Promise<Item>

ISource.setKeepLoaded

Source.setKeepLoaded


setName: (value) => Promise<Item>

Defined in: core/items/item.ts:743

See: #core/Source#setName setName

string

Promise<Item>

ISource.setName

Source.setName


setPosition: (value) => Promise<Item>

Defined in: core/items/item.ts:722

See: #core/IItemLayout#setPosition setPosition

Rectangle

Promise<Item>

IItemLayout.setPosition


setPositionLocked: (value) => Promise<Item>

Defined in: core/items/item.ts:712

See: #core/IItemLayout#setPositionLocked setPositionLocked

boolean

Promise<Item>

IItemLayout.setPositionLocked


setRotateX: (value) => Promise<Item>

Defined in: core/items/item.ts:732

See: #core/IItemLayout#setRotateX setRotateX

number

Promise<Item>

IItemLayout.setRotateX


setRotateY: (value) => Promise<Item>

Defined in: core/items/item.ts:727

See: #core/IItemLayout#setRotateY setRotateY

number

Promise<Item>

IItemLayout.setRotateY


setRotateZ: (value) => Promise<Item>

Defined in: core/items/item.ts:737

See: #core/IItemLayout#setRotateZ setRotateZ

number

Promise<Item>

IItemLayout.setRotateZ


setValue: (value) => Promise<Item>

Defined in: core/items/item.ts:768

See: #core/Source#setValue setValue

string | XML

Promise<Item>

ISource.setValue

Source.setValue


static _emitter: EventEmitter

Defined in: core/items/item.ts:85


static _subscriptions: any[] = []

Defined in: core/items/item.ts:86

duplicate(options?): Promise<Item>

Defined in: core/items/item.ts:416

param: (options: {linked?:, scene?: })

return: Promise<Item>

Duplicate an item into the current scene or to a specified scene as Linked or Unlinked.

Linked items would generally have a single source, and any changes in the property of an item would be applied to all linked items.

Chainable

// item pertains to an actual Item instance
// Sample 1
item.duplicate() // duplicate selected item to the current scene as unlinked

Duplicate the selected item to a specific scene and set it to be linked to a single source with the original item.

// Sample 2
var toScene = xjs.Scene.getById(2)
item.duplicate({linked:true, scene:toScene})

boolean

number | Scene

Promise<Item>


getFPS(): Promise<number>

Defined in: core/items/item.ts:282

return: Promise

Get the frames rendered per second of an item

item.getFPS().then(function(fps) {
// The rest of your code here
});

Promise<number>


getParentItem(): Promise<Item>

Defined in: core/items/item.ts:587

return: Promise

Get the GroupItem that contains this item. This rejects if item is not a child item or non-existent

item.getParentItem()
.then(function(parentItem) {
console.log(parentItem);
});

Promise<Item>


getSceneId(): Promise<string | number>

Defined in: core/items/item.ts:351

return: Promise<number|string>

Get (1-indexed) Scene ID where the source is loaded

source.getSceneId().then(function(id) {
// The rest of your code here
});

Promise<string | number>


getSource(): Promise<Source>

Defined in: core/items/item.ts:530

return: Promise

Gets the Source of an item, linked items would only have 1 source.

Chainable

item.getSource().then(function(source) {
//Manipulate source here
source.setName('New Name')
})

Promise<Source>


getView(): Promise<ViewTypes>

Defined in: core/items/item.ts:320

return: Promise

Get the view type of the item

item.getView().then(function(view) {
// view values:
// 0 = main view
// 1 = preview editor
// 2 = thumbnail preview
})

Promise<ViewTypes>


isChildItem(): Promise<boolean>

Defined in: core/items/item.ts:558

return: Promise

Checks if item is part of a group

item.isChildItem()
.then(function(isChild) {
console.log(isChild);
});

Promise<boolean>


off(event, handler): void

Defined in: core/items/item.ts:224

param: (event: string, handler: Function)

Removes specificied event handler bound by on. Note that this can only be done for named function handlers.

let itemChange = function(...args) {
console.log('Item has changed');
}
let current;
let items;
xjs.Scene.getActiveScene()
.then( scene => {
current = scene;
return current.getItems();
}).then( list => {
items = list;
items[0].on('item-changed', itemChange);
setTimeout( ()=> {
items[0].off('item-changed', itemChange);
}, 10000);
});

string

Function

void


on(event, handler): void

Defined in: core/items/item.ts:126

param: (event: string, handler: Function)

Allows listening to events per instance. Currently there are only two: item-changed and item-destroyed.

Item change is triggered thru any property change:

  • via js(source plugin/extension),
  • via visibility-toggling through the sources list,
  • or via the source properties dialog
let itemChange = function(...args) {
console.log('Item has changed');
}
let current;
let items;
xjs.Scene.getActiveScene()
.then( scene => {
current = scene;
return current.getItems();
}).then( list => {
items = list;
items[0].on('item-changed', itemChange);
});

Duplicate handlers are allowed.

string

Function

void


remove(): Promise<boolean>

Defined in: core/items/item.ts:504

return: Promise

Removes selected item

item.remove()

Promise<boolean>


toXML(): XML

Defined in: core/items/item.ts:373

return: XML

Convert the Item object to an XML object. Use toString() to get the string version of the returned object.

var xml = item.toXML();

XML


unlink(): Promise<Item>

Defined in: core/items/item.ts:486

return: Promise

Unlinks selected item.

Unlinks an item to the source of other linked items and renders its own source.

item.unlink()

Note: Once you unlink an Item, there’s still no method to reverse the process.

Promise<Item>


static getAllSources(): Promise<Source[]>

Defined in: core/source/source.ts:220

return: Promise<Source[]>

Get all unique Source from every scene. Total number of Sources returned may be less than total number of items on all the scenes due to Linked items only having a single Source.

xjs.Source.getAllSources().then(function(sources) {
for(var i = 0 ; i < sources.length ; i++) {
if(sources[i] instanceof xjs.HtmlSource) {
// Manipulate HTML Source here
}
}
})

Promise<Source[]>

Source.getAllSources


static getCurrentSource(): Promise<Source>

Defined in: core/source/source.ts:108

return: Promise

Get the current source (when function is called by sources), or the source that was right-clicked to open the source properties window (when function is called from the source properties window)

xjs.Source.getCurrentSource().then(function(source) {
// This will fetch the current source (the plugin)
}).catch(function(err) {
// Handle the error here. Errors would only occur
// if we try to execute this method on Extension plugins
});

Promise<Source>

Source.getCurrentSource


static getItemList(): Promise<Item[]>

Defined in: core/items/item.ts:248

return: Promise<Item[]>

Gets the list of linked items of the current Item. Linked items are items linked to a single source.

xjs.Item.getItemList().then(function(items) {
for (var i = 0 ; i < items.length ; i++) {
// Manipulate each item here
items[i].setKeepAspectRatio(true);
}
})

This is simply a shortcut to: xjs.Item.getCurrentSource() -> source.getItemList()

Promise<Item[]>

Source.getItemList