- setText: function(text) {
- //console.log('smartxml: ' + text);
- this.nativeNode.data = text;
- this.triggerTextChangeEvent();
- },
-
- appendText: function(text) {
- this.nativeNode.data = this.nativeNode.data + text;
- this.triggerTextChangeEvent();
- },
-
- prependText: function(text) {
- this.nativeNode.data = text + this.nativeNode.data;
- this.triggerTextChangeEvent();
- },
-
- wrapWith: function(desc) {
- if(typeof desc.start === 'number' && typeof desc.end === 'number') {
- return this.document._wrapText({
- inside: this.parent(),
- textNodeIdx: this.parent().indexOf(this),
- offsetStart: Math.min(desc.start, desc.end),
- offsetEnd: Math.max(desc.start, desc.end),
- _with: {tagName: desc.tagName, attrs: desc.attrs}
- });
- } else {
- return DocumentNode.prototype.wrapWith.call(this, desc);
- }
- },
-
- split: function(params) {
- var parentElement = this.parent(),
- passed = false,
- succeedingChildren = [],
- prefix = this.getText().substr(0, params.offset),
- suffix = this.getText().substr(params.offset);
-
- parentElement.contents().forEach(function(child) {
- if(passed) {
- succeedingChildren.push(child);
- }
- if(child.sameNode(this)) {
- passed = true;
- }
- }.bind(this));
-
- if(prefix.length > 0) {
- this.setText(prefix);
- }
- else {
- this.detach();
- }
-
- var attrs = {};
- parentElement.getAttrs().forEach(function(attr) {attrs[attr.name] = attr.value; });
- var newElement = this.document.createDocumentNode({tagName: parentElement.getTagName(), attrs: attrs});
- parentElement.after(newElement);
-
- if(suffix.length > 0) {
- newElement.append({text: suffix});
- }
- succeedingChildren.forEach(function(child) {
- newElement.append(child);
- });