forked from kindsoft/kindeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.js
140 lines (111 loc) · 4.38 KB
/
editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module("editor");
KindEditor.ready(function (K) {
var editor = K.create('#content1', {
basePath : '../',
filterMode : false,
wellFormatMode : false
});
var editor2 = K.create('#content2', {
basePath : '../',
filterMode : false,
wellFormatMode : false
});
test("K.instances", function() {
ok(editor == K.instances[0]);
ok(editor2 == K.instances[1]);
});
test("editor.html", function() {
editor.html(undefined);
equals(editor.html(), '');
editor.html(null);
equals(editor.html(), '');
editor.html('<h3>abc</h3>');
equals(editor.html(), '<h3>abc</h3>');
editor.html('<div class="aaa bbb ccc">abc</div>');
equals(editor.html(), '<div class="aaa bbb ccc">abc</div>');
editor.html('');
equals(editor.html(), '');
editor.html('<div class="aaa bbb ccc">abc</div>');
equals(editor.html(), '<div class="aaa bbb ccc">abc</div>');
editor.html('<p>abc</p>');
equals(editor.html(), '<p>abc</p>');
editor.html('<br /><noscript><img src="" /></noscript>');
equals(editor.html(), '<br /><noscript><img src="" /></noscript>');
editor.html('<a href="test.php?id=1&name=test">test</a>');
equals(editor.html(), '<a href="test.php?id=1&name=test">test</a>');
editor.html('<a href="$abc$$">test</a>');
equals(editor.html(), '<a href="$abc$$">test</a>');
editor.html('<img src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1" />');
equals(editor.html(), '<img src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1" />');
editor.html('<iframe src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1"></iframe>');
equals(editor.html(), '<iframe src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1"></iframe>');
editor.html('<a href="http://linux-wiki.cn/wiki/zh-hans/%E4%BD%BF%E7%94%A83G%E4%B8%8A%E7%BD%91%E5%8D%A1%E6%9">test</a>');
equals(editor.html(), '<a href="http://linux-wiki.cn/wiki/zh-hans/%E4%BD%BF%E7%94%A83G%E4%B8%8A%E7%BD%91%E5%8D%A1%E6%9">test</a>');
editor.html('<input disabled="disabled" checked="checked" type="radio" />');
equals(editor.html(), '<input disabled="disabled" checked="checked" type="radio" />');
editor.html('<input style="display:none;" type="file" />');
equals(editor.html(), '<input style="display:none;" type="file" />');
editor.html('<input type="file" />');
equals(editor.html(), '<input type="file" />');
editor.html('<input type="text" />');
equals(editor.html(), '<input type="text" />');
});
test("editor.text", function() {
editor.html('<h3>abc</h3>');
equals(editor.text(), 'abc');
editor.html('<div class="aaa bbb ccc">abc</div>');
equals(editor.text(), 'abc');
editor.text('<p class="a"></p>');
equals(editor.text(), '<p class="a"></p>');
editor.text('');
equals(editor.text(), '');
});
test("editor.insertHtml", function() {
editor.html('<h3 id="test-h3">abc</h3>');
var h3 = K('#test-h3', editor.edit.doc);
editor.cmd.range.selectNodeContents(h3[0]);
editor.cmd.select();
editor.insertHtml('<a href="abc">abc</a>');
equals(editor.html(), '<h3 id="test-h3"><a href="abc">abc</a></h3>');
editor.html('');
});
test("editor.selectedHtml", function() {
editor.html('<span id="test">abc</span>');
var span = K('#test', editor.edit.doc);
editor.cmd.range.setStart(span.first()[0], 0).setEnd(span.first()[0], 2);
editor.cmd.select();
equals(editor.selectedHtml().replace(/<.+?>/g, ''), 'ab');
editor.html('');
});
test("editor.appendHtml", function() {
editor.html('');
editor.appendHtml('<h3>abc</h3>');
equals(editor.html(), '<h3>abc</h3>');
editor.appendHtml('<div class="aaa bbb ccc">abc</div>');
equals(editor.html(), '<h3>abc</h3><div class="aaa bbb ccc">abc</div>');
editor.html('');
editor.appendHtml('<a href="abc">abc</a>');
equals(editor.html(), '<a href="abc">abc</a>');
});
test("editor.isEmpty", function() {
editor.html('<h3>abc</h3>');
ok(editor.isEmpty() === false);
editor.html('<h3></h3>');
ok(editor.isEmpty() === true);
editor.html('<img src="" />');
ok(editor.isEmpty() === false);
editor.html('');
});
test("editor.count", function() {
editor.html('<h3>abc</h3>');
ok(editor.count('html') === 12);
ok(editor.count('text') === 3);
editor.html('<h3></h3>');
ok(editor.count('html') === 9);
ok(editor.count('text') === 0);
editor.html('<img src="" />');
ok(editor.count('html') === 14);
ok(editor.count('text') === 1);
editor.html('');
});
});