Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery-ui sortable on divs with TinyMCE editors causes text to disappear

following the instructions at: http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/

i've got some nice WYSIWYG editors in my metaboxes

my markup looks like:

 <div class="sortable">
 <div class="sortme">
<?php $mb->the_field('extra_content2'); ?>
        <div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div>
</div>
 <div class="sortme"
<?php $mb->the_field('extra_content3'); ?>
        <div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div>
</div>
</div>

which is just WP_alchemy (also from farinspace.com) for a textarea wrapped in a div

and the script that tells tinymce to kick in:

function my_admin_print_footer_scripts()
{
    ?><script type="text/javascript">/* <![CDATA[ */

        jQuery(function($)
        {
            var i=1;
            $('.customEditor textarea').each(function(e)
            {
                var id = $(this).attr('id');

                if (!id)
                {
                    id = 'customEditor-' + i++;
                    $(this).attr('id',id);
                }
                tinyMCE.execCommand('mceAddControl', false, id);

            });
        });
    /* ]]> */</script><?php
}

// important: note the priority of 99, the js needs to be placed after tinymce loads
add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99);

that part works fine. but when i try to kick in jqueryUI sortable:

$('.sortable').sortable();

it lets me sort the multiple .sortme divs, but the content in the editors disappears. how can i make the text persist? it works just fine w/o the tinymce editors, so I presume it is a conflict w/ that somehow.

like image 225
helgatheviking Avatar asked May 04 '11 15:05

helgatheviking


1 Answers

This ( $('.sortable').sortable(); ) won't work with tinymce editors. Tinymce does not like being dragged around the dom. In order to make it work you first need to shut down Tinymce

tinyMCE.execCommand('mceRemoveControl', false, id);

then sort and then reinitialize them

tinyMCE.execCommand('mceAddControl', false, id);
like image 99
Thariama Avatar answered Sep 30 '22 09:09

Thariama