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

Brian Groce wp at watershedstudio.com
Thu Mar 22 21:44:20 GMT 2007


Any luck with this?  I've been wondering the same thing for TinyMCE on 
WP 2.1.x and WPMU 1.1.1 using a plugin and not editing the core code. 

My needs are to highlight text in the editor, click on my custom button 
and then that would wrap the selected text with some code. 

Something like...

<div class='myClass'>The selected text from TinyMCE</div>

...this is easy to do in the "code" editor, but TinyMCE has yet to work 
for me.

If anyone knows how to go about this, I'd be extremely grateful.


Callum Macdonald said the following on 3/19/2007 5:46 PM:
> I've looked at that, but it's launched as a javascript prompt, not a 
> new HTML window. So it exists with all the variables already set. What 
> I'm doing is trying to send a command back to the editor from an 
> external window. So I can't figure a way to do it relating to the 
> existing insert link functions.
> Any ideas?
> Callum.
> Computer Guru wrote:
>> Can't you refer to the original link insertion dialog for TinyMCE?
>> Computer Guru
>> NeoSmart Technologies
>> http://neosmart.net/blog/
>>> -----Original Message-----
>>> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-
>>> bounces at lists.automattic.com] On Behalf Of Callum Macdonald
>>> Sent: Monday, March 19, 2007 9:11 AM
>>> To: wp-hackers at lists.automattic.com
>>> Subject: [wp-hackers] Plugin to insert a link, how do I handle the
>>> selected text?
>>> 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