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) |
Throws:
- Type
- Error
Examples
let text = new html.Text('Hello world!');
let existingTextNode = document.createTextNode('Hello world'); // or document.getElementById or whatever...
let text = new html.Text(existingTextNode);
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. |
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 |
Throws:
- Type
- Error
Example
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.
Returns:
the text content of the wrapped Text node
- Type
- string
getTextNode() → {Text}
Returns the wrapped Text node.
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 |