Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- *
- {
- margin:0px;
- padding:0px;
- }
- #editor
- {
- width:610px;
- height:390px;
- margin:3% auto 0px auto;
- border:1px solid #c0c0c0;
- position:relative;
- }
- #editor div.toolbar
- {
- width:100%;
- height:30px;
- border-bottom:1px solid #c0c0c0;
- background-color:#efe5e5;
- position:relative;
- }
- #editor ul
- {
- display:block;
- float:left;
- margin-top:4px;
- }
- #editor li
- {
- height:20px;
- margin-left:4px;
- border:1px solid #b0b0b0;
- background-color:#efefef;
- line-height:20px;
- text-align:center;
- font-family:verdana;
- font-size:12px;
- list-style-type:none;
- display:block;
- float:left;
- }
- #editor li:hover
- {
- color:#000;
- background-color:#f5f5f5;
- cursor:pointer;
- }
- #editor li.small_button
- {
- width:20px;
- }
- #editor #code_pane
- {
- width:610px;
- height:390px;
- display:none;
- border-style:none;
- }
- #editor div.mode_tab
- {
- height:20px;
- position:absolute;
- bottom:-20px;
- right:8px;
- z-index:1;
- }
- #editor div.mode_tab div
- {
- width:70px;
- height:20px;
- float:right;
- font-family:verdana;
- font-size:12px;
- color:#505050;
- line-height:20px;
- margin:auto -1px auto auto;
- text-align:center;
- margin-left:4px;
- border:1px solid #c0c0c0;
- cursor:pointer;
- background-color:#efe5e5;
- }
- #editor div.mode_tab div.active
- {
- color:#000000;
- border:1px solid #c0c0c0;
- border-top-color:#ffffff;
- cursor:pointer;
- background-color:#ffffff !important;
- z-index:2;
- }
- div.overlay
- {
- display:none;
- position:absolute;
- top:0px;
- left:0px;
- width:100%;
- height:100%;
- }
- .popbox
- {
- width:265px;
- height:100px;
- border:1px solid #c0c0c0;
- margin:20% auto auto auto;
- background-color:#ffffff;
- }
- .popbox td.title
- {
- text-align:center;
- height:20px;
- }
- .popbox td.title
- {
- height:22px;
- background-color:#c0c0c0;
- }
- .popbox div.field
- {
- margin-top:10px;
- margin-left:5px;
- }
- .popbox div.field input
- {
- width:200px;
- border:1px solid #c0c0c0;
- }
- .popbox div.buttons
- {
- margin-bottom:5px;
- padding-right:5px;
- }
- .popbox div.button
- {
- width:60px;
- height:20px;
- border:1px solid #c0c0c0;
- text-align:center;
- line-height:20px;
- font-family:verdana;
- font-size:12px;
- background-color:#efefef;
- float:right;
- cursor:pointer;
- margin-left:5px;
- margin-bottom:10px;
- }
- </style>
- <script>
- editor = {}
- editor.srgPos = null;
- editor.ergPos = null;
- editor.start = function(){
- var design_pane = document.getElementById('design_pane').contentWindow.document;
- var code_pane = document.getElementById('code_pane');
- design_pane.onmouseup = function(){editor.saveRange('design_pane')}
- if(design_pane.body.innerHTML!=''){
- design_pane.designMode = "on";
- }
- else{
- design_pane.body.focus();
- design_pane.body.innerHTML = "Default content.";
- design_pane.designMode = "on";
- }
- }
- editor.getRangeOffsetIE = function (r){
- var end = Math.abs(r.duplicate().moveEnd('character', -1000000));
- var range = r.duplicate();
- r.collapse( false );
- var parentElm = range.parentElement();
- var children = parentElm.getElementsByTagName('*');
- for (var i = children.length - 1; i >= 0; i--){
- range.moveToElementText( children[i] );
- if(range.inRange(r)){
- parentElm = children[i];
- break;
- }
- }
- range.moveToElementText(parentElm);
- return end - Math.abs(range.moveStart('character', -1000000));
- }
- editor.makeRange = function(iframeName){
- if(document.selection){
- if(editor.srgPos != null){
- window.frames[iframeName].focus();
- var myframe = window.frames[iframeName].document.body.createTextRange();
- myframe.moveStart("character",editor.srgPos);
- myframe.moveEnd("character",editor.ergPos);
- myframe.select();
- }
- }
- }
- editor.saveRange = function(iframeName){
- if(document.selection){
- var myframe = document.getElementById(iframeName).contentWindow.document.selection.createRange();
- if(myframe.text!=""){
- var mylenth = myframe.text.length;
- eOffset = editor.getRangeOffsetIE(myframe);
- editor.srgPos = eOffset - mylenth;
- var newrg = window.frames[iframeName].document.body.createTextRange();
- newrg.moveStart("character",0);
- newrg.moveEnd("character",0);
- fOffset = newrg.text.length;
- editor.ergPos = eOffset - fOffset;
- }
- else{
- editor.srgPos = null;
- editor.ergPos = null;
- }
- }
- }
- editor.cmd = function(iframeOb,cmd,opt){
- if(cmd == 'linkBox'){
- var linkbox = document.getElementById('editor_insertlink');
- var linkbox_ok = document.getElementById('editor_insertlink_ok');
- linkbox.style.display = "block";
- linkbox_ok.onclick = function(){
- var linkbox_field = document.getElementById('editor_insertlink_field').value;
- if(linkbox_field != ''){
- editor.cmd(iframeOb,'createLink',linkbox_field);
- editor.closeBox('editor_insertlink');
- }
- }
- }
- else{
- var design_pane = document.getElementById(iframeOb).contentWindow.document;
- editor.makeRange(iframeOb);
- design_pane.body.focus();
- design_pane.execCommand(cmd,false,opt);
- design_pane.body.focus();
- }
- }
- editor.code = function(clicked){
- var toolbar = document.getElementById('toolbar');
- var design_pane = document.getElementById('design_pane');
- var code_pane = document.getElementById('code_pane');
- var mode_tab = document.getElementById('mode_tab');
- var tabs = mode_tab.getElementsByTagName('div');
- code_pane.value = design_pane.contentWindow.document.body.innerHTML;
- toolbar.style.display = "none";
- design_pane.style.display = "none";
- code_pane.style.display = "block";
- for(i=0;i<tabs.length;i++){
- tabs[i].className = "";
- }
- clicked.className = "active";
- }
- editor.design = function(clicked){
- var toolbar = document.getElementById('toolbar');
- var design_pane = document.getElementById('design_pane');
- var code_pane = document.getElementById('code_pane');
- var mode_tab = document.getElementById('mode_tab');
- var tabs = mode_tab.getElementsByTagName('div');
- design_pane.contentWindow.document.body.innerHTML = code_pane.value;
- toolbar.style.display = "block";
- design_pane.style.display = "block";
- code_pane.style.display = "none";
- for(i=0;i<tabs.length;i++){
- tabs[i].className = "";
- }
- clicked.className = "active";
- }
- editor.closeBox = function(boxname){
- var boxob = document.getElementById(boxname);
- boxob.style.display = "none";
- }
- editor.getSelection = function(){
- var design_pane = document.getElementById('design_pane');
- var subRange = design_pane.contentWindow.document.selection.createRange();
- alert(subRange.text);
- }
- </script>
- </head>
- <body>
- <div id="editor">
- <div id="toolbar" class="toolbar">
- <ul>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','bold')" title="Bold"><b>B</b></li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','italic')" title="Italic"><i>I</i></li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','underline')" title="Underline"><u>U</u></li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','justifyLeft')" title="Left">«</li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','justifyRight')" title="Right">»</li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','justifyCenter')" title="Center">-</li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','justifyFull')" title="Justify">=</li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','insertUnorderedList')" title="Unordered List">·</li>
- <li class="small_button" onmousedown="editor.saveRange('design_pane')" onmouseup="editor.cmd('design_pane','linkBox')" title="Create Link">@</li>
- </ul>
- <ul>
- <li onclick="editor.start()" title="Start editing"> Start </li>
- <li onmousedown="editor.getSelection()" title="Get Selection"> Get Selection </li>
- </ul>
- </div>
- <div>
- <iframe name="design_pane" id="design_pane" width="610" height="359" frameborder="no"></iframe>
- <textarea id="code_pane"></textarea>
- </div>
- <div id="mode_tab" class="mode_tab">
- <div onclick="editor.code(this)">Code</div><div onclick="editor.design(this)" class="active">Design</div>
- </div>
- <div id="editor_insertlink" class="overlay">
- <table class="popbox" cellspacing="0" cellpadding="0">
- <form>
- <tr>
- <td class="title" colspan="3">Create Link</td>
- </tr>
- <tr>
- <td> </td><td><div class="field">URL : <input type="text" id="editor_insertlink_field" /></div></td><td> </td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <div class="buttons">
- <div class="button" onclick="editor.closeBox('editor_insertlink')">Cancel</div>
- <div class="button" id="editor_insertlink_ok">OK</div>
- </div>
- </td>
- <td> </td>
- </tr>
- </form>
- </table>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement