Class s7sdk.set.Swatches
The Swatches
component renders a collection of thumbnail images called swatches. Each swatch is
associated with an Adobe Image Serving catalog/asset ID and is part of a set as defined in Dynamic Media Classic. When operating in standalone mode,
to retrieve the set definition, the Swatches
component makes an Adobe Image Serving req=set
request using the values of the serverurl
and asset
modifiers. The preferred way of passing the set definition to the
component though is by calling the setMediaSet()
API after the set definition has been retrieved and parsed by the MediaSet
component.
thumboverlay
CSS class.
A swatch is selected by clicking (or tapping) the content, or by using the selectSwatch()
API in the viewer code.
When a swatch is selected, the Swatches
component dispatches an AssetEvent.SWATCH_SELECTED_EVENT
with a purpose of communicating the information associated with the swatch to the rest of the viewer application that usually does some
in response to it, for example, display the image associated with the swatch in the ZoomView
.
The Swatches
component can display large collections of swatches. Scrolling controls
appear when the number of swatches exceeds the available space. Scrolling is also supported with a mouse or by using
touch gestures.
This component supports different operation modes in landscape and portrait device orientation. This mode is enabled when the component is
initialized through setMediaSet()
API call with OrientationSetDesc
instance passed as an argument. By default the
component will pick up a MediaSetDesc
instance for landscape orientation, and will re-build appropriately when
setLandscape()
or setPortrait()
methods are called. OrientationSetDesc
instance can be returned by
MediaSet
component.
Customizing Behavior Using Modifiers
Modifiers change Swatches
default behavior. They are passed to the component by the ParameterManager
instance
specified in the constructor.
The following modifiers are supported:
Modifier | Syntax | Description | Default |
serverurl | isRootPath | The Adobe Image Serving root path. If no domain is specified, the domain from which the page is served is applied instead. Standard URI path resolution applies. | /is/image/ |
asset | imageSet | The Adobe Image Serving catalog or asset ID of a named image set whose definition comes from the server by means of the req=set command. | "" |
iscommand | value | The Adobe Image Serving command string that is applied to all swatches. If specified in the URL all occurrences of '&' and '=' must be HTTP-encoded as %26 and %3D , respectively. | "" |
tmbsize | width, height | Specifies the pixel size of the individual swatch thumbnails. If the cell size of the swatches exceeds the size requirement of the component, the swatches do not display. (Deprecated: now use CSS to specify thumb dimensions.) | 75,75 |
tmblayout | cols, rows | Specifies columns, or rows, or both to limit the number of cells per row and column, respectively. Set rows, or columns, or both to 0 to let the component choose how many cells per row and column to display. If both rows and columns are larger than 0, the component ignores any swatches that exceed the total number of cells that are available. The swatches are also ignored if they cannot fit into the component's area and the resizable modifier is set to false. | 0,2 |
maxloadradius | -1|0|preloadnbr | Specifies the component preload behavior. When set to -1 , all swatches are loaded simultaneously when the component is initialized or the asset has changed. When set to 0 , only visible swatches are loaded. Set preloadnbr to define how many invisible rows or columns around the visible area are preloaded. | 1 |
direction | auto|left|right | Specifies the way swatches fill in the view. Set left to set a left-to-right fill order. Set right to reverse the order so that the view is filled in a right-to-left, top-to-bottom direction. Set auto to have the component apply right mode when locale is set to "ja". Otherwise, left is used. | auto |
textpos | bottom|top|left|right|none|tooltip | Specifies where the label is drawn relative to the swatch thumbnail image. That is, the label is centered at the specified location relative to the swatch thumbnail. When tooltip is specified, no label is drawn. | bottom |
fmt | jpg|jpeg|png|png-alpha|gif|gif-alpha | Specifies the image format that the component uses for loading images from Image Server. Any value supported by Image Server and the client browser is used. If the image format ends with "-alpha", the component renders images as transparent. For all other image format values, the component treats images as opaque. | jpeg |
resizable | 0|1 | If set to 0, only the swatches that can fit into the component's area are shown. If set to 1, the component dynamically resizes to fit the content. | 0 |
pagemode | 0|1 | When toggled, the scroll buttons automatically cause the swatches to jump a full page length. Extra whitespace is shown on the last page if the swatches do not fit. The last page has the same number of cells as any previous page. The scrollstep is ignored and mouse scrolling settles only on full pages. | 0 |
enablescrollbuttons | 0|1 | Displays or hides the scroll buttons. When the scroll buttons are hidden, the user can use their mouse or use touch gestures to scroll. Scroll buttons do not appear if there is no need to scroll, regardless of the setting. | 1 |
scrollstep | hStep, vStep | Specifies the number of swatches to scroll for each tap of the corresponding scroll button. If the specified value is greater than the number of swatches visible in that direction, each tap will only scroll by the number of visible swatches to prevent omission of any swatch. | 3,3 |
enabledragging | 0|1[,overdragvalue] | Enables or disables the ability for a user to scroll the swatches using a mouse or using touch gestures. The overdragvalue has a range of 0 - 1 and it is a percent value for the movement in the wrong direction of the actual speed. If set to 1, it moves with the mouse. If set to 0, it does not let you move in the wrong direction at all. | 1,0.5 |
buttonsnapmode | snapin|snapout|overlay | One of three button modes that are specified by setting the desired string. Set snapin to have the buttons align next to the swatches. Set snapout to have the buttons align next to the component border. Use overlay to cause the buttons to render on top of the swatches. | snapout |
partialswatches | 0|1 | Specifies whether to stop component scrolling when any of the swatches are partially visible. That is, scrolling is not aligned. The recommended value is false or 0. | 0 |
orientation | 0|1 | Defines the layout of swatch cells. A row-major layout is used when the orientation is set to 0, and a column-major layout is used when set to 1. When in pagemode, the swatches are filled in the specified manner, page-by-page. Otherwise, page breaks are ignored. | 0 |
align | left|center|right,top|center|bottom | Specifies internal alignment--or anchoring--of the swatches container within the component area. In Swatches, the internal thumbnail container is sized so that only a whole number of swatches is shown. As a result, there is some padding between the internal container and the external component bounds. This command specifies how the internal swatches container is positioned inside the component. It does not have any effect when resizable=1 . | center,center |
scrolltransition | duration | Specifies the slide animation duration in seconds by the duration. | 0.3 |
Defining the Appearance using CSS
You can define the appearance of the Swatches
component using CSS rules. All Adobe Experience Viewers HTML5 SDK components use class selectors for styling. You can style the body of the Swatches
component by using
the .s7swatches
class selector. The styles that are associated with this class selector are applied to all instances of the Swatches
component. You can style particular instances by prefixing
the class rule with the instance #id. For example, styling rules for #myComp.s7swatches
are applied only to the particular Swatches
instance.
The styling of the sub-elements using class selectors like .s7thumb
for example, must be specified in the form of the descendant class selectors, that is,
they must follow the main class selector separated by a space, such as .s7swatches .s7thumb
.
For more information on component styling see the Adobe Experience Viewers HTML5 SDK User Guide and the default styles section.
CSS Class | Attribute Selector | Description |
.s7swatches | (None) | Represents the main body of the Swatches component. |
.s7thumbcell | (None) | Defines thumbnail spacing using margin CSS property. |
.s7thumb | state=[default|selected|over] | Defines the appearance of the swatch thumbnails. The height and width properties will define the dimensions of the swatch thumb. default value of state attribute corresponds to "up" state, selected means that the thumbnail is currently selected and over state turns on when user rolls over unselected thumbnail. |
.s7thumboverlay | type=[image|swatchset|spinset|video] | Defines the asset type overlay. state attribute allows specifying which asset type to assign overlay for: image stands for individual images, swatchset stands for image set or swatch set, spinset means spin set and video means single video or Adaptive Video Set. |
.s7label | (None) | Defines the appearance of the swatch labels. |
.s7tooltip | (None) | A global class selector that defines appearance for the tooltips. To disable tooltips set the display style to none . |
.s7scrollleftbutton | (None) | Defines the appearance of the left scroll button. |
.s7scrollrightbutton | (None) | Defines the appearance of the right scroll button. |
.s7scrollupbutton | (None) | Defines the appearance of the up scroll button. |
.s7scrolldownbutton | (None) | Defines the appearance of the down scroll button. |
Localizable Symbols
Swatches also have a number of text symbols that you can localize either in a preset or in the viewer page though the mechanisms
provided by the ParameterManager
. For more information on localization consult the ParameterManager
API documentation and Adobe Experience Viewers HTML5 SDK User Guide.
Symbol | Description |
Swatches.LABEL | Define a localized "aria-label" of Swatches |
ScrollLeftButton.TOOLTIP | Define a localized tooltip of ScrollLeftButton |
ScrollRightButton.TOOLTIP | Define a localized tooltip of ScrollRightButton |
ScrollUpButton.TOOLTIP | Define a localized tooltip of ScrollUpButton |
ScrollDownButton.TOOLTIP | Define a localized tooltip of ScrollDownButton |
Constructor Attributes | Constructor Name and Description |
---|---|
s7sdk.set.Swatches(container, settings, compId)
|
Method Attributes | Method Name and Description |
---|---|
addEventListener(type, handler, useCapture)
Adds an event listener to the instance of the
Swatches component. |
|
dispose()
Dispose is used to remove itself and all sub-elements from the DOM
|
|
Gets the current selected page from the set.
|
|
getFrame()
Returns the index of the current frame of the image or media set.
|
|
Returns the current inner height of the component.
|
|
Gets the current page count of the swatches.
|
|
getWidth()
Returns the current inner width of the component.
|
|
resize(width, height)
Resizes the
Swatches component to the specified width and height. |
|
selectSwatch(index, triggerScroll)
Selects the specified frame.
|
|
setAsset(assetName)
Changes the currently displayed set.
|
|
setCSS(classname, property, value)
Sets a particular CSS class and property on a component
|
|
setCurrentPage(page)
Sets the currently displayed page from the set.
|
|
Switches component to landscape operation mode.
|
|
setMediaSet(mediaSet, type)
Sets the image or eCatalog set or
OrientationSetDesc instance which contains two instances of MediaSetDesc
for landscape and portrait orientations separately. |
|
setModifier(modObj)
Sets 1-N # of modifiers for the component.
|
|
Switches component to portrait operation mode.
|
Example Code
This example demonstrates how to use the Swatches component in a simple viewer. In this example a Container object,
a ZoomView object, and a Swatches object are created. Every time a user clicks a swatch, the ZoomView loads and
displays the appropriate image asset related to the selected swatch.
The code below does the following:
- The Adobe Experience Viewers HTML5 SDK is linked to the page and the required s7sdk components are included in the document head.
- CSS Styles are defined in the document head to control the appearance of the Swatches component.
- The s7sdk.Util.init() method is called to initialize the SDK.
- A ParameterManager object is created to handle component modifiers for the viewer.
- An initViewer() function is defined. This function initializes a couple of modifiers (hard coded for example purposes),
then creates the component objects required for this simple example. The selectSwatch() function is called on the
Swatches object to designate which swatch the viewer should display first. The initViewer() function also adds
event listeners that designate functions to handle relevant component events (which might be dispatched by the
components as a result of user interactions, changes in a component's state, etc.).
- Handler functions are defined to respond to the component event listeners added in the initViewer() function.
- An event listener is added to the ParameterManager object that designates the initViewer() function as the handler
to call when the Adobe Experience Viewers HTML5 SDK is loaded and ready.
- Finally, the init() method is called on the ParameterManager object to start the viewer.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="user-scalable=no, height=device-height, width=device-width,
initial-scale=1.0, maximum-scale=1.0"/>
<title>Swatches Example</title>
<!--
To run this example locally you need to replace this with an absolute SDK path.
For more information check the Adobe Experience Viewers HTML5 SDK User Guide or the examples
included in the package.
-->
<script language="javascript" type="text/javascript"
src="../js/s7sdk/utils/Utils.js"></script>
<script language="javascript" type="text/javascript">
s7sdk.Util.lib.include('s7sdk.image.ZoomView');
s7sdk.Util.lib.include('s7sdk.set.Swatches');
s7sdk.Util.lib.include('s7sdk.common.Container');
</script>
<style type="text/css" media="screen">
html, body {
width: 100%;
height: 100%;
}
body {
margin: 0px;
padding: 0px;
}
.s7swatches {
top: 10px;
left: 10px;
height: 150px;
width: 300px;
border: 1px;
border-color:#cccccc;
background-color: rgba(200, 200, 200, 0.5);
}
.s7swatches .s7thumb { }
.s7swatches .s7thumb[state="default"] { }
.s7swatches .s7thumb[state="over"] {
box-shadow: inset 0px 0px 0px 2px #6699ff;
-webkit-box-shadow: inset 0px 0px 0px 2px #6699ff;
}
.s7swatches .s7thumb[state="selected"] {
box-shadow: inset 0px 0px 0px 2px #3366CC;
-webkit-box-shadow: inset 0px 0px 0px 2px #3366CC;
}
</style>
</head>
<body style="margin: 0 0;overflow:hidden;">
<script language="JavaScript" type="text/javascript">
var params, container, zoomView, swatches;
// Initialize the SDK
s7sdk.Util.init();
// Create ParameterManager instance to handles modifiers
params = new s7sdk.ParameterManager();
// Define the function that initializes the viewer
function initViewer(){
// Set hardcoded modifiers (not required when values are specified on the url)
params.push("serverurl", "https://s7d1.scene7.com/is/image");
params.push("asset", "Scene7SharedAssets/ImageSet-Views-Sample");
// Create the Container component object
container = new s7sdk.common.Container(null, params, "s7container");
// Create the ZoomView component object to display the asset associated with the swatch
zoomView = new s7sdk.image.ZoomView(container, params, "myZoomView");
zoomView.resize(container.getWidth(),container.getHeight());
// Create the Swatches component object
swatches = new s7sdk.set.Swatches(container, params,"mySwatches");
// Select the first swatch
swatches.selectSwatch(0, true);
// Add an event listener for swatch selection events
swatches.addEventListener(s7sdk.event.AssetEvent.SWATCH_SELECTED_EVENT, onSwatchSelected, false);
}
// Define an event handler function to update the ZoomView image when a new swatch is selected
function onSwatchSelected(event){
zoomView.setItem(event.s7event.asset);
}
// The ParameterManager will dispatch SDK_READY when all modifiers have been processed
// and it is safe to initialize the viewer
params.addEventListener(s7sdk.Event.SDK_READY, initViewer, false);
// Now it is safe to process the modifiers, the callbacks have been defined
// this will trigger the SDK_READY event
params.init();
</script>
</body>
</html>
Default styles for Swatches:
.s7swatches {
background-color:rgba(100, 100, 100, 0.2);
z-index:0;
user-select:none;
-ms-user-select:none;
-moz-user-select:-moz-none;
-webkit-user-select:none;
-webkit-tap-highlight-color:rgba(0,0,0,0);
width:500px;
height:250px;
}
.s7swatches .s7thumbcell {
margin:5px;
}
.s7swatches .s7thumb {
border:1px solid transparent;
width:75px;
height:75px;
}
.s7swatches .s7thumb[state='selected'] {
border:1px solid #FFFFFF;
}
.s7swatches .s7thumb .s7thumboverlay {
width:100%;
height:100%;
}
.s7swatches .s7thumb .s7thumboverlay[type='swatchset'] {
background-image:url(images/sdk/asset_type_swatches.png);
}
.s7swatches .s7thumb .s7thumboverlay[type='spinset'] {
background-image:url(images/sdk/asset_type_spin.png);
}
.s7swatches .s7thumb .s7thumboverlay[type='video'] {
background-image:url(images/sdk/asset_type_video.png);
}
.s7swatches .s7label {
font-family:Helvetica, sans-serif;
font-size:12px;
}
.s7swatches .s7scrollleftbutton {
display:block;
position:absolute;
top:0px;
left:0px;
width:20px;
height:20px;
}
.s7swatches .s7scrollleftbutton[state='up'] {
background-image:url(images/sdk/scroll_left_up.png);
}
.s7swatches .s7scrollleftbutton[state='over'] {
background-image:url(images/sdk/scroll_left_over.png);
}
.s7swatches .s7scrollleftbutton[state='down'] {
background-image:url(images/sdk/scroll_left_down.png);
}
.s7swatches .s7scrollleftbutton[state='disabled'] {
background-image:url(images/sdk/scroll_left_disabled.png);
}
.s7swatches .s7scrollrightbutton {
display:block;
position:absolute;
top:0px;
left:0px;
width:20px;
height:20px;
}
.s7swatches .s7scrollrightbutton[state='up'] {
background-image:url(images/sdk/scroll_right_up.png);
}
.s7swatches .s7scrollrightbutton[state='over'] {
background-image:url(images/sdk/scroll_right_over.png);
}
.s7swatches .s7scrollrightbutton[state='down'] {
background-image:url(images/sdk/scroll_right_down.png);
}
.s7swatches .s7scrollrightbutton[state='disabled'] {
background-image:url(images/sdk/scroll_right_disabled.png);
}
.s7swatches .s7scrollupbutton {
display:block;
position:absolute;
top:0px;
left:0px;
width:20px;
height:20px;
}
.s7swatches .s7scrollupbutton[state='up'] {
background-image:url(images/sdk/scroll_up_up.png);
}
.s7swatches .s7scrollupbutton[state='over'] {
background-image:url(images/sdk/scroll_up_over.png);
}
.s7swatches .s7scrollupbutton[state='down'] {
background-image:url(images/sdk/scroll_up_down.png);
}
.s7swatches .s7scrollupbutton[state='disabled'] {
background-image:url(images/sdk/scroll_up_disabled.png);
}
.s7swatches .s7scrolldownbutton {
display:block;
position:absolute;
top:0px;
left:0px;
width:20px;
height:20px;
}
.s7swatches .s7scrolldownbutton[state='up'] {
background-image:url(images/sdk/scroll_down_up.png);
}
.s7swatches .s7scrolldownbutton[state='over'] {
background-image:url(images/sdk/scroll_down_over.png);
}
.s7swatches .s7scrolldownbutton[state='down'] {
background-image:url(images/sdk/scroll_down_down.png);
}
.s7swatches .s7scrolldownbutton[state='disabled'] {
background-image:url(images/sdk/scroll_down_disabled.png);
}
.s7tooltip {
position:absolute;
padding:5px;
line-height:100%;
text-align:center;
background-color:rgb(224, 224, 224);
color:rgb(26,26,26);
font-family:Helvetica, sans-serif;
font-size:11px;
z-index:10000;
border:1px solid rgb(191,191,191);
}
- Parameters:
- {String|Container} container
- The reference to
Container
instance or the ID of the parent DOM element to which the component is added as a child - {s7sdk.ParameterManager} settings
- A parameter manager instance that represents the desired configuration.
- {String} compId
- An optional parameter that specifies the ID of the component DOM element.
Swatches
component. The handler function
receives a DOM event object of type Event
. The object contains a property s7event
,
which references the associated custom event object, for example s7sdk.event.AssetEvent
.
The events supported by the component are:
s7sdk.event.AssetEvent.SWATCH_SELECTED_EVENT
- Dispatched when a swatch is selected. s7sdk.event.AssetEvents7sdk.event.SwatchEvent.SWATCH_PAGE_CHANGE
- Dispatched when the currently displayed page of swatches has changed. s7sdk.event.SwatchEvents7sdk.event.StatusEvent.NOTF_ASSET_METADATA_READY
- Dispatched when component receives asset metadata. If the component is initialized with setMediaSet()
it dispatches instantly inside that API call. Otherwise if the component loads req=set on its own, this event is sent when component has received and parsed req=set. s7sdk.event.StatusEvents7sdk.event.StatusEvent.NOTF_VIEW_READY
- Dispatched when component loads all images for swatches currently visible on the screen. It is sent both during the initial load and during consequent scroll or resize operations. s7sdk.event.StatusEvents7sdk.event.StatusEvent.NOTF_PRELOAD_START
- Dispatched when swatch images download begins according to maxloadradius
modifier. The event may be sent multiple times during component's life cycle as user actions may trigger new preloading step. s7sdk.event.StatusEvents7sdk.event.StatusEvent.NOTF_PRELOAD_COMPLETE
- Dispatched when all swatch images according to maxloadradius
modifier are downloaded. The event may be sent multiple times during component's life cycle as user actions may trigger new preloading step. s7sdk.event.StatusEvent- Parameters:
- {String} type
- Event name, for example
s7sdk.event.AssetEvent.SWATCH_SELECTED_EVENT
. - {Function} handler
- Function to be called when the event gets dispatched.
- {Boolean} useCapture
- Register capture phase.
- Returns:
- Current page from the set.
- Returns:
- Index of the current frame.
- Returns:
- {Number} the inner height of the component, in pixels.
- Returns:
- Number of pages in the set based on visible thumbnails
- Returns:
- {Number} the inner width of the component, in pixels.
Swatches
component to the specified width and height.
- Parameters:
- {Number} width
- - The width of the component, in pixels.
- {Number} height
- - The height of the component, in pixels.
- Parameters:
- {Number} index
- Frame index in the image set.
- {Boolean} triggerScroll
- Scroll to the newly selected swatch.
SWAP
tracking event that is managed by the TrackingManager
component.
- Parameters:
- {String} assetName
- - The catalog ID of the set.
- Parameters:
- {String} classname
- The CSS classname to use for this style. i.e. .s7swatches
- {String} property
- The CSS property that is being set. i.e. background-color
- {String} value
- The CSS property value being set. i.e. #FF0000
- Parameters:
- {s7sdk.Point2D} page
- - The currently selected page.
setMediaSet()
API call
with OrientationSetDesc
instance passed as an argument, it will re-build using MediaSetDesc
instance specific
to landscape orientation. Otherwise, if component was initialized with asset
modifier, using setAsset()
API
or setMediaSet()
API call with MediaSetDesc
passed as an argument, the call to this method is ignored.
OrientationSetDesc
instance which contains two instances of MediaSetDesc
for landscape and portrait orientations separately. This will re-set the component to use
the new set content; anything previously set through asset
modifier will be ignored.
The set is not parsed recursively; to use embedded sets you need to call this method passing in the embedded set instead.
You can filter out swatches that you do not wish incorporated in the thumbnail set that is displayed in the component by using
type
parameter. This parameter is a bit field and represents a combination of the ImageDescType
values that correspond to the type of items whose associated swatches you want to show in the component. For example, passing in
s7sdk.ItemDescType.VIDEO | s7sdk.ItemDescType.IMG
will show only swatches that are associated either with video or images. All
other items will be ignored. The default
value of 0
turns the filtering off. That is, all swatches are displayed regardless of the type of the item they
are associated with.
- Parameters:
- {MediaSetDesc | OrientationSetDesc} mediaSet
- Set to extract swatches from.
- {int} type
- A bit field combination of the item types to show swatches for. If set to 0 the filtering is turned off.
- Parameters:
- {Object} modObj
- A simple JSON object with name:value pairs of valid modifiers for a particular component
setMediaSet()
API call
with OrientationSetDesc
instance passed as an argument, it will re-build using MediaSetDesc
instance specific
to portrait orientation. Otherwise, if component was initialized with asset
modifier, using setAsset()
API
or setMediaSet()
API call with MediaSetDesc
passed as an argument, the call to this method is ignored.