Class: Text

html.Text(textOrTextNode, opt_eventOutputsopt)

Wrapper capsule for DOM Text nodes. Can be used either to wrap an existing Text node or to create a new one (and wrap it).

The Text capsule has one loop named loop that represents the Text node as well as methods that work with the text node.

Constructor

new Text(textOrTextNode, opt_eventOutputsopt)

When creating an instance of Text capsule you either create new Text node or wrap an already existing Text node. In any case, newly created capsule behaves as a wrapper for the underlying Text node. Creating an instance of Text capsule is simple, although there are two different legal ways to do it. See examples bellow for more details.

Parameters:
Name Type Attributes Description
textOrTextNode string | Text a) the text content of a Text node to create or b) the text node to wrap
opt_eventOutputs Array.<string> <optional>
optional array of events (e.g. ['DOMCharacterDataModified']) for which output operations should be created (see addEventOutput)
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Examples

Creating new Text capsule to create and wrap new (DOM) Text node

let text = new html.Text('Hello world!');

Creating new Text capsule as a wrapper of an existing (DOM) Text node

let existingTextNode = document.createTextNode('Hello world'); // or document.getElementById or whatever...
let text = new html.Text(existingTextNode);

Specifying output operations (optional in both ways of instantiation)

let text = new html.Text('Hello world!', ['DOMCharacterDataModified']); // reacts on text modification
text.DOMCharacterDataModified.wire(function(e){
    alert('Text modified!');
});

Members

Collection of Loops

Properties:
Name Type Description
loop module:capsula.Loop A loop that represents the DOM Text node of this capsule.
Since:
  • 0.1.0
Source:

Methods

addEventOutput(eventName, opt_outputNameopt)

Creates new output operation for the given event name (e.g. 'DOMCharacterDataModified'). Each time the event is captured output operation is called with event object as a parameter. If the output name is provided in the second argument, the output operation would take that name, otherwise it would default to the event name.
Parameters:
Name Type Attributes Description
eventName string event for which to create output operation, e.g. 'DOMCharacterDataModified'
opt_outputName string <optional>
output operation name, if not specified the default value is the eventName
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Example

Reacting on DOMCharacterDataModified event

let text = new html.Text('Hello world!');
...
text.addEventOutput('DOMCharacterDataModified', 'textModified');
...
text.setText('Hello modified world!');
...
text.textModified.wire(function(e){
    alert('I have just been modified.');
});

getText() → {string}

Returns the text content of the wrapped Text node.
Since:
  • 0.1.0
Source:
Returns:
the text content of the wrapped Text node
Type
string

getTextNode() → {Text}

Returns the wrapped Text node.
Since:
  • 0.1.0
Source:
Returns:
the wrapped (DOM) Text node
Type
Text

setText(txt)

Sets the text content to the wrapped Text node.
Parameters:
Name Type Description
txt string the value to set
Since:
  • 0.1.0
Source: