123
user profile image

This is inspired by a e-mail news update from CSS-Tricks "Cut and Copy (from Javascript" by Chris Coyier.

Comments

  1. Thank you for the demo code, excellent for finding out about contenteditable commands.

    I found a couple of bugs:

    1) When javascript prompts for a value for a command (say 'createLink'), the value entered by the user was ignored, the default from the array was used always.

    The code which passed the value to the execCommand was at fault

    I changed:

    val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "";
    document.execCommand(cmd.cmd, false, (cmd.val || ""));
    

    to

    val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "" ;
    document.execCommand(cmd.cmd, false, (val || ""));
    

    2) The definition for formatBlock in the array did not specify a value, but formatBlock needs a value to know which tag to use ie: <div> <h1> etc.

    So the definition of formatBlock in the array changes from:

    "cmd": "formatBlock",
    "desc": "Adds an HTML block-style tag around the line ..."
    

    to:

    "cmd": "formatBlock",
    "val": "<div>",
    "desc": "Adds an HTML block-style tag around the line ..."</div>
    

  2. Thank you Kev

    You have increased the level of quality in my pen by finding and helping fix a couple of bugs! I have fixed them and now two features actually do what they should :-)

    Great work!

  3. This is one of the awesomest things I've seen in CodePen. And using vanilla JS which is more awesome. Could you provide some ideas on how one would go about saving the changes? I'm thinking I would save them as an array in localStorage at least.

Leave a Comment Markdown supported. Click @usernames to add to comment.

You must be logged in to comment.
Loading...