(function () {
    var editor = null;
    UM.registerWidget('formula', {
        tpl: "formula.css\">" +
            "
' + contentHtml.join('') + '
');
                headHtml.push('
' + lang['lang_tab_' + k] + '');
            });
            headHtml.push('
');
            $root.find('.edui-tab-nav').html(headHtml.join(''));
            $root.find('.edui-tab-content').append('
');
            /* 选中第一个tab */
            me.switchTab(0);
        },
        initEvent: function () {
            var me = this;
            //防止点击过后关闭popup
            me.root().on('click', function (e) {
                return false;
            });
            //点击tab切换菜单
            me.root().find('.edui-tab-nav').delegate('.edui-tab-item', 'click', function (evt) {
                me.switchTab(this);
                return false;
            });
            //点击选中公式
            me.root().find('.edui-tab-pane').delegate('.edui-formula-latex-item', 'click', function (evt) {
                var $item = $(this),
                    latex = $item.attr('data-latex') || '';
                if (latex) {
                    me.insertLatex(latex.replace("{/}", "\\"));
                }
                me.$widget.edui().hide();
                return false;
            });
        },
        switchTab:function(index){
            var me = this,
                $root = me.root(),
                index = $.isNumeric(index) ? index:$.inArray(index, $root.find('.edui-tab-nav .edui-tab-item'));
            $root.find('.edui-tab-nav .edui-tab-item').removeClass('edui-active').eq(index).addClass('edui-active');
            $root.find('.edui-tab-content .edui-tab-pane').removeClass('edui-active').eq(index).addClass('edui-active');
            /* 自动长高 */
            me.autoHeight(0);
        },
        autoHeight: function () {
            this.$widget.height(this.root() + 2);
        },
        insertLatex: function (latex) {
            editor.execCommand('formula', latex );
        },
        width: 350,
        height: 400
    });
})();