javascript - Aloha 内联编辑器

标签 javascript ruby-on-rails aloha-editor

我正在尝试向 Aloha 内联编辑器 UI 工具栏添加一个按钮,以便在我的 Rails 应用程序中使用。用于普通 html 页面的代码工作正常。然而,在我的 Rails 应用程序中它不起作用,即使我复制粘贴它也是如此。该页面甚至没有显示任何错误。我的代码如下,它来自他们的网站,只是为了它而把它放在这里:-

<script type="text/javascript">
Aloha.require(['ui/ui', 'ui/button'], function(Ui, Button) {
    var button = Ui.adopt("myButton", Button, {
        click: function(){
            alert("Click!");
        }
    });
});

Aloha.settings.toolbar = {
    tabs: [
     {
        label: 'Save',
        components: [ 'myButton' ]
     }
    ],
    exclude: [ 'strong', 'emphasis', 'strikethrough' ]
};

Aloha.ready( function() {
    var $ = Aloha.jQuery;
    $('.editable').aloha();
});
</script>

最佳答案

我同意!

 Aloha.settings.toolbar = {...};

应该在 aloha.js 的包含之前出现。 但如果是这样,您会遇到 Aloha 在您要使用时未定义的问题。

所以我在演示中找到了解决方法。

(function(window, undefined) {

   if (window.Aloha === undefined || window.Aloha === null ) {
      var Aloha = window.Aloha = {};
   }

   Aloha.settings = { 
      toolbar :{.....} 
   }; 

})(window);

之后,包含 aloha.js 并且设置应该生效。

关于javascript - Aloha 内联编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12196995/

相关文章:

JavaScript/网络开发 : Why do you need a server to connect to hardware?

ruby-on-rails - 如何在 Rails 中为 Mechanize 设置自定义用户代理

ruby-on-rails - 如何设置 Rails Angular 项目来测试 JS?

javascript - 如何使用 Node require 调用导入的异步函数?

javascript - require 未定义 javascript

ruby-on-rails - rails : storing encrypted data in database

javascript - 如何创建一个带有在 div 元素上调用方法时动态使用的 id 的 div 元素?

javascript - 更改 Aloha-Editor 的语言

wiki - 是否有适用于 Aloha 编辑器(或 halo-js)的 wiki?

javascript - 使用 JavaScript 将复选框值传递到数据库