WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] hacking quicktags 2nd link button, how? (11 posts)

  1. chemoul
    Member
    Posted 8 years ago #

    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 = 'http://';
    }
    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

  2. Mark (podz)
    Support Maven
    Posted 8 years ago #

    I added a Podcast quicktag so the principle is the same:
    http://www.tamba2.org.uk/wordpress/podcast/

  3. chemoul
    Member
    Posted 8 years ago #

    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.

  4. Mark (podz)
    Support Maven
    Posted 8 years ago #

    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.

  5. chemoul
    Member
    Posted 8 years ago #

    I've uploaded the quicktags.txt file at http://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

  6. Mark (podz)
    Support Maven
    Posted 8 years ago #

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

  7. chemoul
    Member
    Posted 8 years ago #

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

  8. Mark (podz)
    Support Maven
    Posted 8 years ago #

    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 ?

  9. chemoul
    Member
    Posted 8 years ago #

    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

  10. Mark (podz)
    Support Maven
    Posted 8 years ago #

    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 = 'http://';
    }
    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:
    http://www.tamba2.org.uk/downloads/new-win-qtag.txt

  11. chemoul
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic