PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/sunteks/index.html

https://bitbucket.org/Rabitya/waw
HTML | 217 lines | 72 code | 2 blank | 143 comment | 0 complexity | bedeae07984d0f508350fea3a406533a MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Sunteks - Penyunting Teks</title>
  5. <link href="style.css" rel="stylesheet" />
  6. </head>
  7. <body onLoad="initialize()">
  8. <iframe id="colorpalette" src="color_palette.html"></iframe>
  9. <div id="main">
  10. <nav>
  11. <button class="button" onClick="formatTeks('cut')"><img src="icon/cut.png" title="Cut" /></button>
  12. <button class="button" onClick="formatTeks('copy')"><img src="icon/copy.png" title="Copy" /></button>
  13. <button class="button" onClick="formatTeks('paste')"><img src="icon/paste.png" title="Paste" /></button>
  14. <button class="button" onClick="formatTeks('undo')"><img src="icon/undo.png" title="Undo" /></button>
  15. <button class="button" onClick="formatTeks('redo')"><img src="icon/redo.png" title="Redo" /></button>
  16. &nbsp;|&nbsp;
  17. <button class="button" id="createlink" onClick="formatTeks('createlink')"><img src="icon/insert_link.png" title="Insert Link" /></button>
  18. <button class="button" id="insertimage" onClick="formatTeks('insertimage')"><img src="icon/insert_image.png" title="Insert Image" /></button>
  19. <button class="button" id="createtable" onClick="formatTeks('createtable')"><img src="icon/table.png" title="Insert Table" /></button>
  20. </nav>
  21. <nav>
  22. <select id="block" class="select" onChange="formatTeks('formatblock',this[this.selectedIndex].value)">
  23. <option value="<p>">Normal</option>
  24. <option value="<p>">Paragraph</option>
  25. <option value="<h1>">Heading 1</option>
  26. <option value="<h2>">Heading 2</option>
  27. <option value="<h3>">Heading 3</option>
  28. <option value="<h4>">Heading 4</option>
  29. <option value="<h5>">Heading 5</option>
  30. <option value="<h6>">Heading 6</option>
  31. <option value="<blockquote>">Blockquote</option>
  32. <option value="<address>">Address</option>
  33. <option value="<pre>">Formatted</option>
  34. </select>
  35. <select id="fonts" class="select" onChange="formatTeks('fontname',this[this.selectedIndex].value)">
  36. <option value="Arial">Arial</option>
  37. <option value="Comic Sans MS">Comic Sans MS</option>
  38. <option value="Courier New">Courir New</option>
  39. <option value="Monotype Corsiva">Monotype Corsiva</option>
  40. <option value="Tahoma">Tahoma</option>
  41. <option value="Times">Times New Roman</option>
  42. </select>
  43. <select id="size" class="select" onChange="formatTeks('fontsize',this[this.selectedIndex].value)">
  44. <option value="1">1</option>
  45. <option value="2">2</option>
  46. <option value="3">3</option>
  47. <option value="4">4</option>
  48. <option value="5">5</option>
  49. </select>
  50. <button class="button" onClick="formatTeks('bold')"><img src="icon/bold.png" title="Bold" /></button>
  51. <button class="button" onClick="formatTeks('italic')"><img src="icon/italic.png" title="Italic" /></button>
  52. <button class="button" onClick="formatTeks('underline')"><img src="icon/underline.png" title="Underline" /></button>
  53. <button class="button" id="forecolor" onClick="formatTeks('forecolor')"><img src="icon/select_color_text.png" title="Font Color" /></button>
  54. <button class="button" id="hilitecolor" onClick="formatTeks('hilitecolor')"><img src="icon/select_background_color.png" title="Highlight Color" /></button>
  55. <button class="button" onClick="formatTeks('justifyleft')"><img src="icon/align_left.png" title="Align Left" /></button>
  56. <button class="button" onClick="formatTeks('justifycenter')"><img src="icon/align_center.png" title="Align Center" /></button>
  57. <button class="button" onClick="formatTeks('justifyright')"><img src="icon/align_right.png" title="Align Right" /></button>
  58. <button class="button" onClick="formatTeks('strikethrough')"><img src="icon/strike_through.png" title="Strike Through" /></button>
  59. <button class="button" onClick="formatTeks('subscript')"><img src="icon/subscript.png" title="Subscript" /></button>
  60. <button class="button" onClick="formatTeks('superscript')"><img src="icon/superscript.png" title="Superscript" /></button>
  61. &nbsp;|&nbsp;
  62. <button class="button" onClick="formatTeks('insertorderedlist')"><img src="icon/numbered_list.png" title="Insert Numbered List" /></button>
  63. <button class="button" onClick="formatTeks('insertunorderedlist')"><img src="icon/bulleted_list.png" title="Insert Bulleted List" /></button>
  64. <button class="button" onClick="formatTeks('outdent')"><img src="icon/decrease_indent.png" title="Outdent" /></button>
  65. <button class="button" onClick="formatTeks('indent')"><img src="icon/increase_indent.png" title="Indent" /></button>
  66. </nav>
  67. <iframe id="sunTeks"></iframe>
  68. </div>
  69. <script>
  70. <!--
  71. sunTeks.document.designMode = "on";
  72. sunTeks.document.open();
  73. sunTeks.document.write('<head><style type="text/css">body{font-family:arial;font-size:12px;}</style></head>');
  74. sunTeks.document.close();
  75. function dismisscolorpalette() {
  76. document.getElementById("colorpalette").style.visibility = "hidden";
  77. }
  78. function initialize() {
  79. document.getElementById("block").selectedIndex = 0;
  80. document.getElementById("fonts").selectedIndex = 0;
  81. document.getElementById("size").selectedIndex = 0;
  82. if (document.addEventListener) {
  83. document.addEventListener("mousedown", dismisscolorpalette, true);
  84. document.getElementById("sunTeks").contentWindow.document.addEventListener("mousedown", dismisscolorpalette, true);
  85. document.addEventListener("keypress", dismisscolorpalette, true);
  86. document.getElementById("sunTeks").contentWindow.document.addEventListener("keypress", dismisscolorpalette, true);
  87. } else if (document.attachEvent) {
  88. document.attachEvent("mousedown", dismisscolorpalette, true);
  89. document.getElementById("sunTeks").contentWindow.document.attachEvent("mousedown", dismisscolorpalette, true);
  90. document.attachEvent("keypress", dismisscolorpalette, true);
  91. document.getElementById("sunTeks").contentWindow.document.attachEvent("keypress", dismisscolorpalette, true);
  92. }
  93. sunTeks.focus();
  94. }
  95. function getOffsetTop(elm) {
  96. var mOffsetTop = elm.offsetTop;
  97. var mOffsetParent = elm.offsetParent;
  98. while(mOffsetParent) {
  99. mOffsetTop += mOffsetParent.offsetTop;
  100. mOffsetParent = mOffsetParent.offsetParent;
  101. }
  102. return mOffsetTop;
  103. }
  104. function getOffsetLeft(elm) {
  105. var mOffsetLeft = elm.offsetLeft;
  106. var mOffsetParent = elm.offsetParent;
  107. while(mOffsetParent) {
  108. mOffsetLeft += mOffsetParent.offsetLeft;
  109. mOffsetParent = mOffsetParent.offsetParent;
  110. }
  111. return mOffsetLeft;
  112. }
  113. function insertNodeAtSelection(win, insertNode) {
  114. // get current selection
  115. var sel = win.getSelection();
  116. // get the first range of the selection
  117. // (there's almost always only one range)
  118. var range = sel.getRangeAt(0);
  119. // deselect everything
  120. sel.removeAllRanges();
  121. // remove content of current selection from document
  122. range.deleteContents();
  123. // get location of current selection
  124. var container = range.startContainer;
  125. var pos = range.startOffset;
  126. // make a new range for the new selection
  127. range=document.createRange();
  128. if (container.nodeType==3 && insertNode.nodeType==3) {
  129. // if we insert text in a textnode, do optimized insertion
  130. container.insertData(pos, insertNode.nodeValue);
  131. // put cursor after inserted text
  132. range.setEnd(container, pos+insertNode.length);
  133. range.setStart(container, pos+insertNode.length);
  134. } else {
  135. var afterNode;
  136. if (container.nodeType==3) {
  137. // when inserting into a textnode
  138. // we create 2 new textnodes
  139. // and put the insertNode in between
  140. var textNode = container;
  141. container = textNode.parentNode;
  142. var text = textNode.nodeValue;
  143. // text before the split
  144. var textBefore = text.substr(0,pos);
  145. // text after the split
  146. var textAfter = text.substr(pos);
  147. var beforeNode = document.createTextNode(textBefore);
  148. afterNode = document.createTextNode(textAfter);
  149. // insert the 3 new nodes before the old one
  150. container.insertBefore(afterNode, textNode);
  151. container.insertBefore(insertNode, afterNode);
  152. container.insertBefore(beforeNode, insertNode);
  153. // remove the old node
  154. container.removeChild(textNode);
  155. } else {
  156. // else simply insert the node
  157. afterNode = container.childNodes[pos];
  158. container.insertBefore(insertNode, afterNode);
  159. }
  160. range.setEnd(afterNode, 0);
  161. range.setStart(afterNode, 0);
  162. }
  163. sel.addRange(range);
  164. };
  165. function formatTeks(x,y) {
  166. if ((x == "forecolor") || (x == "hilitecolor")) {
  167. parent.command = x;
  168. buttonElement = document.getElementById(x);
  169. document.getElementById("colorpalette").style.left = getOffsetLeft(buttonElement) + "px";
  170. document.getElementById("colorpalette").style.top = getOffsetTop(buttonElement) + buttonElement.offsetHeight + "px";
  171. document.getElementById("colorpalette").style.visibility = "visible";
  172. } else if (x == "createlink") {
  173. var myURL = prompt("Enter a URL:", "http://");
  174. if ((myURL != null) && (myURL != "")) {
  175. sunTeks.document.execCommand(x,false,myURL);
  176. }
  177. } else if (x == "insertimage") {
  178. myImage = prompt('Enter Image URL:', 'http://');
  179. if ((myImage != null) && (myImage != "")) {
  180. sunTeks.document.execCommand(x,false,myImage);
  181. }
  182. } else if (x == "createtable") {
  183. e = document.getElementById("sunTeks");
  184. rowstext = prompt("Enter row numbers");
  185. colstext = prompt("Enter column numbers");
  186. rows = parseInt(rowstext);
  187. cols = parseInt(colstext);
  188. if ((rows > 0) && (cols > 0)) {
  189. table = e.contentWindow.document.createElement("table");
  190. table.setAttribute("border", "1");
  191. table.setAttribute("cellpadding", "2");
  192. table.setAttribute("cellspacing", "2");
  193. tbody = e.contentWindow.document.createElement("tbody");
  194. for (var i=0; i < rows; i++) {
  195. tr =e.contentWindow.document.createElement("tr");
  196. for (var j=0; j < cols; j++) {
  197. td =e.contentWindow.document.createElement("td");
  198. br =e.contentWindow.document.createElement("br");
  199. td.appendChild(br);
  200. tr.appendChild(td);
  201. }
  202. tbody.appendChild(tr);
  203. }
  204. table.appendChild(tbody);
  205. insertNodeAtSelection(e.contentWindow, table);
  206. }
  207. } else {
  208. sunTeks.document.execCommand(x,false,y);
  209. }
  210. sunTeks.focus();
  211. }
  212. -->
  213. </script>
  214. </body>
  215. </html>