Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AdaptiveElement

Hierarchy

Index

Constructors

constructor

  • Create a new instance of adaptive element. The ID is automatically computed, and the node is tagged with the element type.

    Parameters

    • node: JQuery

      The node of the element.

    • Default value selector: Selector | NoSelector = NO_SELECTOR

      The selector used to find the element node.

    • Default value parent: AdaptiveElement = null

      The parent adaptive element.

    Returns AdaptiveElement

Properties

id

id: string

Unique ID of the element. It should be computed once, before any adaptation, using getID method.

node

node: JQuery

Node of the element.

parent

parent: AdaptiveElement | null

Parent adaptive element. If it has no parent, it should be set to null.

selector

selector: Selector | NoSelector

Selector used to find the node. If no selector was used, it should be set to NO_SELECTOR.

Static TAG_PREFIX

TAG_PREFIX: string = "data-sam-"

Prefix of all tags added to nodes by SAM. It acts as a sort of HTML attribute namespace.

Methods

Private getID

  • getID(): string
  • Get the ID of the element, which should uniquely identify it.

    It is formed by the element type followed by the element selector, with a slash ("/") in between.

    Returns string

    The element ID.

getSelector

  • getSelector(): string

getTag

  • getTag(name: string): string | undefined
  • Call getNodeTag on the element node.

    Parameters

    • name: string

      The name of the tag (without the prefix).

    Returns string | undefined

    The value of the tag, or undefined if the tag was not found.

Abstract getType

  • getType(): string
  • Get the type of the element.

    Each concrete type of element must return an type which must be unique among all types of elements.

    Returns string

    The element type.

tag

  • tag(name: string, value: string): void
  • Add a tag to the element node, i.e. an prefixed HTML attribute. Note: the prefix is automatically prepended to the tag name.

    Parameters

    • name: string

      The name of the tag (without the prefix).

    • value: string

      The value of the attribute.

    Returns void

Private tagWithType

  • tagWithType(): void

Static getNodeTag

  • getNodeTag(node: JQuery, name: string): string | undefined
  • Get the value of a tag of the given node. Note: the prefix is automatically prepended to the tag name.

    Parameters

    • node: JQuery

      The tagged node (with the attribute).

    • name: string

      The name of the tag (without the prefix).

    Returns string | undefined

    The value of the tag, or undefined if the tag was not found.

Static nodeToSelector

  • nodeToSelector(node: JQuery): string
  • Return a standalone jQuery string selector for the given node, i.e. $(<selector>) should select the node.

    The selector is built recursively, in the following way:

    • if the node is the body or html node, it returns the related tag selector;
    • if the node has an ID, it returns the related ID selector;
    • otherwise, it calls nodeToSelector on the parent node of the given node, and returns the result with the following concatenation: (1) a child selector (>); (2) the node tag; (3) the node positional selector (:eq(<index>)).

    Parameters

    • node: JQuery

      The node to represent with a selector.

    Returns string

    The standalone selector.

Generated using TypeDoc