html.js 7.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. module('html');
  2. test("formatUrl", function() {
  3. equals(K.formatUrl(K.query("#test01").value, "absolute", 'http://localhost', '/ke/test'), '/ke/images/xxx.gif');
  4. equals(K.formatUrl(K.query("#test01").value, "relative", 'http://localhost', '/ke/test'), '../images/xxx.gif');
  5. equals(K.formatUrl(K.query("#test01").value, "domain", 'http://localhost', '/ke/test'), 'http://localhost/ke/images/xxx.gif');
  6. equals(K.formatUrl(K.query("#test01").value), '../images/xxx.gif');
  7. equals(K.formatUrl(K.query("#test02").value, "absolute", 'http://localhost:8080', '/ke/test'), '/images/xxx.gif');
  8. equals(K.formatUrl(K.query("#test02").value, "relative", 'http://localhost:8080', '/ke/test'), '../../images/xxx.gif');
  9. equals(K.formatUrl(K.query("#test02").value, "domain", 'http://localhost:8080', '/ke/test'), 'http://localhost:8080/images/xxx.gif');
  10. equals(K.formatUrl(K.query("#test02").value), './../../images/xxx.gif');
  11. equals(K.formatUrl(K.query("#test03").value, "absolute", 'http://localhost', '/ke/test'), '/ke/images/xxx.gif');
  12. equals(K.formatUrl(K.query("#test03").value, "relative", 'http://localhost', '/ke/test'), '../images/xxx.gif');
  13. equals(K.formatUrl(K.query("#test03").value, "domain", 'http://localhost', '/ke/test'), 'http://localhost/ke/images/xxx.gif');
  14. equals(K.formatUrl(K.query("#test03").value), '/ke/images/xxx.gif');
  15. equals(K.formatUrl(K.query("#test04").value, "absolute", 'http://localhost', '/ke/test'), '/ke/images/xxx.gif');
  16. equals(K.formatUrl(K.query("#test04").value, "relative", 'http://localhost', '/ke/images'), 'xxx.gif');
  17. equals(K.formatUrl(K.query("#test04").value, "domain", 'http://localhost', '/ke'), 'http://localhost/ke/images/xxx.gif');
  18. equals(K.formatUrl(K.query("#test04").value), 'http://localhost/ke/images/xxx.gif');
  19. equals(K.formatUrl(K.query("#test05").value, "absolute", 'http://localhost', '/ke'), 'http://www.163.com/images/xxx.gif');
  20. equals(K.formatUrl(K.query("#test05").value, "relative", 'http://localhost', '/ke'), 'http://www.163.com/images/xxx.gif');
  21. equals(K.formatUrl(K.query("#test05").value, "domain", 'http://localhost', '/ke'), 'http://www.163.com/images/xxx.gif');
  22. equals(K.formatUrl(K.query("#test05").value), 'http://www.163.com/images/xxx.gif');
  23. equals(K.formatUrl(K.query("#test06").value, "absolute", 'http://kindsoft.net', '/'), '/kindeditor/plugins/emoticons/etc_01.gif');
  24. equals(K.formatUrl(K.query("#test06").value, "relative", 'http://kindsoft.net', '/'), 'kindeditor/plugins/emoticons/etc_01.gif');
  25. equals(K.formatUrl(K.query("#test06").value, "domain", 'http://kindsoft.net', '/'), 'http://kindsoft.net/kindeditor/plugins/emoticons/etc_01.gif');
  26. equals(K.formatUrl(K.query("#test06").value), 'http://kindsoft.net/kindeditor/plugins/emoticons/etc_01.gif');
  27. equals(K.formatUrl(K.query("#test07").value, "absolute", 'http://kindsoft.net', '/'), 'mailto:test@test.com');
  28. equals(K.formatUrl(K.query("#test07").value, "relative", 'http://kindsoft.net', '/'), 'mailto:test@test.com');
  29. equals(K.formatUrl(K.query("#test07").value, "domain", 'http://kindsoft.net', '/'), 'mailto:test@test.com');
  30. equals(K.formatUrl(K.query("#test07").value), 'mailto:test@test.com');
  31. equals(K.formatUrl('http://static.domain.com/img//123.png'), 'http://static.domain.com/img/123.png');
  32. equals(K.formatUrl('data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
  33. });
  34. test("formatHtml", function() {
  35. equals(K.formatHtml(K.query("#test11").innerHTML).toLowerCase(), '<span style="color:#ff0000;"><strong>test</strong></span>');
  36. equals(K.formatHtml(K.query("#test11").innerHTML, {span:[".color"]}).toLowerCase(), '<span style="color:#ff0000;">test</span>');
  37. equals(K.formatHtml(K.query("#test11").innerHTML, {span:[".font-size", "class"]}), '<span>test</span>');
  38. equals(K.formatHtml(K.query("#test11").innerHTML, {div:[".font-size", "class"]}), 'test');
  39. equals(K.formatHtml(K.query("#test11").innerHTML, {span:["style"]}).toLowerCase(), '<span style="color:#ff0000;">test</span>');
  40. equals(K.formatHtml(K.query("#test11").innerHTML, {span:[]}), '<span>test</span>');
  41. equals(K.formatHtml(K.query("#test12").innerHTML).toLowerCase(), '123<div class="spanclass" style="color:#ff0000;background-color:#00ff00;font-size:18px;font-weight:bold;">test</div>123');
  42. equals(K.formatHtml(K.query("#test12").innerHTML, {span:[".color"]}), '123test123');
  43. equals(K.formatHtml(K.query("#test12").innerHTML, {div:[".font-size", "class"]}), '123<div class="spanclass" style="font-size:18px;">test</div>123');
  44. equals(K.formatHtml(K.query("#test12").innerHTML, {div:[".color"]}).toLowerCase(), '123<div style="color:#ff0000;">test</div>123');
  45. equals(K.formatHtml(K.query("#test12").innerHTML, {div:[".color", ".font-weight"]}).toLowerCase(), '123<div style="color:#ff0000;font-weight:bold;">test</div>123');
  46. equals(K.formatHtml(K.query("#test13").innerHTML), '<input type="checkbox" id="chk" value="1" checked="checked" /> <label for="chk"><strong>checkbox</strong></label>');
  47. equals(K.formatHtml(K.query("#test13").innerHTML, {input:["type", "value"]}), '<input type="checkbox" value="1" /> checkbox');
  48. equals(K.formatHtml(K.query("#test13").innerHTML, {input:["checked"],label:[]}), '<input checked="checked" /> <label>checkbox</label>');
  49. equals(K.formatHtml(K.query("#test13").innerHTML, {}), 'checkbox');
  50. equals(K.formatHtml(K.query("#test14").innerHTML, null, "relative"), '<img src="../plugins/emoticons/images/0.gif" /> test');
  51. equals(K.formatHtml(K.query("#test16").innerHTML), '<span style="font-family:times new roman;"><strong>test</strong></span>');
  52. equals(K.formatHtml(K.query("#test17").innerHTML), '<svg:a>test</svg:a>');
  53. equals(K.formatHtml(K.query("#test18").innerHTML), '<span style="font-family:\'Arial Black\';">ddd</span>');
  54. equals(K.formatHtml(K.query("#test19").innerHTML), '<span style="font-size:xx-large;">ddd</span>');
  55. equals(K.formatHtml(K.query("#test20").innerHTML).toLowerCase(), '<span style="color:#ff0000;">ddd</span>');
  56. equals(K.formatHtml(K.query("#test21").innerHTML), '<span style="background-color:#d8d8d8;font-family:\'Arial Black\';color:#ff0000;font-size:xx-large;">ddd</span>');
  57. equals(K.formatHtml(K.query("#test22").innerHTML, {}), '&copy;');
  58. equals(K.formatHtml('<a href="#" ""="" style="color:red;">123</a>', {a:['href']}), '<a href="#">123</a>');
  59. equals(K.formatHtml('<a href="#">123</a>', {a:['*']}), '<a href="#">123</a>');
  60. equals(K.formatHtml('<p style="text-indent:2em;"></p>'), '<p style="text-indent:2em;"><br /></p>');
  61. equals(K.formatHtml('<p style="text-indent:2em;">\t\n<br/>\n</p>'), '<p style="text-indent:2em;"><br /></p>');
  62. });
  63. test("getAttrList/getCssList", function() {
  64. var tag = '<a href="#" onclick="javascript:if(1<2)alert(1);" style="font-family:\'Arial Black\';">';
  65. var attrList = K.getAttrList(tag);
  66. equals(attrList.href, '#');
  67. equals(attrList.onclick, 'javascript:if(1<2)alert(1);');
  68. var cssList = K.getCssList(attrList.style);
  69. equals(cssList['font-family'], '\'Arial Black\'');
  70. });