无法使用 fancybox 在 CKeditor 中输入

发布于 2024-12-18 11:31:51 字数 1899 浏览 1 评论 0原文

这是我在 cakephp 项目中用于实现 CKeditor 编辑版本的代码。

<div style='display:none'>
    <div class="umsg_div" id="umsg_div">
        <?php           
            echo $this->Form->create('Inbox',array('action'=>'private_message_reply','id' => 'form_umsg'));
        ?>

        <ul >           
            <?php echo $this->Form->input('Inbox.to_id',array('type'=>'hidden','value'=>@$message_details['Inbox']['from_id'],'id'=>'to_id')); ?>
            <li><div class="blue_title">Send Private Message</div></li><br/>
            <li>Subject</li>
            <li><?php echo $this->Form->input('Inbox.subject',array('type'=>'text','class'=>'subject','label'=>false));?></li><br/>
            <li>Message</li>
            <li>
                <?php echo $this->Form->input('Inbox.message',array('type' => 'textarea','id'=>'user_message','rows'=>"2",'style'=>'width:130%','label'=>false));?>
                <script language="javascript" type="text/javascript">
                    if (CKEDITOR.instances['user_message']) {                   
                        CKEDITOR.instances.user_message.destroy();
                     }
                     CKEDITOR.replace( 'user_message',{
                                toolbar : 'Basic',
                    });

                </script> 
            </li>
            <li style="text-align:right;padding:10px;"><input type="submit" name="umsg" value="Send" class="normal_button"/> or <a href="#" onclick='return hide_reply();'>Cancel</a></li>
        </ul>
        <?php echo $this->Form->end(); ?>   
    </div>
</div>

我在我的项目中的很多地方都使用了ckeditor...但是在这个地方我无法输入文本字段。

This is the code I used for implementing an edited version of CKeditor in my cakephp project.

<div style='display:none'>
    <div class="umsg_div" id="umsg_div">
        <?php           
            echo $this->Form->create('Inbox',array('action'=>'private_message_reply','id' => 'form_umsg'));
        ?>

        <ul >           
            <?php echo $this->Form->input('Inbox.to_id',array('type'=>'hidden','value'=>@$message_details['Inbox']['from_id'],'id'=>'to_id')); ?>
            <li><div class="blue_title">Send Private Message</div></li><br/>
            <li>Subject</li>
            <li><?php echo $this->Form->input('Inbox.subject',array('type'=>'text','class'=>'subject','label'=>false));?></li><br/>
            <li>Message</li>
            <li>
                <?php echo $this->Form->input('Inbox.message',array('type' => 'textarea','id'=>'user_message','rows'=>"2",'style'=>'width:130%','label'=>false));?>
                <script language="javascript" type="text/javascript">
                    if (CKEDITOR.instances['user_message']) {                   
                        CKEDITOR.instances.user_message.destroy();
                     }
                     CKEDITOR.replace( 'user_message',{
                                toolbar : 'Basic',
                    });

                </script> 
            </li>
            <li style="text-align:right;padding:10px;"><input type="submit" name="umsg" value="Send" class="normal_button"/> or <a href="#" onclick='return hide_reply();'>Cancel</a></li>
        </ul>
        <?php echo $this->Form->end(); ?>   
    </div>
</div>

I used ckeditor in my project in many places... but in this place I can not type in textfields.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-12-25 11:31:51

基本上 DOM 事件被覆盖,所以你需要做的是在 afterLoad 上使用 setTimeout 来解决问题:

$("#id_of_fancybox_thingy").fancybox({

    //all your existing stuff goes here...

    afterLoad:function(){
        setTimeout(function(){

            if (CKEDITOR.instances['elementname']) {
                CKEDITOR.instances['jelementname'].destroy();
                delete CKEDITOR.instances['elementname'];
            }
            CKEDITOR.replace('elementname', { "toolbar": [ [ "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Print" ], [ "Undo", "Redo", "-", "Find", "Replace", "-", "SelectAll", "RemoveFormat" ], [ "\/" ], [ "Bold", "Italic", "Underline", "Strike", "-", "Subscript", "Superscript" ], [ "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote" ], [ "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock" ], [ "Link", "Unlink", "Anchor" ], [ "\/" ], [ "TextColor", "BGColor" ], [ "Maximize", "ShowBlocks" ] ], "height": "200", "width": "690" });

        }, 1000);
    }

});

Basically the DOM events are being overwritten so what you need to do is use a setTimeout on the afterLoad to fix the problem:

$("#id_of_fancybox_thingy").fancybox({

    //all your existing stuff goes here...

    afterLoad:function(){
        setTimeout(function(){

            if (CKEDITOR.instances['elementname']) {
                CKEDITOR.instances['jelementname'].destroy();
                delete CKEDITOR.instances['elementname'];
            }
            CKEDITOR.replace('elementname', { "toolbar": [ [ "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Print" ], [ "Undo", "Redo", "-", "Find", "Replace", "-", "SelectAll", "RemoveFormat" ], [ "\/" ], [ "Bold", "Italic", "Underline", "Strike", "-", "Subscript", "Superscript" ], [ "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote" ], [ "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock" ], [ "Link", "Unlink", "Anchor" ], [ "\/" ], [ "TextColor", "BGColor" ], [ "Maximize", "ShowBlocks" ] ], "height": "200", "width": "690" });

        }, 1000);
    }

});
谁把谁当真 2024-12-25 11:31:51

问题可能是 Fancybox 克隆了您为其提供的内容,这意味着原始 DOM 元素的所有事件处理程序都会丢失。换句话说,如果您有一个 HTML 元素,并且您已在其上注册了一个事件处理程序,例如:

$(function(){
    $('#span-id').click(function(){
        alert('hello world!');
    });
});

并且您想要显示此 > 在 Fancybox 内,然后单击它,您将不会收到任何消息。

The problem may be that Fancybox clones what you give it as its content, which means that all of the event handlers of the original DOM elements are lost. In other words, if you have an HTML <span> element and you've registered an event handler on it, like:

$(function(){
    $('#span-id').click(function(){
        alert('hello world!');
    });
});

and you want to show this <span> inside the Fancybox, then on its click, you won't get any message.

讽刺将军 2024-12-25 11:31:51

这只是前一位发帖者的扩展,前一位发帖者指出由于 Fancybox 克隆内容而无法访问 DOM 元素:

一种选择可能是在 Fancybox 完成后附加它:

$("#stuff").fancybox({
            // [Your settings]
    onComplete : function() {
                // Register your CKeditor here
                if (CKEDITOR.instances['user_message']) {                   
                    CKEDITOR.instances.user_message.destroy();
                 }
                 CKEDITOR.replace( 'user_message',{
                            toolbar : 'Basic',
                });
    }
});

这可能有点黑客行为,作为免责声明,我从未与 Fancybox 合作过。但这里是回调的 API: http://fancybox.net/api

希望这会有所帮助。

This is just an extension to the previous poster who pointed out the inaccessibility of the DOM elements due to Fancybox cloning the contents:

One option may be to attach it after the Fancybox has completed:

$("#stuff").fancybox({
            // [Your settings]
    onComplete : function() {
                // Register your CKeditor here
                if (CKEDITOR.instances['user_message']) {                   
                    CKEDITOR.instances.user_message.destroy();
                 }
                 CKEDITOR.replace( 'user_message',{
                            toolbar : 'Basic',
                });
    }
});

This might be a bit hackish and, as a disclaimer, I never worked with Fancybox. But here's the API for the callbacks: http://fancybox.net/api

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文