API Asset Manager

Artur Arseniev edited this page Aug 30, 2016 · 1 revision

AssetManager

Before using this methods you should get first the module from the editor instance, in this way:

var assetManager = editor.AssetManager;

Parameters

  • config Object Configurations
    • config.assets Array.<Object>= Default assets (optional, default [])
    • config.uploadText String= Upload text (optional, default 'Dropfileshereorclicktoupload')
    • config.upload String= Where to send upload data. Expects as return a JSON with asset/s object as: {data: [{src:'...'}, {src:'...'}]} (optional, default '')

Examples

...
{
  assets: [
  {src:'path/to/image.png'},
    ...
 ],
 upload: 'http://dropbox/path', // Set to false to disable it
 uploadText: 'Drop files here or click to upload',
}

Returns this

add

Add new asset/s to the collection. URLs are supposed to be unique

Parameters

Examples

// In case of strings, would be interpreted as images
assetManager.add('http://img.jpg');
assetManager.add(['http://img.jpg', './path/to/img.png']);

// Using objects you could indicate the type and other meta informations
assetManager.add({
  src: 'http://img.jpg',
  //type: 'image',  //image is default
  height: 300,
width: 200,
});
assetManager.add([{
  src: 'http://img.jpg',
},{
  src: './path/to/img.png',
}]);

Returns Model

get

Returns the asset by URL

Parameters

Examples

var asset = assetManager.get('http://img.jpg');

Returns Object Object representing the asset

getAll

Return all assets

Returns Collection

load

Load data from the passed object, if the object is empty will try to fetch them autonomously from the storage manager. The fetched data will be added to the collection

Parameters

  • data Object Object of data to load

Examples

var assets = assetManager.load();
// The format below will be used by the editor model
// to load automatically all the stuff
var assets = assetManager.load({
  assets: [...]
});

Returns Object Loaded assets

remove

Remove the asset by its URL

Parameters

Examples

assetManager.remove('http://img.jpg');

Returns this

store

Store assets data to the selected storage

Parameters

  • noStore Boolean If true, won't store

Examples

var assets = assetManager.store();

Returns Object Data to store