Drag n' Drop text into WordPress Editor using jQuery
-
Hi,
I’m having trouble accessing the tinymce content area via jQuery. I created a meta box for Pages and Posts, which displays a list of drag-able text items. I’d like to be able to drop these into the WP content editor at the current caret position.I’ve adapted the code from:
https://skfox.com/2008/11/26/jquery-example-inserting-text-with-drag-n-drop/
(a demo is available here)
https://skfox.com/jqExamples/insertAtCaret.htmlThe only changes I made were to convert the
$("#txtMessage")
and$(".txtDropTarget")
selections to$('.wp-editor')
and I added the following at the top:
$('.wp-editor').addClass('ui-droppable');
However, I’m getting the following JavaScript error at run time:
$(“.wp-editor”).droppable is not a function
https://localhost/wordpress/wp-content/plugins/…/meta-box.js?ver=1.0
Line 15
drop: function(ev, ui) {I understand from looking at the HTML output in Firebug that the WordPress tinymce editor is embedded in an iframe like so:
<td class="mceIframeContainer mceFirst mceLast"> <iframe id="content_ifr" frameborder="0" src="javascript:""" title="Rich Text Area Press ALT F10 for toolbar. Press ALT 0 for help." style="width: 100%; height: 352px;"> <html> <head xmlns="https://www.w3.org/1999/xhtml"> <body id="tinymce" class="mceContentBody wp-editor" dir="ltr">
I consider myself to have an intermediate understanding of jQuery, but I’m stumped on this one. How can I select the content area inside the iframe, and is that the correct approach? Is there another way I should be doing this? I seem to recall other WordPress plugins having the ability to insert items from meta boxes into the current caret position in the WordPress editor.
TIA!
- The topic ‘Drag n' Drop text into WordPress Editor using jQuery’ is closed to new replies.