editor: make toolbar icons more compact
[fnpeditor.git] / src / wlxml / extensions / comments / comments.js
1 define(function() {
2     
3 'use strict';
4
5 var extension = {wlxmlClass: {comment: {
6     methods: {
7         describesParent: true,
8         getText: function() {
9             var text = '';
10             this.contents()
11                 .filter(function(node) {
12                     /* globals Node */
13                     return node && node.nodeType === Node.TEXT_NODE;
14                 })
15                 .forEach(function(node) {
16                     text = text + node.getText();
17                 });
18             return text;
19         },
20         setText: function(text) {
21             var contents = this.contents();
22             if(contents.length === 1 && contents[0].nodeType === Node.TEXT_NODE) {
23                 contents[0].setText(text);
24             } else {
25                 contents.forEach(function(node) {
26                     node.detach();
27                 });
28                 this.append({text: text});
29             }
30         }
31     }
32 }}};
33
34 return extension;
35
36 });