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
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. |
Methods
addEventOutput(eventName, opt_outputNameopt)
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
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:
- Type
- string
getTextNode() → {Text}
Returns:
- Type
- Text
setText(txt)
Parameters:
Name | Type | Description |
---|---|---|
txt |
string | the value to set |