JS class for creating very simple text/html editor combinated with <iframe>
element.
var i_am_instance= class_SimpleEditor.init({
editor_element: iframe_NODE_element,
default_value: default_content
});
<iframe id="editor" src='about:blank'></iframe>
<button onclick="i_am_instance.format('bold');">Bold</button>
- format(format_name):
- primary for using as onclick listener
- format_name= DOMString command name (i.e. 'Commands List' below);
- getContent: return
<iframe>
HTML content - getTextContent: return
<iframe>
text content
- "bold", "italic", "underline": Toggle bold/italic format new or selected text
- "removeFormat": remove format
- "insertOrderedList", "insertUnorderedList", "insertParagraph": add
<ol>
,<ul>
, or<p>
- "createEmail", "createLink", "insertImage": Toggle email, URL link or create image
- in case of email and URL link: the link is created from selected text (if detected), or you can add link via prompt
- "insertImage": for now no detection implemented (in aditional, you must combine this with some uploader)
- "justifyLeft", "justifyRight", "justifyCenter", "justifyFull": alingment change
- Another possibilites in Document.execCommand()
- Email example:
i_am_instance.setValidationFunction("createEmail", function emailValidation(email_candidate) { /*_@_*/ let e= email_candidate.split("@"); if(e.length!==2) return false; /*_@_._*/ e= [e[0], ...e[1].split(".")]; if(e.length!==3) return false; const _e= !/(#|\?|!|\\|\/|\||\.\.)/i.test(e[0]); return _e && e.reduce((r,o)=>r&&o.length>1&&!/\s/.test(o), _e); });