开发者

WYM editor - stop duplicate inserts happening

I am using WYMeditor in a project which works very well and is easy to use. I have added a custom button which opens a modal containing thumbnails of images. Click on the image and it gets inserted into the WYMeditor. Problem is that the first image clicked is great, but if you try to insert more than 1 image it "doubles up" i.e. first image click = 1 image insert, second image click = 2 image inserts, third click = 3 image inserts and so on. I also get a "</span>" after the image insert this is not needed at all. I cannot see why this is happening any clues. Here is the code for the WYM insert.

jQuery('.wymeditor').wymeditor({
    html: '<p>Hello, World!<\/p>',
    postInit: function(wym) {
        var html = "<li class='wym_tools_newbutton'>"
                 + "<a name='NewButton' href='#'"
                 + " style='background-image:"
                 + " url(includes/js/wymeditor/img/media.png);'"
                 + " title='Insert an image' >"
                 + "</a></li>";
       jQuery(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).append(html);
       jQuery(wym._box).find('li.wym_tools_newbutton a').click(function() {
            jQuery('#modal').show().css( { 'left': (winW-980)/2+'px', 'top': '100px' } ).load('includes/admin/adminListMedia.php');
                jQuery('.imgname').live('change',function(){
                var InsertImg = '#'+jQuery(this).attr('id');
                wym.insert('<img src="http://127.0.1/admin/includes/uploads/'+jQuery(InsertImg).val()+'" />');
                jQuery('#modal').empty().hide();
             });
            return(false);
        });

As you can see I close and empty the modal on insert, I did this in an attempt to "clear" the duplication, but it does not work and this is the "modal" code:

<?php
if ($handle = opendir('../..开发者_如何学C/includes/uploads/thumb/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") { ?>
            <div class="MediaImgSelect  wym_src">';
                <img src="includes/uploads/thumb/<?php echo $file; ?>" width="90px" height="90px"/>';
                Size 
                <select class="imgname" id="<?php echo 'img_'.substr($file,0,-4); ?>">
                <option value="Select">Select</option>
                <option value="thumb/<?php echo $file; ?>">Thumb</option>
                <option value="thumb/<?php echo $file; ?>">Small</option>
                <option value="thumb/<?php echo $file; ?>">Large<option>
                </select>
                </div>
        <?php }
    }
    closedir($handle);
}

?>


Actually I got the answer use .bind not .live in the function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜