• Resolved chemoul

    (@chemoul)


    Hi,
    I’m trying to create a second link button in the quicktags.js file, so that I can have the option to format my links two different ways.
    Here is what I did:
    1. I copied and pasted the existing link button and renamed it:
    ‘edButtons[edButtons.length] =
    new edButton(‘ed_jlink’
    ,’jlink’
    ,”
    ,”
    ,’j’
    ); // special case’

    2. added the following else if statement to the function edShowButton:
    ‘else if (button.id == ‘ed_jlink’) {
    document.write(‘<input type=”button” id=”‘ + button.id + ‘” accesskey=”‘ + button.access + ‘” class=”ed_button” onclick=”edInsertJLink(edCanvas, ‘ + i + ‘);” value=”‘ + button.display + ‘” />’);
    }’

    3. copied and renamed the function edInsertLink:
    ‘function edInsertJLink(myField, i, defaultValue) {
    if (!defaultValue) {
    defaultValue = ‘https://&#8217;;
    }
    if (!edCheckOpenTags(i)) {
    var URL = prompt(‘Enter the URL’ ,defaultValue);
    if (URL) {
    edButtons[i].tagStart = ‘‘;
    edInsertTag(myField, i);
    }
    }
    else {
    edInsertTag(myField, i);
    }
    }’

    I uploaded the quicktags.js file but if I go to the post page I don’t get any quicktags button displayed and I get the following javascript error: Error Object expected.

    Can anyone help please?

    Thanks.

    Stefan

Viewing 10 replies - 1 through 10 (of 10 total)
  • I added a Podcast quicktag so the principle is the same:
    https://www.tamba2.org.uk/wordpress/podcast/

    Thread Starter chemoul

    (@chemoul)

    Thank you for your reply.
    The newer versions of quicktag don’t seem to be using the closing tag in the button definition any more, however. I just can’t see what’s wrong with what I did.

    I can’t read your code above because it’s been grabbed and parsed in places. A .txt file in your webspace would help. That said I wasn’t aware that the quicktags.js had changed in several version of WP.

    Thread Starter chemoul

    (@chemoul)

    I’ve uploaded the quicktags.txt file at https://www.thevital.net/quicktags.txt
    To get the second link button/functionality I added at the lines:
    60-66
    174-176
    392-406

    thank you for your help.

    Stefan

    In what way are you actually wanting these links to be different ?

    Thread Starter chemoul

    (@chemoul)

    I’d like a button for links that open in a new window and another button for links that open in the same window. I’m also thinking about 2 different css classes to be able to format links differently with the push of a button.
    To do that I need to be able to create a working ‘clone’ of the original link button though…

    edButtons[i].tagStart = '<a href="' + URL + '">';
    That’s from Jlink – and it has no target=”_blank”>

    edButtons[i].tagStart = '<a href="' + URL + '" target="_blank">';

    Does that work ?

    Thread Starter chemoul

    (@chemoul)

    No, it still doesn’t show me any quicktag buttons at all and has got the “Object expected” error when loading the page. I don’t understand why duplicating and renaming the button, inserting the button and duplicating and renaming the original link function won’t work.. ??
    But thank you for your help so far, it is really appreciated.

    Stefan

    This works. I just tested it on my site:
    Lines 60-66
    edButtons[edButtons.length] =
    new edButton('ed_link2'
    ,'newlink'
    ,''
    ,'</a>'
    ,'a'
    ); // special case

    Lines 227-229
    else if (button.id == 'ed_link2') {
    document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink2(edCanvas, ' + i + ');" value="' + button.display + '" />');
    }

    Right at the very bottom of the js file
    function edInsertLink2(myField, i, defaultValue) {
    if (!defaultValue) {
    defaultValue = 'https://';
    }
    if (!edCheckOpenTags(i)) {
    var URL = prompt('Enter the URL' ,defaultValue);
    if (URL) {
    edButtons[i].tagStart = '<a href="' + URL + '" target="_blank">';
    edInsertTag(myField, i);
    }
    }
    else {
    edInsertTag(myField, i);
    }
    }

    If this does not appear:
    https://www.tamba2.org.uk/downloads/new-win-qtag.txt

    Thread Starter chemoul

    (@chemoul)

    Thank you so much, that worked. I must have changed something else in the quicktags file for it not to work, because this is essentially the same code I already had. I started with a fresh quicktags file and now it works ??

    Thanks again.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘hacking quicktags 2nd link button, how?’ is closed to new replies.