⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coreeditor.js

📁 asp的bbs程序
💻 JS
📖 第 1 页 / 共 3 页
字号:
            var node = this.Document.body.lastChild;
            while (node && node.nodeType != 3) {
                node = node.lastChild;
            }
            if (node) {
                var value = node.nodeValue;
                var lastChar = value.substring(value.length - 1);
                if (lastChar == ' ')
                    node.nodeValue = value.substring(0, value.length - 1);
            }
        }

        // 初始转换状态
        setTimeout(function () {
            if (self.Selectable || self.IsSwitch) self.SelectOneEidtor();

            // 处理编辑器初始化用户设置
            if (!self.FirstRun) {
                self.FirstRun = true;

                // 开启模式
                if (self.AllowUBB && !self.AllowHTML) {
                        Toolbar.ubbMode();
                }
                if (!self.AllowUBB && self.AllowHTML) {
                        Toolbar.xhtmlMode();
                }

                if (self.DMode == Config.UBB && self.AllowUBB) {
                    self.ChangeStateAndButton(Config.UBB);
                    return;
                }
                if (self.DMode == Config.XHTML && self.AllowHTML) {
                    self.ChangeStateAndButton(Config.XHTML);
                    return;
                }
                if (self.DMode == Config.WYSIWYG) {
                    //self.ChangeStateAndButton(Config.WYSIWYG);
                    //return;
                }
            }

        }, 100);
    },

    // 获取文档对象
    GetDocument : function () {
        try {
            return this.Window.document;
        }
        catch (e) {
            try {
                return window.frames[this.Name].window.document;
            }
            catch (e) {
                return null;
            }
        }
    },

    // 编辑器获取焦点
    Focus : function () {
        if (!this.isWYSIWYG()) return;
        // 切换模式时,产生异常
        try {
            if (Browser.IsIELike)
                this.Document.body && this.Document.body.focus();
            else
                this.Window.focus();
        }
        catch (e) {}
    },

    // 移动到某个节点之后
    SelectOne : function (node) {
        if (!node) return;
        if (Browser.IsIE) {
            try  {
                var range = this.Document.selection.createRange();
                range.moveToElementText(node);
                range.setEndPoint('StartToEnd', range);
                range.select();
            }
            catch (e) {
                this.Document.body.focus();
                this.SelectOne(node);
            }
        }
        else {
            // 防止多编辑器引起错误
            if (!this.SelectRange) return;
            // (1)
            if (node.childNodes.length > 0) {
                this.SelectRange.selectAllChildren(node);
                this.SelectRange.collapseToEnd();
            }
            else {
                try {
                    this.SelectRange.selectNode(node);
                    var range = this.SelectRange.getRangeAt(0);
                    range.collapse(false);
                }
                catch (e) {}
            }
            this.Focus();
        }
        this.GetRange();
    },
    
    // 选择编辑框
    SelectOneEidtor : function () {
        this.SelectOne(this.Document.body);
        if (!Browser.IsIE) {
            if (Browser.IsOpera)
                this.Document.body.scrollTop = 1000000;
            else
                this.Window.scrollByLines(1000000);
        }
    },
    
    // 选择文本框
    SelectOneTextArea : function () {
        var TextArea = this.TextArea;
        var value = TextArea.value;
        if (value != '') {
            if (Browser.IsIELike) {
                var range = TextArea.createTextRange();
                range.text = value;
                range.collapse(false);
                range.select();
            }
            else {
                TextArea.setSelectionRange(value.length, value.length);
                this.TextRangeStart = this.TextRangeEnd = value.length;
            }
        }
        
        if (!Browser.IsIE) {
            this.TextArea.scrollTop = 1000000;
        }
        TextArea.focus();
    },

    // 隐藏工具条
    ShowToolbar : function () {
        this.HideToolbar(false);
    },

    // 隐藏工具条
    HideToolbar : function (hidden) {
        Config.ToolbarVisibility = hidden === false ? true : false;
        hidden = hidden !== false ? 'none' : 'block';
        $(this.ToolBarName).style.display = hidden;
        $(this.StatusBarName).style.display = hidden;
        this.Resize();
    },

    // 改变存储区大小
    Resize : function () {
        if (!this.EditorWindow) return;
        var width = this.EditorWindow.offsetWidth - 4 - 10 + 'px';
        var height = this.EditorWindow.offsetHeight - $(this.ToolBarName).offsetHeight - $(this.StatusBarName).offsetHeight - 4 - 8 + 'px';
        
        var editorArea = $(this.EditorAreaName);
        try {
            editorArea.style.width = width;
            this.EditorIframe && (this.EditorIframe.style.width = width);
        }
        catch (e) {}
        try {
            editorArea.style.height = height;
            this.EditorIframe && (this.EditorIframe.style.height = height);
        }
        catch (e) {}
        try {
            if (this.TextArea) {
                this.TextArea.style.width = '100%';
                this.TextArea.style.height = editorArea.offsetHeight - 2 + 'px';
            }
        }
        catch (e) {}
    },
    // 增加高度
    AddHeight : function () {
        var h = this.EditorWindow.offsetHeight + this.StepHeight;
        this.EditorWindow.style.height = h + 'px';
        if (Browser.IsSafari) this.Resize();
    },
    // 减少高度
    MinusHeight : function () {
        var h = this.EditorWindow.offsetHeight;
        if (h - this.StepHeight < this.MinHeight) {
            h = this.MinHeight;
        }
        else {
            h -= this.StepHeight;
        }
        this.EditorWindow.style.height = h + 'px';
        if (Browser.IsSafari) this.Resize();
    },

    // 设置html内容
    SetHtml : function (html) {
        this.CreateEditorArea(html);
        this.EditType = Config.WYSIWYG;
        this.ChangeStateAndButton(Config.WYSIWYG);
    },

    // 设置text内容
    SetText : function (text) {
        this.CreateTextArea(text, Config.XHTML);
    },

    // 获取内容
    GetSource : function (requireHtml) {
        var str;
        switch (this.EditType) {
            case Config.WYSIWYG:
                if (requireHtml || this.AllowHTML)
                    str = UBB.imageHTMLUrlToSign(UBB.multimediaHtmlToUbb(this.GetXhtmlFromHtml()));
                else 
                    str = this.GetUBBFromXHtml(false);
                break;
            case Config.XHTML:
                if (requireHtml || this.AllowHTML)
                    str = this.GetTextContent();
                else 
                    str = this.GetUBBFromXHtml(true);
                break;
            case Config.UBB:
                if (!requireHtml && this.AllowUBB)
                    str = this.GetTextContent();
                else 
                    str = this.GetXHtmlFromUBB(false);
                break;
        }
        return str;
    },
    // 为_TextField赋值
    _GetSource : function () {
        var str;
        switch (this.EditType) {
            case Config.WYSIWYG:
                if (this.TMode == Config.UBB)
                    str = this.GetUBBFromXHtml(false);
                else
                    str = UBB.imageUBBUrlToSign(this.GetXhtmlFromHtml());
                break;
            case Config.XHTML:
                if (this.TMode == Config.UBB)
                    str = this.GetUBBFromXHtml(true);
                else
                    str = this.GetTextContent();
                break;
            case Config.UBB:
                if (this.TMode == Config.UBB)
                    str = this.GetTextContent();
                else
                    str = this.GetXHtmlFromUBB(false);
                break;
        }
        return str;
    },
    GetHtmlSource : function () {
        return UBB.imageHTMLSignToUrl(this.GetSource(true));
    },

    // html转xhtml
    GetXhtmlFromHtml : function () {
        cXml.HtmlToXHtml(this.Document.body);
        var content = cXml.GetXmlString()
            .replace(Config.NotAllowHtmlTag(), '')
            .replace(/(<br[^\>]*?>)/gi, '$1\r\n');
        return content;
    },

    // html/xhtml转ubb
    GetUBBFromXHtml : function (isXHtml) {
        var html = '';
        if (isXHtml)
            html = this.GetTextContent();
        else
            html = this.GetXhtmlFromHtml();
        html = html.replace(/\r|\n/gi, '')
        return UBB.imageUBBUrlToSign(UBB.xhtmlToUbb(UBB.multimediaHtmlToUbb(html)));
    },

    // ubb转html/xhtml
    GetXHtmlFromUBB : function (isXHTML) {
        var str = UBB.ubbToXhtml(this.GetTextContent());
        if (isXHTML) {
            str = UBB.imageHTMLUrlToSign(str)
                .replace(/(<br[^\>]*?>)/gi, '$1\r\n');
        }
        return str;
    },

    // 获取html内容
    GetHtmlContent : function () {
        return this.Document.body.innerHTML;
    },

    // 获取文本内容
    GetTextContent : function () {
        try {
            return this.TextArea.value;
        }
        catch (e) {
            return '';
        }
    },

    // 更新文本域内容
    UpdateTextField : function (only) {
        var value = this.GetSource();
        if (value == this.TextField.value) return;

        var type;
        if (this.AllowHTML && this.AllowUBB) {
            type = this.EditType == Config.UBB ? 'ubb' : 'html';
            if (this.EditorType != Config.UBB) {
                value = UBB.someXhtmlToUbb(value);
                value = UBB.codeXhtmlToUbb(value);
            }
        }
        else if (this.AllowHTML)
            type = 'html';
        else
            type = 'ubb';

        this.EditorType.value = type;
        this.TextField.value = value;
        
        if (only) return;
        
        // 存储临时内容
        // 格式转换
        if (this.TempValue.type != this.type) {
            var _value = this.TempValue.first;
            if (this.type == Config.UBB)
                _value = UBB.xhtmlToUbb(_value);
            this.TempValue.first = _value;
        }
        this.TempValue.type = type == 'html' ? Config.XHTML : Config.UBB;
        if (this.TempValue.first == '' && this.TempValue.first != this.TempValue.second)
            this.TempValue.first = this.TempValue.second;
        this.TempValue.second = value;

        this.DisplayTip();

        // 文本域更新调用
        this.EditorObj.AfterChange(
            {DMode:this.EditType,AllowHTML:this.AllowHTML,AllowUBB:this.AllowUBB},
            this.GetHtmlSource()
        );
    },
    
    // 离开页面时是否需要提示
    DisplayTip : function () {
        var isDisplay;
        if (this.TempValue.second == '') isDisplay = false;
        else if (this.TempValue.first == '') isDisplay = true;
        else isDisplay = this.TempValue.second != this.OriginValue;

        this.EditorObj.Submitting(!isDisplay);
    },

    // 是否为编辑模式
    isWYSIWYG : function () {
        return this.EditType == Config.WYSIWYG;
    },
    isUBB : function () {
        return this.EditType == Config.UBB;
    },
    isXHTML : function () {
        return this.EditType == Config.XHTML;
    },

    // 转换状态
    ChangeState : function (type) {
        var content;
        this.IsSwitch = false;
        // to WYSIWYG
        if (type == Config.WYSIWYG && this.EditType != Config.WYSIWYG) {
            this.IsSwitch = true;
            if (this.EditType == Config.UBB) {
                content = this.GetXHtmlFromUBB(false);
            }
            else {
                content = this.GetTextContent();
            }
            content = UBB.imageHTMLSignToUrl(content)
            this.CreateEditorArea(UBB.multimediaUbbToHtmlView(content, false));
        }
        // to XHTML
        else if (type == Config.XHTML && this.EditType != Config.XHTML) {
            if (!this.AllowHTML) return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -