define([
'layout.dt/js/metadata/AssetMetadata'
], function(
AssetMetadata
) {
'use strict';
/**
* Collection of the assets (files) that make up a theme. There are several
* {@link layout.dt/js/api/ThemeAssets.Type types} depending on an asset's
* functionality.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @exports layout.dt/js/api/ThemeAssets
* @constructor
*
* @see {@link layout.dt/js/spi/ThemeProvider Example of a complete
* ThemeProvider} including a list of assets
* @see {@link layout.dt/js/spi/ThemeProvider#getAssets ThemeProvider.getAssets}
* theme provider SPI method to return a theme's assets
*/
var ThemeAssets = function() {
AbcsLib.checkParameterCount(arguments, 0);
AbcsLib.checkThis(this);
var self = this;
self._assets = [];
};
/**
* Adds an asset to the collection.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {layout.dt/js/api/ThemeAssets.Type} assetType The type of the asset
* @param {String} assetPath The path and filename of the asset, relative to
* the asset path declared by the ThemeProvider.
*
* @returns {layout.dt/js/api/ThemeAssets} a reference to this object to
* allow method chaining
*
* @see {@link layout.dt/js/spi/ThemeProvider Example of a complete
* ThemeProvider} which uses this method
*/
ThemeAssets.prototype.addAsset = function(assetType, assetPath) {
AbcsLib.checkParameterCount(arguments, 2);
AbcsLib.checkDataType(assetType, AbcsLib.Type.STRING); // ThemeAssets.Type is actually String
AbcsLib.checkDataType(assetPath, AbcsLib.Type.STRING);
this._assets.push(new AssetMetadata(assetType, assetPath));
return this;
};
/**
* Gets all theme assets of given type, or all of them if no type defined.
*
* @param {layout.dt/js/api/ThemeAssets.Type} [type] type of assets to get,
* undefined to return all
* @returns {AssetMetadata[]} list of assets
*/
ThemeAssets.prototype.getAssets = function(type) {
// get all assets
if (type === undefined) {
return this._assets;
}
var result = [];
this._assets.forEach(function(asset) {
if (asset.getType() === type) {
result.push(asset);
}
});
return result;
};
/**
* Defines valid asset types.
*
* @AbcsExtension stable
* @version 17.1.5
* @static
* @constant
* @enum {String}
*/
ThemeAssets.Type = {
/**
* Styling file.
*
* <p>Theme CSS files can include styling for elements within the theme
* HTML and also elements generated by ABCS, including Oracle JET
* components.</p>
*
* @AbcsExtension stable
* @version 17.1.5
* @constant
* @type {String}
*/
STYLE: AssetMetadata.Type.STYLE,
/**
* Javascript template file.
*
* <p>A theme can have custom Javascript code in files other than its
* {@link layout.dt/js/spi/ThemeProvider ThemeProvider SPI}
* implementation.</p>
*
* @AbcsExtension stable
* @version 17.1.5
* @constant
* @type {String}
*/
SCRIPT: AssetMetadata.Type.SCRIPT,
/**
* HTML template file.
*
* <p>A theme should have one HTML file designated as its template,
* whose contents should be returned by {@link layout.dt/js/spi/ThemeProvider#getTemplate
* ThemeProvider.getTemplate()}. Further HTML files can be loaded into
* the theme as templates</p>
*
* @AbcsExtension stable
* @version 17.1.5
* @constant
* @type {String}
*/
TEMPLATE: AssetMetadata.Type.TEMPLATE,
/**
* Image file.
*
* <p>A theme can include images which can be used within its layout and
* as theme preview in the theme palette.</p>
*
* @AbcsExtension stable
* @version 17.1.5
* @constant
* @type {String}
*/
IMAGE: AssetMetadata.Type.IMAGE,
/**
* Generic type for files which do not belong to any of the previous
* categories. Not currently used.
*
* @constant
* @type {String}
*/
OTHER: AssetMetadata.Type.OTHER
};
return ThemeAssets;
});