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

📄 htmlarea_bak.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                replace(/<([a-z][a-z]*)> *<([a-z][^>]*)> *<\/\1>/gi,'<$2>');        }        D = D.replace(/<([a-z][a-z]*)><\1>/gi,'<$1>').            replace(/<\/([a-z][a-z]*)><\/\1>/gi,'<\/$1>');        // nuke double spaces        D = D.replace(/  */gi,' ');        this.setHTML(D);        this.updateToolbar();    }};HTMLArea.prototype.forceRedraw = function() {    this._doc.body.style.visibility = "hidden";    this._doc.body.style.visibility = "visible";    // this._doc.body.innerHTML = this.getInnerHTML();};// focuses the iframe window.  returns a reference to the editor document.HTMLArea.prototype.focusEditor = function() {    switch (this._editMode) {        case "wysiwyg" : this._iframe.contentWindow.focus(); break;        case "textmode": this._textArea.focus(); break;        default    : alert("ERROR: mode " + this._editMode + " is not defined");    }    return this._doc;};// takes a snapshot of the current text (for undo)HTMLArea.prototype._undoTakeSnapshot = function() {    ++this._undoPos;    if (this._undoPos >= this.config.undoSteps) {        // remove the first element        this._undoQueue.shift();        --this._undoPos;    }    // use the fasted method (getInnerHTML);    var take = true;    var txt = this.getInnerHTML();    if (this._undoPos > 0)        take = (this._undoQueue[this._undoPos - 1] != txt);    if (take) {        this._undoQueue[this._undoPos] = txt;    } else {        this._undoPos--;    }};HTMLArea.prototype.undo = function() {    if (this._undoPos > 0) {        var txt = this._undoQueue[--this._undoPos];        if (txt) this.setHTML(txt);        else ++this._undoPos;    }};HTMLArea.prototype.redo = function() {    if (this._undoPos < this._undoQueue.length - 1) {        var txt = this._undoQueue[++this._undoPos];        if (txt) this.setHTML(txt);        else --this._undoPos;    }};// updates enabled/disable/active state of the toolbar elementsHTMLArea.prototype.updateToolbar = function(noStatus) {    var doc = this._doc;    var text = (this._editMode == "textmode");    var ancestors = null;    if (!text) {        ancestors = this.getAllAncestors();        if (this.config.statusBar && !noStatus) {            this._statusBarTree.innerHTML = HTMLArea.I18N.msg["Path"] + ": "; // clear            for (var i = ancestors.length; --i >= 0;) {                var el = ancestors[i];                if (!el) {                    // hell knows why we get here; this                    // could be a classic example of why                    // it's good to check for conditions                    // that are impossible to happen ;-)                    continue;                }                var a = document.createElement("a");                a.href = "#";                a.el = el;                a.editor = this;                a.onclick = function() {                    this.blur();                    this.editor.selectNodeContents(this.el);                    this.editor.updateToolbar(true);                    return false;                };                a.oncontextmenu = function() {                    // TODO: add context menu here                    this.blur();                    var info = "Inline style:\n\n";                    info += this.el.style.cssText.split(/;\s*/).join(";\n");                    alert(info);                    return false;                };                var txt = el.tagName.toLowerCase();                a.title = el.style.cssText;                if (el.id) {                    txt += "#" + el.id;                }                if (el.className) {                    txt += "." + el.className;                }                a.appendChild(document.createTextNode(txt));                this._statusBarTree.appendChild(a);                if (i != 0) {                    this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb)));                }            }        }    }    for (var i in this._toolbarObjects) {        var btn = this._toolbarObjects[i];        var cmd = i;        var inContext = true;        if (btn.context && !text) {            inContext = false;            var context = btn.context;            var attrs = [];            if (/(.*)\[(.*?)\]/.test(context)) {                context = RegExp.$1;                attrs = RegExp.$2.split(",");            }            context = context.toLowerCase();            var match = (context == "*");            for (var k in ancestors) {                if (!ancestors[k]) {                    // the impossible really happens.                    continue;                }                if (match || (ancestors[k].tagName.toLowerCase() == context)) {                    inContext = true;                    for (var ka in attrs) {                        if (!eval("ancestors[k]." + attrs[ka])) {                            inContext = false;                            break;                        }                    }                    if (inContext) {                        break;                    }                }            }        }        btn.state("enabled", (!text || btn.text) && inContext);        if (typeof cmd == "function") {            continue;        }        // look-it-up in the custom dropdown boxes        var dropdown = this.config.customSelects[cmd];        if ((!text || btn.text) && (typeof dropdown != "undefined")) {            dropdown.refresh(this);            continue;        }        switch (cmd) {            case "fontname":            case "fontsize":            case "formatblock":            if (!text) try {                var value = ("" + doc.queryCommandValue(cmd)).toLowerCase();                if (!value) {                    // FIXME: what do we do here?                    break;                }                // HACK -- retrieve the config option for this                // combo box.  We rely on the fact that the                // variable in config has the same name as                // button name in the toolbar.                var options = this.config[cmd];                var k = 0;                // btn.element.selectedIndex = 0;                for (var j in options) {                    // FIXME: the following line is scary.                    if ((j.toLowerCase() == value) ||                        (options[j].substr(0, value.length).toLowerCase() == value)) {                        btn.element.selectedIndex = k;                        break;                    }                    ++k;                }            } catch(e) {};            break;            case "textindicator":            if (!text) {                try {with (btn.element.style) {                    backgroundColor = HTMLArea._makeColor(                        doc.queryCommandValue(HTMLArea.is_ie ? "backcolor" : "hilitecolor"));                    if (/transparent/i.test(backgroundColor)) {                        // Mozilla                        backgroundColor = HTMLArea._makeColor(doc.queryCommandValue("backcolor"));                    }                    color = HTMLArea._makeColor(doc.queryCommandValue("forecolor"));                    fontFamily = doc.queryCommandValue("fontname");                    fontWeight = doc.queryCommandState("bold") ? "bold" : "normal";                    fontStyle = doc.queryCommandState("italic") ? "italic" : "normal";                }} catch (e) {                    // alert(e + "\n\n" + cmd);                }            }            break;            case "htmlmode": btn.state("active", text); break;            case "lefttoright":            case "righttoleft":            var el = this.getParentElement();            while (el && !HTMLArea.isBlockElement(el))                el = el.parentNode;            if (el)                btn.state("active", (el.style.direction == ((cmd == "righttoleft") ? "rtl" : "ltr")));            break;            default:            try {                btn.state("active", (!text && doc.queryCommandState(cmd)));            } catch (e) {}        }    }    // take undo snapshots    if (this._customUndo && !this._timerUndo) {        this._undoTakeSnapshot();        var editor = this;        this._timerUndo = setTimeout(function() {            editor._timerUndo = null;        }, this.config.undoTimeout);    }    // check if any plugins have registered refresh handlers    for (var i in this.plugins) {        var plugin = this.plugins[i].instance;        if (typeof plugin.onUpdateToolbar == "function")            plugin.onUpdateToolbar();    }};/** Returns a node after which we can insert other nodes, in the current * selection.  The selection is removed.  It splits a text node, if needed. */HTMLArea.prototype.insertNodeAtSelection = function(toBeInserted) {    if (!HTMLArea.is_ie) {        var sel = this._getSelection();        var range = this._createRange(sel);        // remove the current selection        sel.removeAllRanges();        range.deleteContents();        var node = range.startContainer;        var pos = range.startOffset;        switch (node.nodeType) {            case 3: // Node.TEXT_NODE            // we have to split it at the caret position.            if (toBeInserted.nodeType == 3) {                // do optimized insertion                node.insertData(pos, toBeInserted.data);                range = this._createRange();                range.setEnd(node, pos + toBeInserted.length);                range.setStart(node, pos + toBeInserted.length);                sel.addRange(range);            } else {                node = node.splitText(pos);                var selnode = toBeInserted;                if (toBeInserted.nodeType == 11 /* Node.DOCUMENT_FRAGMENT_NODE */) {                    selnode = selnode.firstChild;                }                node.parentNode.insertBefore(toBeInserted, node);                this.selectNodeContents(selnode);                this.updateToolbar();            }            break;            case 1: // Node.ELEMENT_NODE            var selnode = toBeInserted;            if (toBeInserted.nodeType == 11 /* Node.DOCUMENT_FRAGMENT_NODE */) {                selnode = selnode.firstChild;            }            node.insertBefore(toBeInserted, node.childNodes[pos]);            this.selectNodeContents(selnode);            this.updateToolbar();            break;        }    } else {        return null;    // this function not yet used for IE <FIXME>    }};// Returns the deepest node that contains both endpoints of the selection.HTMLArea.prototype.getParentElement = function() {    var sel = this._getSelection();    var range = this._createRange(sel);    if (HTMLArea.is_ie) {        switch (sel.type) {            case "Text":            case "None":            // It seems that even for selection of type "None",            // there _is_ a parent element and it's value is not            // only correct, but very important to us.  MSIE is            // certainly the buggiest browser in the world and I            // wonder, God, how can Earth stand it?            return range.parentElement();            case "Control":            return range.item(0);            default:            return this._doc.body;        }    } else try {        var p = range.commonAncestorContainer;        if (!range.collapsed && range.startContainer == range.endContainer &&            range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes())            p = range.startContainer.childNodes[range.startOffset];        /*        alert(range.startContainer + ":" + range.startOffset + "\n" +              range.endContainer + ":" + range.endOffset);        */        while (p.nodeType == 3) {            p = p.parentNode;        }        return p;    } catch (e) {        return null;    }};// Returns an array with all the ancestor nodes of the selection.HTMLArea.prototype.getAllAncestors = function() {    var p = this.getParentElement();    var a = [];    while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {        a.push(p);        p = p.parentNode;    }    a.push(this._doc.body);    return a;};// Selects the contents inside the given nodeHTMLArea.prototype.selectNodeContents = function(node, pos) {    this.focusEditor();    this.forceRedraw();    var range;

⌨️ 快捷键说明

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