rich_text.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <script type="text/javascript">
  6. function setKeypressHandler (el, keyHandler) {
  7. if (el.addEventListener) {
  8. el.addEventListener('keypress', keyHandler, false);
  9. el.addEventListener('keydown', keyHandler, false);
  10. el.addEventListener('keyup', keyHandler, false);
  11. } else {
  12. el.attachEvent('onkeypress', keyHandler);
  13. el.attachEvent('onkeydown', keyHandler);
  14. el.attachEvent('onkeyup', keyHandler);
  15. }
  16. }
  17. function output (text) {
  18. var div = document.getElementById('debugOutput');
  19. div.appendChild(document.createTextNode(text));
  20. div.appendChild(document.createElement('br'));
  21. }
  22. window.onload = function () {
  23. // Super dumb browser detection
  24. var isIE = window.navigator.userAgent.search('MSIE') != -1
  25. || window.navigator.userAgent.search('Trident') != -1;
  26. var editFrame = document.getElementById('editFrame').contentWindow;
  27. setKeypressHandler(editFrame.document, printEventData);
  28. if (isIE) {
  29. editFrame.document.body.contentEditable = true;
  30. } else {
  31. editFrame.document.designMode = 'On';
  32. // Attach a name to the containing HTML element
  33. editFrame.document.getElementsByTagName("html")[0].id = "frameHtml";
  34. }
  35. var editDiv = document.getElementById('editDiv');
  36. setKeypressHandler(editDiv, printEventData);
  37. editDiv.contentEditable = true;
  38. editFrame.document.body.style.margin = 1;
  39. editFrame.document.body.style.padding = 0;
  40. editFrame.document.body.id = 'theBody';
  41. editDiv.style.margin = 1;
  42. editDiv.style.padding = 0;
  43. window.setTimeout(function() {
  44. var pre = document.createElement('pre');
  45. function write(text) {
  46. pre.appendChild(document.createTextNode(text));
  47. pre.appendChild(document.createElement('br'));
  48. }
  49. write('frame.contentWindow.document.designMode: ' +
  50. editFrame.document.designMode);
  51. write('frame.contentWindow.document.body.contentEditable: ' +
  52. editFrame.document.body.contentEditable);
  53. document.getElementById('editFrameInfo').appendChild(pre);
  54. pre = document.createElement('pre');
  55. write('div.ownerDocument.designMode: ' +
  56. editDiv.ownerDocument.designMode);
  57. write('div.ownerDocument.body.contentEditable: ' +
  58. editDiv.ownerDocument.body.contentEditable);
  59. write('div.contentEditable: ' +
  60. editDiv.contentEditable);
  61. document.getElementById('editDivInfo').appendChild(pre);
  62. }, 0);
  63. };
  64. function isDef(obj, prop) {
  65. return typeof obj[prop] != 'undefined';
  66. }
  67. function printEventData(e) {
  68. e = e || window.event;
  69. function write(id, text, opt_color) {
  70. var el = document.getElementById(id);
  71. el.innerHTML = '[' + text + ']';
  72. el.style.backgroundColor = opt_color || 'white';
  73. }
  74. write('type', e.type);
  75. write('tagName', isDef(e, 'target') ? e.target.tagName : e.srcElement.tagName);
  76. write('tagId', isDef(e, 'target') ? e.target.id : e.srcElement.id);
  77. write('keyidentifier', isDef(e, 'keyIdentifier') ? e.keyIdentifier : 'n/a');
  78. write('keylocation', isDef(e, 'keyLocation') ? e.keyLocation : 'n/a');
  79. write('keycode', e.keyCode);
  80. write('charcode', e.charCode);
  81. write('which', e.which);
  82. if (isDef(e, 'isTrusted')) {
  83. write('istrusted', e.isTrusted, e.isTrusted ? '#afa' : '#faa');
  84. } else {
  85. write('istrusted', 'n/a');
  86. }
  87. write('alt', e.altKey);
  88. write('ctrl', e.ctrlKey);
  89. write('shift', e.shiftKey);
  90. write('meta', e.metaKey);
  91. var s = "";
  92. for (var i in e) {
  93. s += i + ": " + e[i] + " ";
  94. }
  95. //alert(s);
  96. }
  97. </script>
  98. </head>
  99. <body>
  100. <div>
  101. <div id="butter" style="background-color: #ffa;">
  102. </div>
  103. <table width="100%">
  104. <tr valign="top">
  105. <td width="50%">
  106. <div>IFRAME</div>
  107. <iframe id="editFrame" name="editFrame" src="" height="200px" width="300px" frameborder="0" style="border: 1px solid black;">
  108. </iframe>
  109. <div id="editFrameInfo">
  110. <pre>frame.contentWindow.document.designMode: on<br>frame.contentWindow.document.body.contentEditable: false<br></pre></div>
  111. </td>
  112. <td>
  113. <div>DIV</div>
  114. <div id="editDiv" style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: black; border-right-color: black; border-bottom-color: black; border-left-color: black; height: 200px; width: 300px; overflow-x: auto; overflow-y: auto; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; margin-left: 1px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " contenteditable="true">
  115. </div>
  116. <div id="editDivInfo">
  117. <pre>div.ownerDocument.designMode: off<br>div.ownerDocument.body.contentEditable: false<br>div.contentEditable: true<br></pre></div>
  118. </td>
  119. </tr>
  120. </table>
  121. </div>
  122. <HR>
  123. <DIV style="margin: 0px;padding:0px;padding-left:10px;font-family:Courier;">
  124. <TABLE cellpadding="0" cellspacing="0" width="200px" style="font-size:9pt;">
  125. <TBODY>
  126. <TR><TD width="110px">type:</TD><TD id="type" width="90px">[]</TD></TR>
  127. <TR><TD>tagName:</TD><TD id="tagName">[]</TD></TR>
  128. <TR><TD>id:</TD><TD id="tagId">[]</TD></TR>
  129. <TR><TD>keyIdentifier:</TD><TD id="keyidentifier">[]</TD></TR>
  130. <TR><TD>keyLocation:</TD><TD id="keylocation">[]</TD></TR>
  131. <TR><TD>keyCode:</TD><TD id="keycode">[]</TD></TR>
  132. <TR><TD>charCode:</TD><TD id="charcode">[]</TD></TR>
  133. <TR><TD>which:</TD><TD id="which">[]</TD></TR>
  134. <TR><TD>isTrusted:</TD><TD id="istrusted">[]</TD></TR>
  135. <TR><TD colspan="2">---------------------</TD></TR>
  136. <TR><TD colspan="2">Modifiers</TD></TR>
  137. <TR><TD>alt:</TD><TD id="alt">[]</TD></TR>
  138. <TR><TD>ctrl:</TD><TD id="ctrl">[]</TD></TR>
  139. <TR><TD>shift:</TD><TD id="shift">[]</TD></TR>
  140. <TR><TD>meta:</TD><TD id="meta">[]</TD></TR>
  141. </TBODY>
  142. </TABLE>
  143. </DIV>
  144. </BODY></HTML>