Welcome › mkmcst community Forum › Web programming › JavaScript › A working editor in JavaScript a nice project
- This topic has 1 reply, 1 voice, and was last updated 5 months, 3 weeks ago by
Michael Mc.
Viewing 1 reply thread
-
AuthorPosts
-
-
October 29, 2024 at 6:52 PM #8919
“You are welcome to contribute to this project. Simply repost your updates so we can review your work.”
<!DOCTYPE html> <html> <head> <meta charset='utf-8'> <script type="text/javascript" src="custom-text-editor.js"></script> <link type="text/css" rel="stylesheet" href="custom-text-editor.css"/> </head> <body> <div id="container" > <fieldset> <button class="fontStyle italic" onclick="document.execCommand('italic',false,null);" title="Italicize Highlighted Text"></button> <button class="fontStyle bold" onclick="document.execCommand( 'bold',false,null);" title="Bold Highlighted Text"></button> <button class="fontStyle underline" onclick="document.execCommand( 'underline',false,null);"></button> <select id="input-font" class="input" onchange="changeFont (this);"> <option value="Arial">Arial</option> <option value="Helvetica">Helvetica</option> <option value="Times New Roman">Times New Roman</option> <option value="Sans serif">Sans serif</option> <option value="Courier New">Courier New</option> <option value="Verdana">Verdana</option> <option value="Georgia">Georgia</option> <option value="Palatino">Palatino</option> <option value="Garamond">Garamond</option> <option value="Comic Sans MS">Comic Sans MS</option> <option value="Arial Black">Arial Black</option> <option value="Tahoma">Tahoma</option> <option value="Comic Sans MS">Comic Sans MS</option> </select> <button class="fontStyle strikethrough" onclick="document.execCommand( 'strikethrough',false,null);"><strikethrough></strikethrough></button> <button class="fontStyle align-left" onclick="document.execCommand( 'justifyLeft',false,null);"><justifyLeft></justifyLeft></button> <button class="fontStyle align-center" onclick="document.execCommand( 'justifyCenter',false,null);"><justifyCenter></justifyCenter></button> <button class="fontStyle align-right" onclick="document.execCommand( 'justifyRight',false,null);"><justifyRight></justifyRight></button> <button class="fontStyle redo-apply" onclick="document.execCommand( 'redo',false,null);"><redo></redo></button> <button class="fontStyle undo-apply" onclick="document.execCommand( 'undo',false,null);"><undo></undo></button> <button class="fontStyle orderedlist" onclick="document.execCommand('insertOrderedList', false, null);"><insertOrderedList></insertOrderedList></button> <button class="fontStyle unorderedlist" onclick="document.execCommand('insertUnorderedList',false, null)"><insertUnorderedList></insertUnorderedList></button> <input class="color-apply" type="color" onchange="chooseColor()" id="myColor"> <!-- font size start --> <select id="fontSize" onclick="changeSize()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> <!-- font size end --> </fieldset> <div id="editor1" contenteditable="true" data-text="Enter comment...."></div> </div> </body> </html>
-
October 29, 2024 at 7:51 PM #8921
a better editor
<html> <head> <style> .editor { border:solid 1px #ccc; padding: 20px; min-height:200px; } .sample-toolbar { border:solid 1px #ddd; background:#f4f4f4; padding: 5px; border-radius:3px; } .sample-toolbar > span { cursor:pointer; } .sample-toolbar > span:hover { text-decoration:underline; } </style> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"> </head> <body> <div class="sample-toolbar"> <a href="javascript:void(0)" onclick="format('bold')"><span class="fa fa-bold fa-fw"></span></a> <a href="javascript:void(0)" onclick="format('italic')"><span class="fa fa-italic fa-fw"></span></a> <a href="javascript:void(0)" onclick="format('insertunorderedlist')"><span class="fa fa-list fa-fw"></span></a> <a href="javascript:void(0)" onclick="setUrl()"><span class="fa fa-link fa-fw"></span></a> <span><input id="txtFormatUrl" placeholder="url" class="form-control"></span> </div> <div class="editor" id="sampleeditor"> </div> <script> window.addEventListener('load', function(){ document.getElementById('sampleeditor').setAttribute('contenteditable', 'true'); document.getElementById('sampleeditor2').setAttribute('contenteditable', 'true'); }); function format(command, value) { document.execCommand(command, false, value); } function setUrl() { var url = document.getElementById('txtFormatUrl').value; var sText = document.getSelection(); document.execCommand('insertHTML', false, '<a href="' + url + '" target="_blank">' + sText + '</a>'); document.getElementById('txtFormatUrl').value = ''; } </script> </body> </html>
-
-
AuthorPosts
Viewing 1 reply thread
- You must be logged in to reply to this topic.