2014-11-23 52 views
1

我正在尝试使用redactor.js来编辑流星中的某些div; 模板我:在流星中使用contenteditable和wysiwyg

<template name="home"> 
    <section class="editable"> 
    </section> 
    ... 
</template> 

,并在JS:

Template.home.events({ 
    "click section.editable": function(event) { 
     $(event.target).redactor(); 
    }, 
}); 

这个正确创建主编所见即所得的编辑器,当我点击部分;问题是通过再次点击,另一个编辑器(嵌套在前一个编辑器中)被创建;我试图没有成功,只有在编辑器不存在的情况下才能限制redactor()方法的执行。

回答

0

你可以将状态包装在会话变量中吗?当然,你需要回来一次修订者结束设置

Template.home.events({ 
    "click section.editable": function(event) { 
     var isEditorActive = Session.get("editorActive", false); 
     if (!isEditorActive) { 
      Session.set("editorActive",true); 
      $(event.target).redactor({ 
       blurCallback: function(e) 
       { 
        Session.set("editorActive",false); 
        this.core.destroy(); // destroy redactor ? 
       } 
      }); 
     } 
    } 
}); 

以前的版本(也许尝试挂钩到一个模糊事件?):

是否有特定的你想为此使用流星事件吗?你可以使用redactor。

if (Meteor.isClient) { 
    Meteor.startup(function() { 
     $('section.editable').redactor({ 
      focus: false 
     }); 
    }); 
} 
+0

那么将其绑定到click事件的原因是,我想实现的点击编辑模式;我不想在那里和编辑一起创业;只是一个普通的div,当你点击它时,编辑会显示自己 – 2014-11-23 10:31:04

+0

@CerealKiller我已经更新了我的答案。让我知道你是怎么办的。 – cobberboy 2014-11-23 13:43:08

+0

是的,但此解决方案不支持更多同时处于活动状态的编辑器(您将需要比变量更复杂的内容来跟踪编辑器状态......);最后,我使用了一个解决方案,在编辑器被激活时添加一个自定义(编辑)类,并在停用时将其删除;检查编辑器.hasClass('。editing')是否让你决定是否需要调用redactor()方法... – 2014-11-24 01:48:53