参考:http://www.zyku.net/xhtml/195.html
http://www.cnblogs.com/liuhongfeng/p/4887670.html
试试这里面的
toolbars: [
[
'indent', //首行缩进
]
]
$(".edui-icon-indents").click(function (event) {
var range = window.getSelection().getRangeAt(0);//获取所有内容
var container = range.cloneRange();//获取所有可以编辑内容
var containers = range.cloneContents();//获取不可以编辑但是已选择区域
var isnode = true;
var lan;
var arr = ["p", "h1", "h2", "h3", "h4", "h5", "h6"]; //包含标签
if (container.commonAncestorContainer.children == null) { //单个缩进
isnode = false;
lan = container.commonAncestorContainer.parentNode;
var str = lan.localName;
if ($.inArray(str, arr) == -1) {
return;
}
//缩进
//alert($(lan).css("text-indent"));
if ($(lan).css("text-indent") == "0px") {
$(lan).css("text-indent", "2em");
} else {
$(lan).css("text-indent", "0em");
}
}
else { //多个缩进或是一个选择缩进
lan = container.commonAncestorContainer;
//判断是否包含缩进标签
if (lan.localName == "div") {
//循环判断
if (lan.children.length > 0) {
for (var i = 0; i <= lan.children.length - 1; i++) {
var biaoq = container.commonAncestorContainer.children[i];
for (var s = 0; s <= containers.children.length - 1; s++) {
var biaoqs = containers.children[s];
if(biaoqs.innerText.trim() !=""){
if (biaoq.innerText == biaoqs.innerText) {
//缩进
if ($(biaoq).css("text-indent") == "0px") {
$(biaoq).css("text-indent", "2em");
} else {
$(biaoq).css("text-indent", "0em");
}
}
}
}
}
}
} else {
//缩进
var str = lan.localName;
if ($.inArray(str, arr) == -1) {
return;
}
//缩进
if ($(lan).css("text-indent") == "0px") {
$(lan).css("text-indent", "2em");
}
else {
$(lan).css("text-indent", "0em");
}
}
}
});