Callback function quicktags that uses variable in start tag

I am trying to make a callback function that returns on click of a quick tag wordpress button dinamical generated variables inside the tags.

Something like

QTags.addButton( 'eg_wrap', 'WRAP ARROWND', 'div class="moudle-area"', 'p[Tweet "I just completed Module '+module_nr+' of the '+course+' Course"]/p/div', 'WRAP ARROWND', 'WRAP ARROWND', 1 );

Current Example

function callback_wrap() {
    var course = getSelectedText("_lesson_course");
    var module_info = jQuery("#title").val();
    var module_nr = module_info.match( /\d+/g );
});
QTags.addButton('eg_wrap', 'WRAP ARROWND', callback_wrap);

Problem when I select text how can I pass the variables and read the selected text in order to insert the start tag end tag and the variables.

So when clicked should return:

div class="moudle-area"
     SELECTED STRING HERE 
     p[Tweet "I just completed Module NUMBER (2) of the 
     NAME OF COURSE Course"]
     /p
 /div

Topic quicktag html-editor plugin-development Wordpress

Category Web


Managed to find out how:

function callback_wrap(e, c, ed) {
    var course = getSelectedText("_lesson_course");
    var module_info = jQuery("#title").val();
    var module_nr = module_info.match( /\d+/g );
    var start = ed.canvas.selectionStart;
    var end = ed.canvas.selectionEnd;
    var content = jQuery("#content").val();
    console.log(start);
    console.log(end);
    console.log(ed);
    var selected = content.slice(start, end);
    var string = '<div class="moudle-area">'+selected+'<p>[Tweet "I just completed Module '+module_nr+' of the '+course+' Course"]</p></div>';
    QTags.insertContent(string);
}
QTags.addButton( 'eg_wrap', 'WRAP ARROWND', callback_wrap);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.