Advertisement
Guest User

Text Editor

a guest
Apr 24th, 2011
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <style>
  5.             *
  6.             {
  7.                 margin:0px;
  8.                 padding:0px;
  9.             }
  10.             #editor
  11.             {
  12.                 width:610px;
  13.                 height:390px;
  14.                 margin:3% auto 0px auto;
  15.                 border:1px solid #c0c0c0;
  16.                 position:relative;
  17.             }
  18.             #editor div.toolbar
  19.             {
  20.                 width:100%;
  21.                 height:30px;
  22.                 border-bottom:1px solid #c0c0c0;
  23.                 background-color:#efe5e5;
  24.                 position:relative;
  25.             }
  26.             #editor ul
  27.             {
  28.                 display:block;
  29.                 float:left;
  30.                 margin-top:4px;
  31.             }
  32.             #editor li
  33.             {
  34.                 height:20px;
  35.                 margin-left:4px;
  36.                 border:1px solid #b0b0b0;
  37.                 background-color:#efefef;
  38.                 line-height:20px;
  39.                 text-align:center;
  40.                 font-family:verdana;
  41.                 font-size:12px;
  42.                 list-style-type:none;
  43.                 display:block;
  44.                 float:left;
  45.                
  46.             }
  47.             #editor li:hover
  48.             {
  49.                 color:#000;
  50.                 background-color:#f5f5f5;
  51.                 cursor:pointer;
  52.             }
  53.             #editor li.small_button
  54.             {
  55.                 width:20px;
  56.             }
  57.             #editor #code_pane
  58.             {
  59.                 width:610px;
  60.                 height:390px;
  61.                 display:none;
  62.                 border-style:none;
  63.             }
  64.             #editor div.mode_tab
  65.             {
  66.                 height:20px;
  67.                 position:absolute;
  68.                 bottom:-20px;
  69.                 right:8px;
  70.                 z-index:1;
  71.             }
  72.             #editor div.mode_tab div
  73.             {
  74.                 width:70px;
  75.                 height:20px;
  76.                 float:right;
  77.                 font-family:verdana;
  78.                 font-size:12px;
  79.                 color:#505050;
  80.                 line-height:20px;
  81.                 margin:auto -1px auto auto;
  82.                 text-align:center;
  83.                 margin-left:4px;
  84.                 border:1px solid #c0c0c0;
  85.                 cursor:pointer;
  86.                 background-color:#efe5e5;
  87.             }
  88.             #editor div.mode_tab div.active
  89.             {
  90.                 color:#000000;
  91.                 border:1px solid #c0c0c0;
  92.                 border-top-color:#ffffff;
  93.                 cursor:pointer;
  94.                 background-color:#ffffff !important;
  95.                 z-index:2;
  96.             }
  97.             div.overlay
  98.             {
  99.                 display:none;
  100.                 position:absolute;
  101.                 top:0px;
  102.                 left:0px;
  103.                 width:100%;
  104.                 height:100%;
  105.             }
  106.             .popbox
  107.             {
  108.                 width:265px;
  109.                 height:100px;
  110.                 border:1px solid #c0c0c0;
  111.                 margin:20% auto auto auto;
  112.                 background-color:#ffffff;
  113.             }
  114.             .popbox td.title
  115.             {
  116.                 text-align:center;
  117.                 height:20px;
  118.             }
  119.             .popbox td.title
  120.             {
  121.                 height:22px;
  122.                 background-color:#c0c0c0;
  123.             }
  124.             .popbox div.field
  125.             {
  126.                 margin-top:10px;
  127.                 margin-left:5px;
  128.             }
  129.             .popbox div.field input
  130.             {
  131.                 width:200px;
  132.                 border:1px solid #c0c0c0;
  133.             }
  134.             .popbox div.buttons
  135.             {
  136.                 margin-bottom:5px;
  137.                 padding-right:5px;
  138.             }
  139.             .popbox div.button
  140.             {
  141.                 width:60px;
  142.                 height:20px;
  143.                 border:1px solid #c0c0c0;
  144.                 text-align:center;
  145.                 line-height:20px;
  146.                 font-family:verdana;
  147.                 font-size:12px;
  148.                 background-color:#efefef;
  149.                 float:right;
  150.                 cursor:pointer;
  151.                 margin-left:5px;
  152.                 margin-bottom:10px;
  153.             }
  154.         </style>
  155.         <script>
  156.             editor = {}
  157.             editor.start = function(){
  158.                 var design_pane = document.getElementById('design_pane').contentWindow.document;
  159.                 var code_pane   = document.getElementById('code_pane');
  160.                 if(design_pane.body.innerHTML!=''){
  161.                     design_pane.designMode = "on";
  162.                 }
  163.                 else{
  164.                     design_pane.body.focus();
  165.                     design_pane.body.innerHTML = "Default content.";
  166.                     design_pane.designMode = "on";
  167.                 }
  168.             }
  169.             editor.cmd = function(cmd,opt){
  170.                 if(cmd == 'linkBox'){
  171.                     var linkbox = document.getElementById('editor_insertlink');
  172.                     var linkbox_ok = document.getElementById('editor_insertlink_ok');
  173.                     linkbox.style.display = "block";
  174.                     linkbox_ok.onclick = function(){
  175.                         var linkbox_field = document.getElementById('editor_insertlink_field').value;
  176.                         if(linkbox_field != ''){
  177.                             var design_pane = document.getElementById('design_pane').contentWindow.document;
  178.                             design_pane.execCommand('createLink',false,linkbox_field);
  179.                             editor.closeBox('editor_insertlink');
  180.                         }
  181.                     }
  182.                 }
  183.                 else{
  184.                     var design_pane = document.getElementById('design_pane').contentWindow.document;
  185.                     design_pane.body.focus();
  186.                     design_pane.execCommand(cmd,false,opt);
  187.                     design_pane.body.focus();
  188.                 }
  189.             }
  190.             editor.code = function(clicked){
  191.                 var toolbar = document.getElementById('toolbar');
  192.                 var design_pane = document.getElementById('design_pane');
  193.                 var code_pane   = document.getElementById('code_pane');
  194.                 var mode_tab = document.getElementById('mode_tab');
  195.                 var tabs = mode_tab.getElementsByTagName('div');
  196.                 code_pane.value = design_pane.contentWindow.document.body.innerHTML;
  197.                 toolbar.style.display = "none";
  198.                 design_pane.style.display = "none";
  199.                 code_pane.style.display = "block";
  200.                 for(i=0;i<tabs.length;i++){
  201.                     tabs[i].className = "";
  202.                 }
  203.                 clicked.className = "active";
  204.             }
  205.             editor.design = function(clicked){
  206.                 var toolbar = document.getElementById('toolbar');
  207.                 var design_pane = document.getElementById('design_pane');
  208.                 var code_pane   = document.getElementById('code_pane');
  209.                 var mode_tab = document.getElementById('mode_tab');
  210.                 var tabs = mode_tab.getElementsByTagName('div');
  211.                 design_pane.contentWindow.document.body.innerHTML = code_pane.value;
  212.                 toolbar.style.display = "block";
  213.                 design_pane.style.display = "block";
  214.                 code_pane.style.display = "none";
  215.                 for(i=0;i<tabs.length;i++){
  216.                     tabs[i].className = "";
  217.                 }
  218.                 clicked.className = "active";
  219.             }
  220.             editor.closeBox = function(boxname){
  221.                 var boxob = document.getElementById(boxname);
  222.                 boxob.style.display = "none";
  223.             }
  224.         </script>
  225.     </head>
  226.     <body>
  227.         <div id="editor">
  228.             <div id="toolbar" class="toolbar">
  229.                 <ul>
  230.                     <li class="small_button" onclick="editor.cmd('bold')" title="Bold"><b>B</b></li>
  231.                     <li class="small_button" onclick="editor.cmd('italic')" title="Italic"><i>I</i></li>
  232.                     <li class="small_button" onclick="editor.cmd('underline')" title="Underline"><u>U</u></li>
  233.                     <li class="small_button" onclick="editor.cmd('justifyLeft')" title="Left">&laquo;</li>
  234.                     <li class="small_button" onclick="editor.cmd('justifyRight')" title="Right">&raquo;</li>
  235.                     <li class="small_button" onclick="editor.cmd('justifyCenter')" title="Center">-</li>
  236.                     <li class="small_button" onclick="editor.cmd('justifyFull')" title="Justify">=</li>
  237.                     <li class="small_button" onclick="editor.cmd('insertUnorderedList')" title="Unordered List">&middot;</li>
  238.                     <li class="small_button" onclick="editor.cmd('linkBox')" title="Create Link">@</li>
  239.                 </ul>
  240.                 <ul>
  241.                     <li onclick="editor.start()" title="Start editing">&nbsp;Start&nbsp;</li>
  242.                 </ul>
  243.             </div>
  244.             <div>
  245.                 <iframe id="design_pane" width="610" height="359" frameborder="no"></iframe>
  246.                 <textarea id="code_pane"></textarea>
  247.             </div>
  248.             <div id="mode_tab" class="mode_tab">
  249.                 <div onclick="editor.code(this)">Code</div><div onclick="editor.design(this)" class="active">Design</div>
  250.             </div>
  251.             <div id="editor_insertlink" class="overlay">
  252.                 <table class="popbox" cellspacing="0" cellpadding="0">
  253.                     <form>
  254.                         <tr>
  255.                             <td class="title" colspan="3">Create Link</td>
  256.                         </tr>
  257.                         <tr>
  258.                             <td>&nbsp;</td><td><div class="field">URL&nbsp;:&nbsp;<input type="text" id="editor_insertlink_field" /></div></td><td>&nbsp;</td>
  259.                         </tr>
  260.                         <tr>
  261.                             <td>&nbsp;</td>
  262.                             <td>
  263.                                 <div class="buttons">
  264.                                     <div class="button" onclick="editor.closeBox('editor_insertlink')">Cancel</div>
  265.                                     <div class="button" id="editor_insertlink_ok">OK</div>
  266.                                 </div>
  267.                             </td>
  268.                             <td>&nbsp;</td>
  269.                         </tr>
  270.                     </form>
  271.                 </table>
  272.             </div>
  273.         </div>
  274.     </body>
  275. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement