How to enable the content editor as a droppable target with jQuery-ui?

I’m trying to enable the WordPress content editor as a droppable using jQuery UI drag and drop. However, I can’t get the drag to drop, or the drop event to fire.

Is there something I’m missing?

<ul id="keywords">
    <li>drag one</li>
    <li>drag two</li>
    <li>drag three</li>
</ul>

jQuery("#keywords").find("li").each(function(){jQuery(this).draggable(
{ 
    helper:'clone', 
    start: function(event, ui){
        jQuery(this).fadeTo('fast', 0.5);}, 
        stop: function(event, ui) { 
            jQuery(this).fadeTo(0, 1); 
            } 
        });
    });

jQuery('#content').droppable(
{ 
    drop: function(event, ui)
    {
        alert('dropped in content'); //DOES NOT FIRE!!!
        jQuery(this).dropIt(ui.draggable.html());
    } 
});

if(typeof tinyMCE=='object')
{ 
    alert('tinyMCE is active'); //DOES NOT FIRE!!!
    jQuery('#editorcontainer').droppable(
    { 
        drop: function(event, ui) 
        { 
        alert('dropped in tinyMCE editor'); //DOES NOT FIRE!!!
        //Dynamically add content
        tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'New content.');
        } 
    });
}

Related posts

Leave a Reply

2 comments

  1. In the above example the following line:

    jQuery(".myDiv").find("li").each(function(){
    

    should be:

    jQuery(".keywords").find("li").each(function(){
    

    That should enable the list items to be dragged and dropped.

    To allow the items to be dropped on the TinyMCE textarea the following code works.

    $('#editorcontainer').droppable({ 
        drop: function(event, ui) { 
            alert('dropped'); //NOW FIRES!
            //Dynamically add content
            tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'New content.');
        } 
    });
    
  2. Try to declare on TinyMCE body’s tag like this, it works for me

    On tiny_mce_src.js

    t.iframeHTML += '</head><body ondrop="parent.drop(event);"  " id="' + bi + '" class="mceContentBody '+ t.id +'_cl' + bc +'" onload="window.parent.tinyMCE.get('' + t.id + '').onLoad.dispatch();"><br></body></html>';
    

    On editor’s page:

        function drop(ev)
        {
                ev.preventDefault();
                var data=ev.dataTransfer.getData("Text");
                tinyMCE.execCommand('mceInsertContent',true,data);
        }
        function allowDrop(ev) {
                ev.preventDefault();
        }
    
        function drag(ev) {
                var html = $('#'+ev.target.id).html();
                ev.dataTransfer.setData("Text",html);
        }
    

    It’s seems using jquery with TinyMCE doesn’t work …