"use strict";
UE.registerUI('autoformat',
function (editor) {
var btn = new UE.ui.Button({
name: 'autoformat',
title: '一键排版',
editor: editor,
className: 'power-edui-autoformat',
cssRules: 'backgourd:none',
onclick: function () {
editor.execCommand('selectall');
editor.execCommand('autoformat');
var content = editor.getContent();
var $div = $('
').html(content);
$div.find("p:first").css('text-indent', 'initial');
editor.setContent($div.html());
}
});
btn.label = '';
btn.showIcon = false;
editor.addListener('selectionchange',
function () {
var state = editor.queryCommandState("autoformat");
if (state === -1) {
//当按钮按下后被放开就执行这里
btn.setDisabled(true);
btn.setChecked(false);
} else {
//当ue内容改变后执行这里
btn.setDisabled(false);
btn.setChecked(0);
}
});
return btn;
});