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

Callum Macdonald lists.automattic.com at callum-macdonald.com
Fri Mar 23 07:43:42 GMT 2007


Using a combination of all of the howtos I could find, I did eventually 
get it working. It's not quite perfect, I pass the selected text to the 
popup as a GET variable and then insert it via PHP to the javascript 
functions. But at least it works.

The article on maxpower is good, and it relates to buttonsnap.php which 
is a great help, but it doesn't work in the Code view of the Rich 
Editor. To get that working as well required some further fiddling. 
Happy to post my code somewhere if it would be useful.

Cheers,


Callum.

Ryan Fitzer wrote:
> MaxPower has a great article/downloadable plugin that takes care of this:
> http://www.maxpower.ca/how-to-add-buttons-to-the-wordpress-editor-for-your-plugin-theme/2006/10/28/ 
>
>
> Ryan
>
> On 3/22/07, Jamie Holly <hovercrafter at earthlink.net> wrote:
>>
>> You can do it with a custom plugin for TinyMCE. The key functions 
>> would be
>> mceInsertContent and {instance}.selection.getSelectedText(). My best
>> advice
>> would be to download the full TinyMCE package and take a look at the
>> advlink
>> plugin, since this basically does the same thing.
>>
>> Jamie Holly
>> http://www.intoxination.net
>>
>> > -----Original Message-----
>> > From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-
>> > bounces at lists.automattic.com] On Behalf Of Brian Groce
>> > Sent: Thursday, March 22, 2007 5:44 PM
>> > To: wp-hackers at lists.automattic.com
>> > Subject: Re: [wp-hackers] Plugin to insert a link, how do I handle the
>> > selected text?
>> >
>> > Callum,
>> >
>> > 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.
>> >
>> > Brian
>> >
>> >
>> > 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.
>> > >
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
>



More information about the wp-hackers mailing list