Conditional Configuration Options
Conditional options are parameter blocks being evaluated if one or more conditions are met.
<fsi_parameter>
<if parameter="renderer" value="png">
<options>
<effects value="Sepia()" />
<renderer value="jpeg" />
</options>
</if>
</fsi_parameter>
The options
block containing the effects
and renderer
parameters applies only, if renderer
equals png
.
When are the conditions evaluated?
Conditional options are evaluated after the non-conditional parameters and after applying parameters by query and/or arguments.
When to use conditions in configurations?
Conditions are evaluated client side each time a viewer instance is loaded. Therefore, do not use too complex conditions and use them if required only.
You could e.g. define a specific UI skin depending on the directory a source image resides in.
The recommended way in this case though would be to assign the skin
attribute to the viewer’s HTML tag.
A good example when to use conditions is using the @mobile
parameter in conditions.
If you use FSI Viewer and would like to hide the UI on mobile devices, this condition does the trick:
<fsi_parameter>
<if parameter="@mobile" value="true">
<viewer>
<HideUI value="true" />
</viewer>
</if>
</fsi_parameter>
Cascaded Conditions
If multiple conditions should be met to apply parameters, you can cascade conditions:
<fsi_parameter>
<if parameter="renderer" value="sw1">
<if parameter="quality" operator="lessThanEqual" value="50" >
<options>
<effects value="Sepia()" />
</options>
</if>
</if>
<fsi_parameter>
The options
block containing the effects
and renderer
parameters applies only, if
renderer
equalssw1
AND
quality
<= 50
Conditions and Groups
Conditions can appear within groups like <options>
, <viewer>
, <pages>
and alike.
In this case they are only evaluated, if the group matches for the viewer in use.
That means a condition in <pages>
will be ignored by FSI Viewer. This is the recommended way if a conditions applies to a single viewer type only.
<fsi_parameter>
<pages>
<if parameter="renderer" value="png">
<effects value="Sepia()" />
<renderer value="jpeg" />
</if>
</pages>
</fsi_parameter>
If a condition should apply to all viewer types you can add the condition to the <options>
group.
In case you want a condition to apply to multiple viewer types, but NOT to all, you can add the groups in question to the condition. The content of the groups does not need to be the same. If it should be the same, you need to repeat it in each viewer group:
<fsi_parameter>
<if parameter="renderer" value="sw1">
<pages>
<effects value="Sepia()" />
</pages>
<viewer>
<effects value="Sepia()" />
</viewer>
</if>
</fsi_parameter>
Building Conditions
The tag name of conditions must be <if>
.
The following attributes are supported:
- parameter: Mandatory. The name of the configuration parameter to compare. E.g.
language
,imageSrc
,dir
, etc. - value: Mandatory. The value to compare the configuration parameter to.
- operator: Optional. Defaults to
=
. The operator to use for the comparison.
Supported Operators in Conditions:
Operator | Description | Aliases |
---|---|---|
= | equals (case insensitive) | eq |
== | equals (case sensitive) | none |
!= | not equal (case insensitive) | not |
!== | not equal (case sensitive) | none |
< | less than (numerical) | lt, lessThan |
<= | less than or equal (numerical) | lte, lessThanEqual |
> | greater than (numerical) | gt, greaterThan |
>= | greater than or equal (numerical) | gte, greaterThanEqual |
match | match a JS regular expression | none |
notmatch | not match a JS regular expression | none |
As <
and >
may not be used in XML attribute values, you should use the alias instead (e.g. lt
instead of <
).
You can as well use the entity <
, but this does not look too good.
Regular Expressions (operator "match" and "notmatch")
Please assign a JavaScript regular expression like you would in a browser to the value
attribute of the condition.
The following example matches all source images ending with .tif
:
<if parameter="imagesrc" operator="match" value="/.*\.tif$/gi" >
<options>
<effects value="Sepia()" />
</options>
</if>
What parameter values can I use for conditions?
You can use all configuration parameters as you would use them in a URL.
E.e. use imagesrc
for <image><src value="foo" />
In addition, you can use a small number of device dependent parameters prefixed with "@". The following table lists possible values:
Name | Possible values | Description |
---|---|---|
@mobile | true/false | true for mobile devices, false for desktop devices |
@devicepixelratio | >= 1.0 | device pixel ration of the user’s device |
@navigatorUserAgent | String | User agent value of the user’s browser |
@navigatorLanguage | String | navigator.language of the user’s browser |
@navigatorPlatform | String | navigator.platform of the user’s browser |