Created
January 8, 2016 22:13
-
-
Save agibsonsw/5a4702c0b697c6f4bb66 to your computer and use it in GitHub Desktop.
Bookmarklet to add a comment box at selection
This file contains 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
javascript: (function() { | |
var d = document; | |
var wrap = d.createElement('span'); | |
wrap.style.position = 'relative'; | |
wrap.className = 'wrap'; | |
var cmt = d.createElement('textarea'); | |
cmt.style.backgroundColor = 'yellow'; | |
cmt.style.top = '1.5em'; | |
cmt.style.position = 'absolute'; | |
cmt.style.zIndex = '99'; | |
cmt.className = 'cmt'; | |
cmt.style.height = '4em'; | |
cmt.style.width = '170px'; | |
if (window.getSelection) { | |
var sel = window.getSelection(); | |
if (sel.rangeCount) { | |
var rng = sel.getRangeAt(0).cloneRange(); | |
rng.surroundContents(wrap); | |
sel.removeAllRanges(); | |
sel.addRange(rng); | |
wrap.insertBefore(cmt, wrap.firstChild); | |
cmt.thetext = rng; | |
cmt.focus(); | |
} | |
} | |
return false; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment