0

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>
0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.