(function () {
    var a = {
        exec: function (editor) {
            var data = "";
            var mySelection = editor.getSelection();
            if (CKEDITOR.env.ie) {
                mySelection.unlock(true);
                data = mySelection.getNative().createRange().text;
            } else {
                data = mySelection.getNative();
            }

            var startEle = mySelection.getStartElement();
            var text = editor.getSelection().getSelectedText();
            if (data != null && data != '') {
                var className = startEle.getAttribute("class");
                if (className == "level2") {
                    var tempP = new CKEDITOR.dom.element('p');
                    tempP.insertBefore(startEle);
                    tempP.setHtml(text);
                    startEle.remove();
                } else if (className == "level1") {
                    startEle.setAttribute("class", "level2");
                } else {
                    editor.insertHtml('<div class="level2">' + data + '</div>');
                }
            }
        }
    },
    b = 'catalog2';
    CKEDITOR.plugins.add(b, {
        init: function (editor) {
            editor.addCommand(b, a);
            editor.ui.addButton('catalog2', {
                label: '二级目录',
                className: 'catalog',
                command: b
            });
        }
    });
})();