如何为我的wysiwyg编辑器包含RTL(从右到左)的支持。 我已经试过document.execCommand('dirRTL',false,null)。但它不起作用。 但Gmail如何做到这一点。我缺少什么对wysiwyg编辑器的RTL支持
感谢, Gautham
如何为我的wysiwyg编辑器包含RTL(从右到左)的支持。 我已经试过document.execCommand('dirRTL',false,null)。但它不起作用。 但Gmail如何做到这一点。我缺少什么对wysiwyg编辑器的RTL支持
感谢, Gautham
好消息是,当涉及到RTL(从右到左)原稿方向操作系统照顾的实际问题。 你只需要将你想要应用RTL的元素作为目标,然后将文本对齐添加到RIGHT并将其指向RTL。只有当你开始输入阿拉伯文时,你才会看到真实的结果,因为不仅文字将从右到左开始,而且它的方向也是如此。
这是一个很老的问题,反正我刚刚实施了一个解决方案,所以我分享。
我用的是bootstrap-wysihtml5-rails gem,这是基于bootstrap3-wysiwyg代码。
编辑器与一个iframe创建的,所以我要做的只是:
<script>
$(window).load(function() {
$('iframe.wysihtml5-sandbox').each(function(i) {
$(this).contents().find("body").css({'direction':'rtl', 'font-family':'Arial'});
});
})
</script>
(我用each
功能,因为我有几个编辑)
最好的解决办法: 编辑文件:wysihtml5- 0.3.0.js并查找行wysihtml5.dom.setAttributes并添加下列行: “direction”:“rtl”,
没有命令可用于execCommand中的文本方向。
下面是我使用“insertHTML”在插入点插入HTML字符串的解决方案。
//Consider tag as the name of the command to execute eg. bold,underline,justifyRight,...
if(tag=='rtl' || tag=='ltr'){
var s=document.getSelection(); \t \t \t
if(s==''){
document.execCommand("insertHTML", false, "<p dir='"+tag+"'></p>");
}else{
document.execCommand("insertHTML", false, "<span dir='"+tag+"'>"+ document.getSelection()+"</span>");
}
}else{
//Default
document.execCommand(tag,false,null);
}
其解决方案取决于插件的类型。 – undefined 2012-04-12 16:04:55
你通过插件的意思......我需要一个纯JavaScript的解决方案:( – 2012-04-12 16:08:54
我的意思是你的所见即所得的编辑器的类型。它能够更好地提供更多的细节。 – undefined 2012-04-12 16:10:51