首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NicEdit -解除绑定事件

NicEdit -解除绑定事件
EN

Stack Overflow用户
提问于 2012-10-08 18:19:49
回答 1查看 1.6K关注 0票数 0

我决定在项目中使用NicEdit,因为它是轻量级的。

因此,现在我在我的页面中有一个可变数量的实例,在单击时加载,在编辑器模糊时删除。

我需要知道如何从这个组件中解除绑定事件。我试着手动解绑它,但是我不知道它们链接在哪里!

代码语言:javascript
复制
$('.container').bind('click', function(){
    var _form = $(this).parentsUntil('form').parent();
    var textarea = _form.find('textarea.edit');
    var ta_id = textarea.attr('id');
    var ed = new nicEditor(niceditOptions).panelInstance(ta_id);

    // Show Preview and update textarea and so on
    ed.addEvent('blur', function() {
        var _ed = nicEditors.findEditor(ta_id);
        var ev_type, evt, events = this.eventList;

        for (ev_type in events){
            for (evt in ev_type){
                if (this.removeEventListener){
                    this.removeEventListener(ev_type, events[ev_type][evt]);
                }
                else {
                    this.detachEvent('on' + ev_type, events[ev_type][evt]);
                }
            }
        }
        this.removeInstance(ta_id);
    });

});

非常感谢!大卫。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-19 15:48:00

你的解决方案可能还有其他方法,但在这种情况下,我更喜欢使用one版本的nicEditor面板并绑定我所有的所见即所得实例。这样做的原因是我认为它稍微整洁了一些。我将假设您知道如何使用bind one editor to multiple editable instances

加载时,我的HTML可能如下所示:

代码语言:javascript
复制
<div id="instance1">text</div>
...
<div id="instance2">text</div>
...
<div id="myNicPanel" style="display:none;position:relative;"></div>

因此,一旦页面完成加载周期,我应该有两个可编辑的区域和一个隐藏的编辑器。然后,当选择要编辑的实例时,我将使用以下jQuery重新定位并显示编辑器:

代码语言:javascript
复制
        $('#instance1 , #instance2').click(function () {
         //Reposition the editor to just above the selected instance
            $('#myNicPanel').css({
                top: $(this).position().top,
                left: $(this).position().left,
                display: 'block',
                width: $(this).width() - 2 //manual adjustment,
                position: 'absolute'
            });
         //Make the width of the editor equal to that of the instance
            $('#myNicPanel').css({
                top: $(this).position().top - $('#myNicPanel').height()
            });
        });

当然,在此之前,您已经启动了编辑器和实例,如果您还想让编辑器在模糊时再次隐藏,您可以将hide()函数附加到其中一个nicEditor events

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12779717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档