templateRenderer

templateRenderer

Source:
Author:
  • ariel.wexler@vecna.com
See:

Static Template Engine.
All template renders should be piped through this method.

Methods

(static) copyTopElement(el) → {Element}

Source:

Produces a copy of the element tag with attributes but with no contents

Parameters:
Name Type Description
el Element

the DOM element to be copied

Returns:

a shallow copy of the element with no children but with attributes

Type
Element

(static) getCaretPosition(elem) → {Integer}

Source:

Method that returns the current caret (cursor) position of a given element.
Source: http://stackoverflow.com/questions/2897155/get-cursor-position-in-characters-within-a-text-input-field

Parameters:
Name Type Description
elem element

the DOM element to check caret position

Returns:

the cursor index of the given element.

Type
Integer

(static) hotswap(currentNode, newNode, ignoreElements)

Source:

Changes DOM Nodes that are different, and leaves others untouched.

Algorithm:
Delegates to a particular swapMethod, depending on the Node type.
Recurses for nested Element Nodes only.
There is always room for optimizing this method.

Parameters:
Name Type Description
currentNode Node

The DOM Node corresponding to the existing page content to update

newNode Node

The detached DOM Node representing the desired DOM subtree

ignoreElements Array

Array of jQuery selectors for DOM Elements to ignore during render. Can be an expensive check.

(static) hotswapKeepCaret(currentNode, newNode, ignoreElements)

Source:

Call this.hotswap but also keeps the caret position the same

Parameters:
Name Type Description
currentNode Node

The DOM Node corresponding to the existing page content to update

newNode Node

The detached DOM Node representing the desired DOM subtree

ignoreElements Array

Array of jQuery selectors for DOM Elements to ignore during render. Can be an expensive check.

(static) render($el, template, context, optsopt)

Source:

Performs efficient re-rendering of a template.

Parameters:
Name Type Attributes Description
$el external:jQuery

The Element to render into

template external:Handlebars-Template

The HBS template to apply

context Object

The context object to pass to the template

opts Object <optional>

Other options

Properties
Name Type Attributes Default Description
force boolean <optional>
false

Will forcefully do a fresh render and not a diff-render

newHTML string <optional>

If you pass in newHTML, it will not use the template or context, but use this instead.

ignoreElements Array <optional>

jQuery selectors of DOM elements to ignore during render. Can be an expensive check

(static) setCaretPosition(elem, caretPos) → {Integer}

Source:

Method that returns sets the current caret (cursor) position of a given element and puts it in focus.
Source: http://stackoverflow.com/questions/512528/set-cursor-position-in-html-textbox

Parameters:
Name Type Description
elem element
caretPos Integer

The caret index to set

Returns:

the cursor index of the given element.

Type
Integer

(static) supportsSelection(el) → {boolean}

Source:

Determines if the element supports selection. As per spec, https://html.spec.whatwg.org/multipage/forms.html#do-not-apply
selection is only allowed for text, search, tel, url, password. Other input types will throw an exception in chrome

Parameters:
Name Type Description
el Element

the DOM element to check

Returns:

boolean indicating whether or not the selection is allowed for {Element} el

Type
boolean