diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..176a458f --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/execcommand/index.html b/execcommand/index.html new file mode 100644 index 00000000..75529df6 --- /dev/null +++ b/execcommand/index.html @@ -0,0 +1,125 @@ + + +
+ + + + +contenteditable=true
to allow modifications to the
+ content. Updated
: Added
+ font awesome icons. 2017-06-04 updated:
2018-04-17 updated:
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Praesent semper in nunc at mattis. Suspendisse metus augue, + pellentesque finibus luctus dictum, tempor id nunc. Phasellus + semper magna ac interdum scelerisque. Vestibulum laoreet + sapien a nisi ullamcorper, nec luctus neque eleifend. Aliquam + vel tortor justo. Nam aliquam dapibus mi ut volutpat. Donec + eros turpis, gravida et neque nec, interdum pulvinar nibh. Ut + vel sodales nulla, a tempus sem. Nunc facilisis pretium + aliquam. Proin nulla ante, congue at purus sit amet, commodo + placerat erat. Sed malesuada eros nulla, in cursus urna + elementum finibus. Suspendisse posuere purus pellentesque + rutrum tempor. Nunc nec tincidunt est. Sed convallis ligula + quis dui laoreet maximus. Nulla pharetra placerat quam ut + rutrum. Nullam sit amet vehicula nisi. +
++ Pellentesque feugiat posuere fermentum. In ut varius odio, nec + venenatis lorem. Pellentesque interdum odio tortor, ac + hendrerit mauris venenatis nec. Maecenas finibus dapibus + eleifend. Nulla rhoncus metus non nisi rutrum tempor. Cras + luctus lacinia eros sed volutpat. Duis accumsan quam libero, + non accumsan nisl faucibus sit amet. +
++ Cras tincidunt magna malesuada maximus tristique. Sed a + fringilla ipsum. Nam malesuada gravida commodo. In ut + convallis neque. Nulla ut consequat nisi, a imperdiet ante. +
+", + desc: "Adds an HTML block-level element around the line containing the current selection, replacing the block element containing the line if one exists (in Firefox,is the exception — it will wrap any containing block element). Requires a tag-name string as a value argument. Virtually all block-level elements can be used.", + }, + { + name: "forwardDelete", + desc: "Deletes the character ahead of the cursor's position, identical to hitting the Delete key on a Windows keyboard.", + }, + { + name: "heading", + val: "h3", + icon: "header", + desc: 'Adds a heading element around a selection or insertion point line. Requires the tag-name string as a value argument (i.e., "H1", "H6").', + }, + { + name: "hiliteColor", + val: "Orange", + desc: "Changes the background color for the selection or at the insertion point. Requires a color value string as a value argument. useCSS must be true for this to function.", + }, + { + name: "increaseFontSize", + desc: "Adds a tag around the selection or at the insertion point.", + }, + { + name: "indent", + icon: "indent", + desc: "Indents the line containing the selection or insertion point. In Firefox, if the selection spans multiple lines at different levels of indentation, only the least indented lines in the selection will be indented.", + }, + { + name: "insertBrOnReturn", + desc: "Controls whether the Enter key inserts a
element, or splits the current block element into two.", + }, + { + name: "insertHorizontalRule", + desc: "Inserts a
element at the insertion point, or replaces the selection with it.", + }, + { + name: "insertHTML", + val: "<h3>Life is great!</h3>", + icon: "code", + desc: "Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string as a value argument.", + }, + { + name: "insertImage", + val: "http://dummyimage.com/160x90", + icon: "picture-o", + desc: "Inserts an image at the insertion point (deletes selection). Requires a URL string for the image's src as a value argument. The requirements for this string are the same as createLink.", + }, + { + name: "insertOrderedList", + icon: "list-ol", + desc: "Creates a numbered ordered list for the selection or at the insertion point.", + }, + { + name: "insertUnorderedList", + icon: "list-ul", + desc: "Creates a bulleted unordered list for the selection or at the insertion point.", + }, + { + name: "insertParagraph", + icon: "paragraph", + desc: "Inserts a paragraph around the selection or the current line.", + }, + { + name: "insertText", + val: new Date().toString(), + icon: "file-text-o", + desc: "Inserts the given plain text at the insertion point (deletes selection).", + }, + { + name: "italic", + icon: "italic", + desc: "Toggles italics on/off for the selection or at the insertion point.", + }, + { + name: "justifyCenter", + icon: "align-center", + desc: "Centers the selection or insertion point.", + }, + { + name: "justifyFull", + icon: "align-justify", + desc: "Justifies the selection or insertion point.", + }, + { + name: "justifyLeft", + icon: "align-left", + desc: "Justifies the selection or insertion point to the left.", + }, + { + name: "justifyRight", + icon: "align-right", + desc: "Right-justifies the selection or the insertion point.", + }, + { + name: "outdent", + icon: "outdent", + desc: "Outdents the line containing the selection or insertion point.", + }, + { + name: "paste", + icon: "clipboard", + desc: "Pastes the clipboard contents at the insertion point (replaces current selection). Disabled for web content.", + }, + { + name: "redo", + icon: "repeat", + desc: "Redoes the previous undo command.", + }, + { + name: "removeFormat", + desc: "Removes all formatting from the current selection.", + }, + { + name: "selectAll", + desc: "Selects all of the content of the editable region.", + }, + { + name: "strikeThrough", + icon: "strikethrough", + desc: "Toggles strikethrough on/off for the selection or at the insertion point.", + }, + { + name: "subscript", + icon: "subscript", + desc: "Toggles subscript on/off for the selection or at the insertion point.", + }, + { + name: "superscript", + icon: "superscript", + desc: "Toggles superscript on/off for the selection or at the insertion point.", + }, + { + name: "underline", + icon: "underline", + desc: "Toggles underline on/off for the selection or at the insertion point.", + }, + { + name: "undo", + icon: "undo", + desc: "Undoes the last executed command.", + }, + { + name: "unlink", + icon: "chain-broken", + desc: "Removes the anchor tag from a selected anchor link.", + }, + { + name: "useCSS", + desc: "Toggles the use of HTML tags or CSS for the generated markup. Requires a boolean true/false as a value argument. NOTE: This argument is logically backwards (i.e., use false to use CSS, true to use HTML). This has been deprecated in favor of styleWithCSS.", + }, + { + name: "styleWithCSS", + desc: "Replaces the useCSS command. true modifies/generates style attributes in markup, false generates presentational elements.", + }, + { + name: "AutoUrlDetect", + desc: "Changes the browser auto-link behavior.", + }, +]; + +const buttons = document.querySelector(".buttons"); + +commands.forEach((command) => { + const button = document.createElement("button"); + const supported = document.queryCommandSupported(command.name); + button.className = `btn btn-xs btn-${supported ? "success" : "error"}`; + + button.addEventListener("mousedown", (e) => e.preventDefault()); + if (supported) { + button.addEventListener("click", () => { + const val = command.val + ? prompt(`Value for ${command.name}?`, command.val) || "" + : ""; + document.execCommand(command.name, false, val); + }); + } else { + button.setAttribute("disabled", "true"); + } + button.innerHTML = ` ${command.name}`; + buttons.appendChild(button); +}); diff --git a/execcommand/style.css b/execcommand/style.css new file mode 100644 index 00000000..00abe130 --- /dev/null +++ b/execcommand/style.css @@ -0,0 +1,38 @@ +@import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700|Open+Sans:400,800); +body { + font-family: "Open Sans", sans-serif; +} +.jumbotron { + font-family: "Inconsolata", monospace; +} +.btn-success { + background-color: green; + color: white; +} +.btn-error { + background-color: grey; + color: black; +} + +.btn-success, +.btn-success { + margin: 5px; +} +i { + color: white; +} +.btn-error i { + color: black; +} + +.btn { + user-select: none; +} + +:focus { + outline: none; +} + +img { + margin-top: 30px; +}