Home Reference Source
import Template from '~/template/Template.js'
public class | source

Template

Manages a section of HTML used with a view. See TemplateType to see how you can import one

Static Member Summary

Static Public Members
public static get

An empty template

Static Method Summary

Static Public Methods
public static

Performs a move TemplateType for a given HTML id to return a template based on the id's root.

public static

fromInnerHTML(wrapper: HTMLElement, innerHTML: string, type: TemplateType): Template

From innerHTML will wrap in div

public static

Creates template <div> with text.

Constructor Summary

Public Constructor
public

constructor(root: HTMLElement, type: TemplateType)

Creates a template from some form of HTML fragment.

Member Summary

Public Members
public get

underlyingNode: HTMLElement

Returns the underlying element

Method Summary

Public Methods
public

defineLinkedClass(name: string, className: string, node: HTMLElement)

Defines a linked class

public

defineLinkedInput(name: string, input: HTMLElement)

Defines a linked input

public

defineLinkedText(name: string, defaultValue: string): Text

Creates a field w/ updating text

public abstract

async didInitialLoad()

Called when loaded the first time

public abstract

Called when the view has loaded

public

Called when disappeared

public

getParent(defaultElement: HTMLElement): HTMLElement

Gets the original parent or else a default

public

loadBeforeContext(elem: HTMLElement): HTMLElement

Loads before an element

public

loadInContext(parent: HTMLElement, allowDupliacte: boolean): HTMLElement

Loads the template in a context

public

loadReplacingContext(source: HTMLElement): HTMLElement

Loads and replaces

public

prependInContext(parent: HTMLElement, allowDupliacte: boolean): HTMLElement

Prepends the template in a context

public

Removes from the context.

public

unique(): HTMLElement

Returns a unique instance of the template as an HTMLElement.

public

async willInitialLoad()

Called before loaded the first time

public

Called right before the view will appear on screen

public

Called before disappearing

Static Public Members

public static get empty source

An empty template

Static Public Methods

public static fromId(id: string, type: TemplateType): Template source

Performs a move TemplateType for a given HTML id to return a template based on the id's root.

Params:

NameTypeAttributeDescription
id string

HTML ID of a HTMLElement

type TemplateType

Type of the template

Return:

Template

New template.

public static fromInnerHTML(wrapper: HTMLElement, innerHTML: string, type: TemplateType): Template source

From innerHTML will wrap in div

Params:

NameTypeAttributeDescription
wrapper HTMLElement
innerHTML string

the innerHTML

type TemplateType
  • optional
  • default: none

Return:

Template

public static fromText(text: string, type: TemplateType): Template source

Creates template <div> with text.

Params:

NameTypeAttributeDescription
text string

text of new elem

type TemplateType
  • optional
  • default: none

Type of the generated template.

Return:

Template

new template.

Public Constructors

public constructor(root: HTMLElement, type: TemplateType) source

Creates a template from some form of HTML fragment. This can be from the DOM or a JS-based HTMLElement

Params:

NameTypeAttributeDescription
root HTMLElement

Root view of the template

type TemplateType
  • optional
  • default: none

Type of the template to reference.

Public Members

public get underlyingNode: HTMLElement source

Returns the underlying element

Public Methods

public defineLinkedClass(name: string, className: string, node: HTMLElement) source

Defines a linked class

Params:

NameTypeAttributeDescription
name string

field name

className string
node HTMLElement
  • optional
  • default: underlyingNode

public defineLinkedInput(name: string, input: HTMLElement) source

Defines a linked input

Params:

NameTypeAttributeDescription
name string

the name

input HTMLElement
  • optional
  • default: underlyingNode

public defineLinkedText(name: string, defaultValue: string): Text source

Creates a field w/ updating text

Params:

NameTypeAttributeDescription
name string

The field name

defaultValue string

The default value

Return:

Text

public abstract async didInitialLoad() source

Called when loaded the first time

public abstract didLoad() source

Called when the view has loaded

public didUnload() source

Called when disappeared

public getParent(defaultElement: HTMLElement): HTMLElement source

Gets the original parent or else a default

Params:

NameTypeAttributeDescription
defaultElement HTMLElement
  • nullable: true

Return:

HTMLElement

parent element or the defualt provided.

public loadBeforeContext(elem: HTMLElement): HTMLElement source

Loads before an element

Params:

NameTypeAttributeDescription
elem HTMLElement

Element to load before

Return:

HTMLElement

rendered element

public loadInContext(parent: HTMLElement, allowDupliacte: boolean): HTMLElement source

Loads the template in a context

Params:

NameTypeAttributeDescription
parent HTMLElement

Will be appended to this node.

allowDupliacte boolean

If should allow to be loaded multiple times

Return:

HTMLElement

rendered element

public loadReplacingContext(source: HTMLElement): HTMLElement source

Loads and replaces

Params:

NameTypeAttributeDescription
source HTMLElement

what to replace

Return:

HTMLElement

public prependInContext(parent: HTMLElement, allowDupliacte: boolean): HTMLElement source

Prepends the template in a context

Params:

NameTypeAttributeDescription
parent HTMLElement

Will be appended to this node.

allowDupliacte boolean

If should allow to be loaded multiple times

Return:

HTMLElement

rendered element

public removeFromContext() source

Removes from the context. Errors if not loaded

public unique(): HTMLElement source

Returns a unique instance of the template as an HTMLElement.

Return:

HTMLElement

unique instance of the DOM element.

public async willInitialLoad() source

Called before loaded the first time

public willLoad() source

Called right before the view will appear on screen

public willUnload() source

Called before disappearing