editor.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. module("editor");
  2. KindEditor.ready(function (K) {
  3. var editor = K.create('#content1', {
  4. basePath : '../',
  5. filterMode : false,
  6. wellFormatMode : false
  7. });
  8. var editor2 = K.create('#content2', {
  9. basePath : '../',
  10. filterMode : false,
  11. wellFormatMode : false
  12. });
  13. test("K.instances", function() {
  14. ok(editor == K.instances[0]);
  15. ok(editor2 == K.instances[1]);
  16. });
  17. test("editor.html", function() {
  18. editor.html(undefined);
  19. equals(editor.html(), '');
  20. editor.html(null);
  21. equals(editor.html(), '');
  22. editor.html('<h3>abc</h3>');
  23. equals(editor.html(), '<h3>abc</h3>');
  24. editor.html('<div class="aaa bbb ccc">abc</div>');
  25. equals(editor.html(), '<div class="aaa bbb ccc">abc</div>');
  26. editor.html('');
  27. equals(editor.html(), '');
  28. editor.html('<div class="aaa bbb ccc">abc</div>');
  29. equals(editor.html(), '<div class="aaa bbb ccc">abc</div>');
  30. editor.html('<p>abc</p>');
  31. equals(editor.html(), '<p>abc</p>');
  32. editor.html('<br /><noscript><img src="" /></noscript>');
  33. equals(editor.html(), '<br /><noscript><img src="" /></noscript>');
  34. editor.html('<a href="test.php?id=1&name=test">test</a>');
  35. equals(editor.html(), '<a href="test.php?id=1&name=test">test</a>');
  36. editor.html('<a href="$abc$$">test</a>');
  37. equals(editor.html(), '<a href="$abc$$">test</a>');
  38. editor.html('<img src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1" />');
  39. equals(editor.html(), '<img src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1" />');
  40. editor.html('<iframe src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1"></iframe>');
  41. equals(editor.html(), '<iframe src="http://localhost/minglsjy.33/trunk/index.php?r=file/pic&f=24&t=1"></iframe>');
  42. 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>');
  43. 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>');
  44. editor.html('<input disabled="disabled" checked="checked" type="radio" />');
  45. equals(editor.html(), '<input disabled="disabled" checked="checked" type="radio" />');
  46. editor.html('<input style="display:none;" type="file" />');
  47. equals(editor.html(), '<input style="display:none;" type="file" />');
  48. editor.html('<input type="file" />');
  49. equals(editor.html(), '<input type="file" />');
  50. editor.html('<input type="text" />');
  51. equals(editor.html(), '<input type="text" />');
  52. });
  53. test("editor.text", function() {
  54. editor.html('<h3>abc</h3>');
  55. equals(editor.text(), 'abc');
  56. editor.html('<div class="aaa bbb ccc">abc</div>');
  57. equals(editor.text(), 'abc');
  58. editor.text('<p class="a"></p>');
  59. equals(editor.text(), '&lt;p class="a"&gt;&lt;/p&gt;');
  60. editor.text('');
  61. equals(editor.text(), '');
  62. });
  63. test("editor.insertHtml", function() {
  64. editor.html('<h3 id="test-h3">abc</h3>');
  65. var h3 = K('#test-h3', editor.edit.doc);
  66. editor.cmd.range.selectNodeContents(h3[0]);
  67. editor.cmd.select();
  68. editor.insertHtml('<a href="abc">abc</a>');
  69. equals(editor.html(), '<h3 id="test-h3"><a href="abc">abc</a></h3>');
  70. editor.html('');
  71. });
  72. test("editor.selectedHtml", function() {
  73. editor.html('<span id="test">abc</span>');
  74. var span = K('#test', editor.edit.doc);
  75. editor.cmd.range.setStart(span.first()[0], 0).setEnd(span.first()[0], 2);
  76. editor.cmd.select();
  77. equals(editor.selectedHtml().replace(/<.+?>/g, ''), 'ab');
  78. editor.html('');
  79. });
  80. test("editor.appendHtml", function() {
  81. editor.html('');
  82. editor.appendHtml('<h3>abc</h3>');
  83. equals(editor.html(), '<h3>abc</h3>');
  84. editor.appendHtml('<div class="aaa bbb ccc">abc</div>');
  85. equals(editor.html(), '<h3>abc</h3><div class="aaa bbb ccc">abc</div>');
  86. editor.html('');
  87. editor.appendHtml('<a href="abc">abc</a>');
  88. equals(editor.html(), '<a href="abc">abc</a>');
  89. });
  90. test("editor.isEmpty", function() {
  91. editor.html('<h3>abc</h3>');
  92. ok(editor.isEmpty() === false);
  93. editor.html('<h3></h3>');
  94. ok(editor.isEmpty() === true);
  95. editor.html('<img src="" />');
  96. ok(editor.isEmpty() === false);
  97. editor.html('');
  98. });
  99. test("editor.count", function() {
  100. editor.html('<h3>abc</h3>');
  101. ok(editor.count('html') === 12);
  102. ok(editor.count('text') === 3);
  103. editor.html('<h3></h3>');
  104. ok(editor.count('html') === 9);
  105. ok(editor.count('text') === 0);
  106. editor.html('<img src="" />');
  107. ok(editor.count('html') === 14);
  108. ok(editor.count('text') === 1);
  109. editor.html('');
  110. });
  111. });