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

📄 richtextcanvas.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
        return selectionId;    },    overwriteLines : function (lineNum, numLines, newLines) {        if (!isc.isAn.Array(newLines)) newLines = [newLines];        var line = this.getLine(lineNum);        while (lineNum >= 0 && (!line || !line.getAttribute || !line.getAttribute("isLine"))) {            line = this.getLine(lineNum);            lineNum--        }        if (lineNum < 0) {//            this.logWarn("wiping lineContainer");            this.getLineContainer().innerHTML = isc.emptyString;            line = this.createLine();            this.getLineContainer().appendChild(line);            if (isc.Browser.isMoz) lineNum++;        }                var container = line.parentNode;//        this.logWarn("looking for lineNum: " + lineNum + " - got: " + isc.Log.echoAll(line));        line.innerHTML = newLines[0];//        this.logWarn("replaced line: " + lineNum + " with: " + newLines[0]);        // remove the numLines to replace//        this.logWarn("removing: " + numLines + " lines");        while (numLines != null && numLines-- > 0) {            var removeLine = this.getLine(lineNum+1);            if (removeLine) {//                this.logWarn("removing line: " + removeLine.innerHTML);//                this.logWarn("next line is: " + (removeLine.nextSibling ? removeLine.nextSibling.innerHTML:"null"));                container.removeChild(removeLine);            }        }        // add new lines        for (var i = 1; i < newLines.length; i++) {            if (newLines[i] != -1) this.addLineAfter(lineNum+i-1, newLines[i]);        }    },    addLineAfter : function (lineNum, line) {//        this.logWarn("addAfter: " + lineNum + " line: " + line);        var afterLine = this.getLine(lineNum);        var nextLine = this.getNextLine(afterLine);        line = this.createLine(line);        if (nextLine) {            nextLine.parentNode.insertBefore(line, nextLine);        } else {            afterLine.parentNode.appendChild(line);        }    },    escapeSelection : function (str, escapeValue) {        if (escapeValue == null) escapeValue = isc.emptyString;        return str.replace(/<span [^>]*isSelectionSpan[^>]*><\/span>/gi, escapeValue);//        var r = new RegExp("<span [^>]*id=\"?"+selectionId+"[^>]*><\/span>", "gi");//        return str.replace(r, escapeValue);    },    getSelectionMarkerIndex : function (s) {        var regex = new RegExp("<span [^>]*isSelectionSpan[^>]*>", "i");        var result = regex.exec(s);        if (result) return result.index;        return -1;    },    getLineNumber : function (line) {        var peers = line.parentNode.childNodes;        for (var i = 0; i < peers.length; i++)             if (peers[i] == line) return i;    },    getPreviousLine : function (line) {        return line.previousSibling;    },    getNextLine : function (line) {        return line.nextSibling;    },    getLineContainer : function () {        return isc.Browser.isIE ? this.getHandle() : this.getContentBody();    },    getLine : function (lineNum) {        return this.getLineContainer().childNodes[lineNum];    },    getLineHTML : function (line) {        return line.innerHTML;    },    getLineContents : function (line) {        return this.removeMarkup(this.getLineHTML(line));    },    removeMarkup : function (str, preserveSelectionSpan) {        // FF actually inserts \n or \r in addition to <BR> on the ENTER key, so first remove        // any literal newlines.           //        // IE actually inserts <FONT color="foo"></FONT> tags into the contents in some cases -        // it appears to be tracking the currently applied style, so need to remove that HTML        // markup here.        if (preserveSelectionSpan) {            // remove all tag except <br> and the selectionSpan            str = str.replace(/\n|\r|(<\/?(?!br|BR|([^>]*isSelectionSpan)).*?>)/gi, isc.emptyString);        } else {            // remove all tag except <br>            str = str.replace(/\n|\r|(<\/?(?!br|BR).*?>)/gi, isc.emptyString);        }                str = str.unescapeHTML();                        if (isc.Browser.isOpera) {            var nbsp = new RegExp(String.fromCharCode(160), "g");            str = str.replace(nbsp, " ");        }        return str;    },    // given the selectionId of a selection span in the contents, move the selection cursor to    // that span.  After selection is moved to the span, the selectionMarker is destroyed.    moveSelectionToMarker : function (selectionId) {        var doc = this.getContentDocument();        var selectionNode = doc.getElementById(selectionId);        if (isc.Browser.isIE) {            var range = doc.selection.createRange();            range.moveToElementText(selectionNode);            range.collapse();            range.select();        } else if (isc.Browser.isMoz) {            var selection = this.getContentWindow().getSelection();                        selection.removeAllRanges();            var range = doc.createRange();            range.setStartBefore(selectionNode);            range.setEndBefore(selectionNode);            selection.addRange(range);        }        this.destroySelectionMarker(selectionId);    },    // destroyes the selectionMarker in the contents    destroySelectionMarker : function (selectionId) {        var doc = this.getContentDocument();        var selectionNode = doc.getElementById(selectionId);                    if (selectionNode) selectionNode.parentNode.removeChild(selectionNode);    },    // ------------ Public Runtime API --------------    //>@method  setEditable ()    // Enable / disable editing of the rich text canvas.    // @param   editable    (boolean)   True if we are enabling editing    //<    setEditable : function (editable) {                //this.logWarn("setEditable" + editable);            if (editable == this.editable) return;        this.editable = editable;        this._setHandleEditable(editable);            },    // Actually set the handle to be editable or not.    _setHandleEditable : function (editable, initialPass) {                if (this._useDesignMode()) {            var cDoc = this.getContentDocument();            if (cDoc) {                                if (editable || initialPass) cDoc.designMode = "on";                // Call execCommand directly rather than using our _execCommand method as                // we may have 'this.editable' set to false already.                if (isc.Browser.isMoz) cDoc.execCommand("readonly", false, editable);                if (!editable) cDoc.designMode = "off";            }        } else {            var handle = this.getHandle();            if (handle != null) {                handle.contentEditable = (editable ? true : "inherit");                                if (isc.Browser.isIE) {                    if (!this.isVisible() && this._hasSelection())                         this._emptySelectionForHide();                    else if (isc.Browser.version < 6)                         this._rememberSelection();                }            }        }    },        parentVisibilityChanged : function (vis) {        if (!this._useDesignMode() && isc.Browser.isIE && (vis == isc.Canvas.HIDDEN) &&             this._hasSelection())         {            this._emptySelectionForHide();        }        return this.Super("parentVisibilityChanged", arguments);    },        // Helper method for IE to ensure that our selection is empty.    _emptySelectionForHide : function () {                document.body.focus();        var focusCanvas = isc.EH.getFocusCanvas();        if (focusCanvas != this && focusCanvas != null) {                    focusCanvas.focus();        }    },    // Override setHandleDisabled - when disabled we always want to be non-editable    setHandleDisabled : function (disabled) {        this.Super("setHandleDisabled", arguments);        // If we're editable (when enabled) update the handle to be non editable when         // disabled (or make it editable again when enabled)        if (this.editable) this._setHandleEditable(disabled ? false : true);    },            // ---------- Contents management ---------------    // We need APIs for the developer to both set and retrieve the HTML contained in the    // editable area.        // _rememberContents - stores the contents of the editable area under this.contents.    // Note: getContents() should be used rather than checking this.contents directly.    _rememberContents : function () {        if (!this.isDrawn() || this._drawingFrame) return;        var contents = this._getContents();        if (contents != null) this.contents = contents;    },        _getContents : function () {        var contents;        if (this._useDesignMode()) {            var c_body = this.getContentBody();            if (!c_body) return;            contents = c_body.innerHTML;                } else {            var handle = this.getHandle();            if (handle) contents = handle.innerHTML;        }        return contents;    },    //>	@method	RichTextCanvas.getContents()    ([])    // Returns current the HTML contents of the RichTextCanvas.    // @return (string) (possibly edited) contents    // @see RichTextCanvas.setContents()    //<    getContents : function (dontRemoveMarkup) {        this._rememberContents();            // if a syntaxHiliter or line counting is applied, remove line and hiliting information        // before returning the contents.        if ((this.syntaxHiliter || this.countLines) && !dontRemoveMarkup) {            return this.removeMarkup(this.contents);        } else {            return this.contents;        }    },    //>	@method	RichTextCanvas.setContents()    ([])    //      Changes the contents of a widget to newContents, an HTML string.    //  @param	newContents	(string)    an HTML string to be set as the contents of this widget    //  @see RichTextCanvas.getContents()    //<    setContents : function (contents, force, selectionMarkerIndex, selectionMarkerHTML) {        // setContents in effect gets called twice in FF because the iframe takes a while        // to load, so an end user calling setContents() directly effectively ends up        // setting this.contents which is then picked up via _setupEditArea()        if (contents == this.contents && !force) return;        // don't hilite if we're not drawn since in that case _setContents() would just return        this.contents = contents;        if (!this.isDrawn() || this._drawingFrame) return;        this._setContents(this.hiliteAndCount(contents, selectionMarkerIndex, selectionMarkerHTML));    },    _setContents : function (contents) {        this.contents = contents;        if (!this.isDrawn()) return;                if (this._useDesignMode()) {            var c_body = this.getContentBody();            if (!c_body) return;            c_body.innerHTML = contents;                    } else {            var handle = this.getHandle();            if (handle) handle.innerHTML = contents;        }        // contents have changed, so get updated scrollHeight, check for scrollbars, etc        this.adjustOverflow();    },    hiliteAndCount : function (contents, selectionMarkerIndex, selectionMarkerHTML) {        if (this.syntaxHiliter) {            // if a syntaxHiliter is applied, pass the new contents through it            contents = this.syntaxHiliter.hilite(cont

⌨️ 快捷键说明

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