小编Kan*_*sha的帖子

TinyMCE添加切换样式

我正在研究一个TinyMCE插件,我想要它做的一件事是注册命令/按钮切换自定义格式.

例如,如果单击TinyMCE中的粗体按钮,它将以粗体文本显示突出显示的粗体按钮.深入研究源代码我看到这种情况发生在:tinymce.EditorCommands.addCommands认为我似乎无法弄清楚如何复制它.TinyMCE的文档也很糟糕=(

所以给定customFormat我希望能够通过我的插件设置一个按钮,当应用customFormat时,它会像工具栏上的Bold,Italics和其他类似按钮一样显示.点击我的customFormat切换格式开/关.我可以通过"addCommand"和"addButton"轻松完成toogle,但是它没有像Bold那样的状态跟踪.

显示我当前的非工作尝试(此代码位于我的插件创建方法的init中):

tinymce.EditorCommands.call('addCommands', {
   'MyFormat' :  function(name) {
      ed.formatter.toggle("customFormat");
    }
},'exec');

tinymce.EditorCommands.call('addCommands', {
   'MyFormat' : function(name) {
       return ed.formatter.match('customFormat');
    } 
},'state');

ed.addButton('customformat', {cmd : 'MyFormat'});
Run Code Online (Sandbox Code Playgroud)

以下是addCommands"文档"的链接:http://www.tinymce.com/wiki.php/API3:method.tinymce.EditorCommands.addCommands

经过更多的环顾四周后,我发现这似乎是完美的:http://www.tinymce.com/wiki.php/API3: method.tinymce.Editor.addQueryStateHandler

但是当我实现代码时,它不会改变按钮的状态:

  ed.addCommand('MyFormat', function(ui, v) {
    ed.formatter.toggle("thoughtFormat");
  });

  ed.addQueryStateHandler('MyFormat', function() { 
      return ed.formatter.match('thoughtFormat');
  });

  ed.addButton('myformat', {cmd : 'MyFormat'});
Run Code Online (Sandbox Code Playgroud)

javascript tinymce

7
推荐指数
2
解决办法
5765
查看次数

让AuthLogic使用ActionCable

我正在开发一个新的Rails 5(RC1)应用程序.我使用AuthLogic进行用户身份验证,它一如既往地运行良好,直到我进入ActionCable.

#app/channels/application_cable/connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = UserSession.find
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我收到错误:您必须在创建对象之前使用控制器对象激活Authlogic :: Session :: Base.controller

我试过了:

Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为Connection类不是Controller.

我看一下AuthLogic代码,但我无法弄清楚如何绕过它对控制器对象的依赖.我只需要加载用户的会话.有什么想法吗?

ruby ruby-on-rails authlogic ruby-on-rails-5 actioncable

0
推荐指数
1
解决办法
616
查看次数