I need to highlight
a selected text with JavaScript (no jQuery) and having control points
or markers
(left and right), I don't really know how to call them, similarly like on mobile phones so I can extend the selection anytime by dragging any of the control points.
Example: http://screencast.com/t/KJBdvreeVW
I've grabbed the selected text, demo: http://jsfiddle.net/henrichro/HJ482/
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
alert(text);
}
if (window.Event) document.captureEvents(Event.MOUSEUP);
document.onmouseup = getSelectionText;
Now I have this working code to get the text, but I would like to have markers around it, as written above :)
Update 10/28/2013:
After Dementic's directions (his answer below), I figured out the next working code: http://jsfiddle.net/henrichro/WFLU9/
The only problem persists when I select more than one line. On that scenario the markers are showing wrong.