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

📄 richtext.js

📁 初学者
💻 JS
📖 第 1 页 / 共 3 页
字号:
				if (this.object) {					argument = this._native2LocalFormatNames[argument];				} else {					if (dojo.render.html.ie) {						argument = "<" + argument + ">";					}				}			}		}	}	if (this.object) {		switch (command) {		  case "hilitecolor":			command = "setbackcolor";			break;		  case "forecolor":		  case "backcolor":		  case "fontsize":		  case "fontname":			command = "set" + command;			break;		  case "formatblock":			command = "setblockformat";		}		if (command == "strikethrough") {			command = "inserthtml";			var range = this.document.selection.createRange();			if (!range.htmlText) {				return;			}			argument = range.htmlText.strike();		} else {			if (command == "inserthorizontalrule") {				command = "inserthtml";				argument = "<hr>";			}		}		if (command == "inserthtml") {			var range = this.document.selection.createRange();			if (this.document.selection.type.toUpperCase() == "CONTROL") {				for (var i = 0; i < range.length; i++) {					range.item(i).outerHTML = argument;				}			} else {				range.pasteHTML(argument);				range.select();			}			returnValue = true;		} else {			if (arguments.length == 1) {				returnValue = this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt);			} else {				returnValue = this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt, argument);			}		}	} else {		if (command == "inserthtml") {			if (dojo.render.html.ie) {				var insertRange = this.document.selection.createRange();				insertRange.pasteHTML(argument);				insertRange.select();				return true;			} else {				return this.document.execCommand(command, false, argument);			}		} else {			if ((command == "unlink") && (this.queryCommandEnabled("unlink")) && (dojo.render.html.mozilla)) {				var selection = this.window.getSelection();				var selectionRange = selection.getRangeAt(0);				var selectionStartContainer = selectionRange.startContainer;				var selectionStartOffset = selectionRange.startOffset;				var selectionEndContainer = selectionRange.endContainer;				var selectionEndOffset = selectionRange.endOffset;				var a = dojo.withGlobal(this.window, "getAncestorElement", dojo.html.selection, ["a"]);				dojo.withGlobal(this.window, "selectElement", dojo.html.selection, [a]);				returnValue = this.document.execCommand("unlink", false, null);				var selectionRange = this.document.createRange();				selectionRange.setStart(selectionStartContainer, selectionStartOffset);				selectionRange.setEnd(selectionEndContainer, selectionEndOffset);				selection.removeAllRanges();				selection.addRange(selectionRange);				return returnValue;			} else {				if ((command == "hilitecolor") && (dojo.render.html.mozilla)) {					this.document.execCommand("useCSS", false, false);					returnValue = this.document.execCommand(command, false, argument);					this.document.execCommand("useCSS", false, true);				} else {					if ((dojo.render.html.ie) && ((command == "backcolor") || (command == "forecolor"))) {						argument = arguments.length > 1 ? argument : null;						returnValue = this.document.execCommand(command, false, argument);					} else {						argument = arguments.length > 1 ? argument : null;						if (argument || command != "createlink") {							returnValue = this.document.execCommand(command, false, argument);						}					}				}			}		}	}	this.onDisplayChanged();	return returnValue;}, queryCommandEnabled:function (command) {	command = this._normalizeCommand(command);	if (this.object) {		switch (command) {		  case "hilitecolor":			command = "setbackcolor";			break;		  case "forecolor":		  case "backcolor":		  case "fontsize":		  case "fontname":			command = "set" + command;			break;		  case "formatblock":			command = "setblockformat";			break;		  case "strikethrough":			command = "bold";			break;		  case "inserthorizontalrule":			return true;		}		if (typeof this._activeX.command[command] == "undefined") {			return false;		}		var status = this.object.QueryStatus(this._activeX.command[command]);		return ((status != this._activeX.status.notsupported) && (status != this._activeX.status.disabled));	} else {		if (dojo.render.html.mozilla) {			if (command == "unlink") {				return dojo.withGlobal(this.window, "hasAncestorElement", dojo.html.selection, ["a"]);			} else {				if (command == "inserttable") {					return true;				}			}		}		var elem = (dojo.render.html.ie) ? this.document.selection.createRange() : this.document;		return elem.queryCommandEnabled(command);	}}, queryCommandState:function (command) {	command = this._normalizeCommand(command);	if (this.object) {		if (command == "forecolor") {			command = "setforecolor";		} else {			if (command == "backcolor") {				command = "setbackcolor";			} else {				if (command == "strikethrough") {					return dojo.withGlobal(this.window, "hasAncestorElement", dojo.html.selection, ["strike"]);				} else {					if (command == "inserthorizontalrule") {						return false;					}				}			}		}		if (typeof this._activeX.command[command] == "undefined") {			return null;		}		var status = this.object.QueryStatus(this._activeX.command[command]);		return ((status == this._activeX.status.latched) || (status == this._activeX.status.ninched));	} else {		return this.document.queryCommandState(command);	}}, queryCommandValue:function (command) {	command = this._normalizeCommand(command);	if (this.object) {		switch (command) {		  case "forecolor":		  case "backcolor":		  case "fontsize":		  case "fontname":			command = "get" + command;			return this.object.execCommand(this._activeX.command[command], this._activeX.ui.noprompt);		  case "formatblock":			var retvalue = this.object.execCommand(this._activeX.command["getblockformat"], this._activeX.ui.noprompt);			if (retvalue) {				return this._local2NativeFormatNames[retvalue];			}		}	} else {		if (dojo.render.html.ie && command == "formatblock") {			return this._local2NativeFormatNames[this.document.queryCommandValue(command)] || this.document.queryCommandValue(command);		}		return this.document.queryCommandValue(command);	}}, placeCursorAtStart:function () {	this.focus();	if (dojo.render.html.moz && this.editNode.firstChild && this.editNode.firstChild.nodeType != dojo.dom.TEXT_NODE) {		dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode.firstChild]);	} else {		dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode]);	}	dojo.withGlobal(this.window, "collapse", dojo.html.selection, [true]);}, placeCursorAtEnd:function () {	this.focus();	if (dojo.render.html.moz && this.editNode.lastChild && this.editNode.lastChild.nodeType != dojo.dom.TEXT_NODE) {		dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode.lastChild]);	} else {		dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode]);	}	dojo.withGlobal(this.window, "collapse", dojo.html.selection, [false]);}, replaceEditorContent:function (html) {	html = this._preFilterContent(html);	if (this.isClosed) {		this.domNode.innerHTML = html;	} else {		if (this.window && this.window.getSelection && !dojo.render.html.moz) {			this.editNode.innerHTML = html;		} else {			if ((this.window && this.window.getSelection) || (this.document && this.document.selection)) {				this.execCommand("selectall");				if (dojo.render.html.moz && !html) {					html = "&nbsp;";				}				this.execCommand("inserthtml", html);			}		}	}}, _preFilterContent:function (html) {	var ec = html;	dojo.lang.forEach(this.contentPreFilters, function (ef) {		ec = ef(ec);	});	if (this.contentDomPreFilters.length > 0) {		var dom = dojo.doc().createElement("div");		dom.style.display = "none";		dojo.body().appendChild(dom);		dom.innerHTML = ec;		dojo.lang.forEach(this.contentDomPreFilters, function (ef) {			dom = ef(dom);		});		ec = dom.innerHTML;		dojo.body().removeChild(dom);	}	return ec;}, _postFilterContent:function (html) {	var ec = html;	if (this.contentDomPostFilters.length > 0) {		var dom = this.document.createElement("div");		dom.innerHTML = ec;		dojo.lang.forEach(this.contentDomPostFilters, function (ef) {			dom = ef(dom);		});		ec = dom.innerHTML;	}	dojo.lang.forEach(this.contentPostFilters, function (ef) {		ec = ef(ec);	});	return ec;}, _lastHeight:0, _updateHeight:function () {	if (!this.isLoaded) {		return;	}	if (this.height) {		return;	}	var height = dojo.html.getBorderBox(this.editNode).height;	if (!height) {		height = dojo.html.getBorderBox(this.document.body).height;	}	if (height == 0) {		dojo.debug("Can not figure out the height of the editing area!");		return;	}	this._lastHeight = height;	this.editorObject.style.height = this._lastHeight + "px";	this.window.scrollTo(0, 0);}, _saveContent:function (e) {	var saveTextarea = dojo.doc().getElementById("dojo.widget.RichText.savedContent");	saveTextarea.value += this._SEPARATOR + this.saveName + ":" + this.getEditorContent();}, getEditorContent:function () {	var ec = "";	try {		ec = (this._content.length > 0) ? this._content : this.editNode.innerHTML;		if (dojo.string.trim(ec) == "&nbsp;") {			ec = "";		}	}	catch (e) {	}	if (dojo.render.html.ie && !this.object) {		var re = new RegExp("(?:<p>&nbsp;</p>[\n\r]*)+$", "i");		ec = ec.replace(re, "");	}	ec = this._postFilterContent(ec);	if (this.relativeImageUrls) {		var siteBase = dojo.global().location.protocol + "//" + dojo.global().location.host;		var pathBase = dojo.global().location.pathname;		if (pathBase.match(/\/$/)) {		} else {			var pathParts = pathBase.split("/");			if (pathParts.length) {				pathParts.pop();			}			pathBase = pathParts.join("/") + "/";		}		var sameSite = new RegExp("(<img[^>]* src=[\"'])(" + siteBase + "(" + pathBase + ")?)", "ig");		ec = ec.replace(sameSite, "$1");	}	return ec;}, close:function (save, force) {	if (this.isClosed) {		return false;	}	if (arguments.length == 0) {		save = true;	}	this._content = this._postFilterContent(this.editNode.innerHTML);	var changed = (this.savedContent != this._content);	if (this.interval) {		clearInterval(this.interval);	}	if (dojo.render.html.ie && !this.object) {		dojo.event.browser.clean(this.editNode);	}	if (this.iframe) {		delete this.iframe;	}	if (this.textarea) {		with (this.textarea.style) {			position = "";			left = top = "";			if (dojo.render.html.ie) {				overflow = this.__overflow;				this.__overflow = null;			}		}		if (save) {			this.textarea.value = this._content;		} else {			this.textarea.value = this.savedContent;		}		dojo.html.removeNode(this.domNode);		this.domNode = this.textarea;	} else {		if (save) {			if (dojo.render.html.moz) {				var nc = dojo.doc().createElement("span");				this.domNode.appendChild(nc);				nc.innerHTML = this.editNode.innerHTML;			} else {				this.domNode.innerHTML = this._content;			}		} else {			this.domNode.innerHTML = this.savedContent;		}	}	dojo.html.removeClass(this.domNode, "RichTextEditable");	this.isClosed = true;	this.isLoaded = false;	delete this.editNode;	if (this.window._frameElement) {		this.window._frameElement = null;	}	this.window = null;	this.document = null;	this.object = null;	this.editingArea = null;	this.editorObject = null;	return changed;}, destroyRendering:function () {}, destroy:function () {	this.destroyRendering();	if (!this.isClosed) {		this.close(false);	}	dojo.widget.RichText.superclass.destroy.call(this);}, connect:function (targetObj, targetFunc, thisFunc) {	dojo.event.connect(targetObj, targetFunc, this, thisFunc);}, disconnect:function (targetObj, targetFunc, thisFunc) {	dojo.event.disconnect(targetObj, targetFunc, this, thisFunc);}, disconnectAllWithRoot:function (targetObj) {	dojo.deprecated("disconnectAllWithRoot", "is deprecated. No need to disconnect manually", "0.5");}, _fixContentForMoz:function (html) {	html = html.replace(/<strong([ \>])/gi, "<b$1");	html = html.replace(/<\/strong>/gi, "</b>");	html = html.replace(/<em([ \>])/gi, "<i$1");	html = html.replace(/<\/em>/gi, "</i>");	return html;}});

⌨️ 快捷键说明

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