made with requirebin
Last active
August 29, 2015 14:26
-
-
Save kingease/4bfffcef5ed178dfca00 to your computer and use it in GitHub Desktop.
first try select some words in contentEditable control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // require() some stuff from npm (like you were using browserify) | |
| // and then hit Run Code to run it on the right | |
| var editor = document.getElementById('main'); | |
| editor.focus(); | |
| console.dir(editor); | |
| var startNode = editor.childNodes[0]; | |
| console.dir(startNode); | |
| var endNode = editor.childNodes[1].firstChild; | |
| var range = document.createRange(); | |
| range.setStart(startNode, 4); // 6 is the offset of "world" within "Hello world" | |
| range.setEnd(endNode, 1); // 7 is the length of "this is" | |
| var sel = window.getSelection(); | |
| sel.removeAllRanges(); | |
| sel.addRange(range); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var editor=document.getElementById("main");editor.focus();console.dir(editor);var startNode=editor.childNodes[0];console.dir(startNode);var endNode=editor.childNodes[1].firstChild;var range=document.createRange();range.setStart(startNode,4);range.setEnd(endNode,1);var sel=window.getSelection();sel.removeAllRanges();sel.addRange(range); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "requirebin-sketch", | |
| "version": "1.0.0", | |
| "dependencies": { | |
| "jquery": "2.1.4" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- contents of this file will be placed inside the <body> --> | |
| <h1>riddle editor</h1> | |
| <div contentEditable="true" class="text-area" id="main"> | |
| hello <s>world</s> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment