bajaux/icon/iconUtils

Utility functions for working with icons and associated HTML.

Description:
  • Utility functions for working with icons and associated HTML.

Source:

Methods

(static) toCssClass(uri) → {String}

Description:
  • Convert the URI to a usable CSS class, expected to be represented in the
    spritesheet CSS for that module.

Source:
Parameters:
Name Type Description
uri String
Returns:
Type
String

(static) toElements(icon, syncopt) → {Promise.<Array.<HTMLSpanElement>>}

Description:
  • Just like toHtml, but resolves an array of raw Elements instead.

Source:
Parameters:
Name Type Attributes Default Description
icon String | baja.Ord | Array.<(String|baja.Ord)> | baja.Simple

icon as
ORD, URI, or array of the same; a baja.Icon; (as of 4.12) a gx:Image

sync boolean <optional>
false

set to true to wait for the image to finish
loading (making it possible to query it for width/height) before the
toHtml promise resolves

Returns:

to be resolved with an array of
span elements

Type
Promise.<Array.<HTMLSpanElement>>

(static) toHtml(icon, syncopt) → {Promise.<string>}

Description:
  • Given an icon value (string, baja.Icon, etc), convert it into a usable
    HTML snippet.

    The HTML will consist of a one or more span tags. Each span will have
    one img element. If the icon is accounted for in a spritesheet, the
    img tag will be hidden and the icon will be represented solely by the
    span using pure CSS. If the icon is not in a spritesheet, the img
    tag will be shown and have its src tag set to the raw icon image.

Source:
Parameters:
Name Type Attributes Default Description
icon String | baja.Ord | Array.<(String|baja.Ord)> | baja.Simple

icon as
ORD, URI, or array of the same; a baja.Icon; (as of 4.12) a gx:Image

sync boolean <optional>
false

set to true to wait for the image to finish
loading (making it possible to query it for width/height) before the
toHtml promise resolves

Returns:

promise to be resolved with a raw HTML string containing
one or more span tags

Type
Promise.<string>

(static) toImageMetrics(icon) → {Promise.<module:bajaux/icon/iconUtils~ImageMetrics>}

Description:
  • Given an icon, calculate the metrics needed to paint the icon in a painting
    context such as a canvas.

Source:
Since:
  • Niagara 4.11
Parameters:
Name Type Description
icon String | baja.Ord | Array.<(String|baja.Ord)> | baja.Simple

icon as
ORD, URI, or array of the same; a baja.Icon; (as of 4.12) a gx:Image

Returns:
Type
Promise.<module:bajaux/icon/iconUtils~ImageMetrics>

(static) toUris(icon) → {Array.<String>}

Description:
  • Convert a value to an array of image URIs.

Source:
Parameters:
Name Type Description
icon String | baja.Ord | Array.<(String|baja.Ord)> | baja.Simple

a string
or array of strings. Each string can be a URI directly, or a module://
ORD. These will be converted to URIs to image files. If passing in
arbitrary ORDs, it's recommended to relativizeToSession() first. Can also
be a baja.Icon or (as of 4.12) a gx:Image

Throws:

if invalid input given

Type
Error
Returns:

array of image URIs

Type
Array.<String>

Type Definitions

ImageMetrics

Description:
  • Metrics needed to paint an icon in a painting context such as a canvas.

Source:
Properties:
Name Type Description
uri string

URI of the image to paint

x number

pixels from left edge of the image

y number

pixels from top edge of the image

width number

width in pixels

height number

height in pixels

Metrics needed to paint an icon in a painting context such as a canvas.