I am using a fantastic jquery text editor called Redactor . I am trying to add a new button that, when clicked, gets the text highlighted in a text editor.
The script allows you to add a new button by adding the following setting:
buttonsCustom: { button1: { title: 'Button', callback: testButton //executes callback on button click } }
then in the callback I want to get the selected text
function testButton(obj, event, key) { alert(highlighted_text); }
I carefully looked through the documentation and could not get the highlighted text. I tried other functions like ...
function getSelText() { var txt = ''; if (window.getSelection) { txt = window.getSelection(); } else if (document.getSelection) { txt = document.getSelection(); } else if (document.selection) { txt = document.selection.createRange().text; } else return; return txt; }
... but the text editor script already has a way to do this, and it would be better to use it.
In the script, I found that the text selection function is on line 1719, but cannot figure out how to use it for a custom button.
Anyone running into Redactor help!
source share