我正在尝试向 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/