[wp-hackers] Plugin to insert a link, how do I handle the selected text?

Callum Macdonald lists.automattic.com at callum-macdonald.com
Mon Mar 19 07:10:45 GMT 2007


G'day,

I'm working on a plugin that adds a couple of buttons to the editors 
(using Photopress as a base) and then pops up a list of links to insert 
into the post. However, I can't figure out how to detect if text is 
currently selected in the editor, and if so, wrap the link around that 
text. My current code is:
function pluginInsertLink(linkcode) {
var winder = window.opener ? window.opener : window.dialogArguments;
    if ( !winder ) {
        winder = top;
    }
    tinyMCE = winder.tinyMCE;
    if ( typeof tinyMCE != "undefined" && 
tinyMCE.getInstanceById("content") ) {
        tinyMCE.selectedInstance.getWin().focus();
alert(focusElm);
        tinyMCE.execCommand("mceInsertContent", false, linkcode);
    } else {
        edCanvas = window.opener.document.post.content;
        winder.edInsertContent(edCanvas, linkcode);
    }
}

Does anyone know if the current text is mapped to a javascript variable? 
Do I need to pass it to the popup when the popup is opened?

Or does anyone know of another plugin which does something similar? I'm 
happy to poke about in that code and figure something out.

Cheers,


Callum.



More information about the wp-hackers mailing list