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

📄 toolbar.js

📁 asp的bbs程序
💻 JS
📖 第 1 页 / 共 5 页
字号:
                    
                    var geta = function (node) {
                        while (node) {
                            if (oNode.IsNode(node) && node.tagName.toLowerCase() == 'a') {
                                break;
                            }
                            node = node.parentNode;
                        }
                        return node;
                    };
                    
                    var sa = geta(snode);
                    var ea = geta(enode);
                    
                    // <a>内部
                    if (sa == ea && oNode.IsNode(sa) && sa.tagName.toLowerCase() == 'a') {
                        node = sa;
                        url = sa.getAttribute('href', 2);
                        _text = text = sa.innerHTML;
                    }
                    // <a>节点
                    else if (snode == enode && soff + 1 == eoff && snode.childNodes[soff].tagName.toLowerCase() == 'a') {
                        node = sa = snode.childNodes[soff];
                        url = sa.getAttribute('href', 2);
                        _text = text = sa.innerHTML;
                    }
                    else {
                        node = range.cloneContents();
                    }
                }
                
                var clearTag = function (html) {
                    return html.toString().replace(/<[^>]+?>/g, '');
                };
                var htmlentities = function (html) {
                    return html ? html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : '';
                };
                var _htmlentities = function (html) {
                    return html ? html.replace(/&lt;/gi, '<').replace(/&gt;/gi, '>').replace(/&amp;/gi, '&') : '';
                };
                
                $('url_' + id).value = url;
                $('text_' + id).value = _htmlentities(clearTag(text));
                
                /*
                text = prompt('请输入显示内容:', _htmlentities(clearTag(text)));
                url = prompt('请输入链接地址:', url);
                if (url) {
                    //cEditor.SelectTextRange();
                    if (oNode.IsNode(node) && node.tagName.toLowerCase() == 'a') {
                        node.href = url;
                        node.innerHTML = (text == clearTag(_text) ? _text : htmlentities(text));
                    }
                    else {
                        if (Browser.IsIE) {
                            cEditor.SelectRange.clear();
                            cEditor.InsertContent('<a href="' + url + '">' + (text == clearTag(_text) ? _text : htmlentities(text)) + '</a>');
                        }
                        else {
                            //cEditor.TextRange.deleteContents();
                            var n = cEditor.Document.createElement('a');
                            n.href = url;
                            n.appendChild(text == clearTag(_text) ? node : cEditor.Document.createTextNode(text));
                            cEditor.InsertContentGecko(n);
                        }
                    }
                }*/
            }
            else {
                //url = window.prompt('输入url地址:', 'http://');
                //url && cEditor.SetUBBStyle('[url=\x02]\x01[/url]', url);
            }
        };
    },

    // 取消链接
    createUnlink : function (toolbar, div) {
        if (! this.icons.unlink[0]) return;
        var unlink = this.buttons.unlink = this.createIcon(div, 'unlink');
        unlink.onclick = function () {
            if (!cEditor.isWYSIWYG()) return;
            cEditor.SetStyle('Unlink', false);
            toolbar.changeState(this, false);
        };
    },

    // 插入表情
    createFace : function (toolbar, div) {
        if (! this.icons.face[0]) return;
        var face = this.buttons.face = this.createIcon(div, 'face');
        CSS.AddClass(face, 'face');
        face.onclick = function () {
            if (cEditor.isXHTML()) return;
            //if (!cEditor.isWYSIWYG()) return;
            //var oDiv = oNode.CreateNode('div');
            //oDiv.appendChild(toolbar.faceBlock());
            if (toolbar.facePanel) {
                toolbar.faceNode.parentNode.removeChild(toolbar.faceNode);
                toolbar.facePanel.parentNode.removeChild(toolbar.facePanel);
            }

            toolbar.facePanel = cEditor.Menu(window, 365, 0, '');
            CSS.AddClass(toolbar.facePanel, 'face');
            toolbar.faceBlock(toolbar.facePanel);
            toolbar.facePanel.style.top = Global.GetOffsetTop(this) + this.offsetHeight + 'px';
            toolbar.facePanel.style.left = Global.GetOffsetLeft(this) + 'px';
        };
    },

    // 创建表格
    createTable : function (toolbar, div) {
        if (! this.icons.table[0]) return;
        var self = this;
        var table = this.buttons.table = this.createIcon(div, 'table');

        var mask = CSS.AddBack();
        CSS.AddClass(mask, 'table-mask');
        CSS.SetAlpha(mask, 0);
        mask.Hide();

        var tip = new Tip();
        tip.css.tip = 'table-tip';
        tip.Condition = function () {return true};

        var t;
        var mousedown, mousemove, mouseup;
        if (Browser.IsIE) {
            table.onmousedown = click;
        }
        else {
            table.onclick = click;
        }
        function click () {
            if (cEditor.isXHTML()) return;
            t = toolbar.tablePanel = oNode.CreateNode(Browser.IsIE ? 'a' : 'div');
            oNode.AddNode(t);
            CSS.AddClass(t, 'table-panel');
            t.href = 'javascript:void(0)';

            var x = Global.GetOffsetLeft(table);
            var y = Global.GetOffsetTop(table);
            t.style.left = x + 'px';
            t.style.top = y + table.offsetHeight + 'px';

            var tColor = oNode.CreateNode('span');
            oNode.AddNode(tColor, t);
            CSS.AddClass(tColor, 'table-color');

            var tImage = oNode.CreateNode('span');
            oNode.AddNode(tImage, t);
            CSS.AddClass(tImage, 'table-image');

            mask.Show();
            tip.Create();

            // 事件处理
            var xCount = yCount = 0;
            var is_down = !false;
            var w = 18, h = 18;
            // 是否鼠标按起
            var isMouseUp = false;
            mousedown = function  (e) {
                var obj = $EO(e);
                while (obj) {
                    if (obj == t) break;
                    obj = obj.parentNode;
                }
                if (obj) {
                    // to do
                    is_down = true;
                    x = e.clientX + Global.GetScrollLeft();
                    y = e.clientY + Global.GetScrollTop();
                }
                else {
                    removeevent();
                }
                Events.CancelAll(e);
            }
            mousemove = function (e) {
                if (is_down) {
                    var x_t = e.clientX + Global.GetScrollLeft();
                    var y_t = e.clientY + Global.GetScrollTop();
                    xCount = Math.ceil((x_t - x + w) / 18 - 1);
                    yCount = Math.ceil((y_t - y + h) / 18 - 2);
                    x_t = xCount * 18;
                    y_t = yCount * 18;
                    tColor.style.width = (x_t > 0 ? x_t : 0) + 'px';
                    tColor.style.height = (y_t > 0 ? y_t : 0) + 'px';
                    if (xCount < 3) {
                        if (xCount < 0) xCount = 0;
                        t.style.width = tImage.style.width = 2 * 18 + 'px';
                    }
                    else {
                        t.style.width = tImage.style.width = x_t + 'px';
                    }
                    if (yCount < 3) {
                        if (yCount < 0) yCount = 0;
                        t.style.height = tImage.style.height = 2 * 18 + 'px';
                    }
                    else {
                        t.style.height = tImage.style.height = y_t + 'px';
                    }
                    tip.isCreate && tip.SetText(yCount + ' x ' + xCount);
                }
                Events.CancelAll(e);
            }
            mouseup = function (e) {
                if (isMouseUp) return;
                isMouseUp = true;
                if (is_down) CreateTable(yCount, xCount);
                removeevent();
                try {Events.CancelAll(e);}catch (e) {}
            }
            //Events.AttachEvent(document, 'mousedown', mousedown);
            Events.AttachEvent(document, 'mousemove', mousemove);
            Events.AttachEvent(document, 'mouseup', mouseup);
            Events.AttachEvent(window.top.document, 'mouseup', mouseup);

            CSS.SelectOff();
        };
        table.onmouseup = function () {
            removeevent();
        };
        table.onmouseover = function () {
            if (cEditor.isXHTML()) return;
            table.style.backgroundPosition = (typeof self.icons[table.type][1] == 'string' ? 0 : '-' + self.icons[table.type][1]) + 'px -' + self.yOffset + 'px';
        };
        var _mouseout = table.onmouseout = function () {
            if (cEditor.isXHTML()) return;
            if (table.overState) return;
            table.style.backgroundPosition = (typeof self.icons[table.type][1] == 'string' ? 0 : '-' + self.icons[table.type][1]) + 'px 0';
        };

        function removeevent () {
            is_down = false;
            //Events.RemoveEvent(document, 'mousedown', mousedown);
            Events.RemoveEvent(document, 'mousemove', mousemove);
            Events.RemoveEvent(document, 'mouseup', mouseup);
            Events.RemoveEvent(window.top.document, 'mouseup', mouseup);
            oNode.RemoveNode(t);
            mask.Hide();
            tip.isCreate && tip.Remove();
            _mouseout();
            CSS.SelectOn();
        }

        function CreateTable (row, col) {
            if (row == 0 || col == 0) return;

            var str = '';
            for (var r = 0; r < row; r++) {
                str += '<tr>';
                for (var c = 0; c < col; c++) {
                    str += '<td>&nbsp;</td>';
                }
                str += '</tr>';
            }

            var table = cEditor.isUBB() ? '[table]' + str.replace(/</g, '[').replace(/>/g, ']').replace(/&nbsp;/g, ' ').replace(' ', '\x01') + '[/table]'
                                        : '<table cellspacing="1" border="1" width="100%">' + str + '</table>';
            if (cEditor.isWYSIWYG()) {
                cEditor.SelectTextRange();
                cEditor.InsertContent(table);
            }
            else {
                cEditor.SetUBBStyle(table);
            }
        }
    },

    // 创建code
    createCode : function (toolbar, div) {
        if (! this.icons.code[0]) return;
        var code = this.buttons.code = this.createIcon(div, 'code');
        code.onclick = function () {
            if (cEditor.isXHTML()) return;
            if (cEditor.isUBB()) {
                cEditor.SetUBBStyle('[code]\x01[/code]');
                return;
            }
            var id = Global.Random();
            var panel = PopUp.Panel([
'<div class="editwin-head">',
'    <h3>插入代码</h3>',
'</div>',
'<div class="clearfix editwin-body editwin-code">',
'    <p>',
'    <textarea rows="10" cols="35" id="content_' + id + '"></textarea>',
'    </p>',
'    <p style="float:right">',
'    <span class="xbtn"><input type="button" value="确认" id="confirm_' + id + '" /></span>',
'    <span class="xbtn"><input type="button" value="取消" id="cancel_' + id + '" /></span>',
'    </p>',
'</div>',
'</div>'].join(''), 200, 100);
            CSS.AddClass(panel, 'editwin');
            panel.style.zIndex = 10;
            panel.style.left = Global.GetOffsetLeft(code) + 'px';
            panel.style.top = Global.GetOffsetTop(code) + code.offsetHeight + 'px';
            PopUp.AddPopUp(panel, true);
            PopUp.HideModal(panel);

            $('content_' + id).focus();
            $('confirm_' + id).onclick = function () {
                var content = $('content_' + id).value;
                PopUp.RemovePopUp(panel);

                if (content.replace(/\s*/g, '') == '') return;

                content = content.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r\n|\r|\n/g, '<br />');
                content = '[code]' + content + '[/code]';
                cEditor.SelectTextRange();
                cEditor.InsertContent(content);
                //cEditor.GetRange();
            };
            $('cancel_' + id).onclick = function () {
                PopUp.RemovePopUp(panel);
            };
        };
    },
    
    // 免费
    createFree : function (toolbar, div) {
        if (! this.icons.free[0]) return;
        var free = this.buttons.free = this.createIcon(div, 'free');
        free.onclick = function () {
            if (cEditor.isXHTML()) return;
            if (cEditor.isUBB()) {
                cEditor.SetUBBStyle('[free]\x01[/free]');
                return;
            }
            
            if (cEditor.isWYSIWYG()) {
                var text = Browser.IsIE ? cEditor.TextRange.htmlText : cEditor.SelectRange;
                if (Browser.IsIE) {
                    //cEditor.SelectRange.clear();
                    cEditor.InsertContent('[free]' + text + '[/free]');
                }
                else {
                    var range = cEditor.SelectRange.getRangeAt(0);

⌨️ 快捷键说明

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