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

📄 htmlarea.js

📁 Typo3, 开源里边最强大的
💻 JS
📖 第 1 页 / 共 5 页
字号:
	var doc = this._doc;	var docWellFormed = true;		// check if the stylesheets have been loaded	if (this._stylesLoadedTimer) window.clearTimeout(this._stylesLoadedTimer);	var stylesAreLoaded = true;	var errorText = '';	var rules;	for (var rule = 0; rule < doc.styleSheets.length; rule++) {		if (HTMLArea.is_gecko) try { rules = doc.styleSheets[rule].cssRules; } catch(e) { stylesAreLoaded = false; errorText = e; }		if (HTMLArea.is_ie) try { rules = doc.styleSheets[rule].rules; } catch(e) { stylesAreLoaded = false; errorText = e; }		if (HTMLArea.is_ie) try { rules = doc.styleSheets[rule].imports; } catch(e) { stylesAreLoaded = false; errorText = e; }	}	if (!stylesAreLoaded && !HTMLArea.is_wamcom) {		HTMLArea._appendToLog("[HTMLArea::initIframe]: Failed attempt at loading stylesheets: " + errorText + " Retrying...");		this._stylesLoadedTimer = window.setTimeout("HTMLArea.stylesLoaded(" + this._editorNumber + ");", 100);		return false;	}	HTMLArea._appendToLog("[HTMLArea::initIframe]: Stylesheets successfully loaded.");	if (!this.config.fullPage) {		doc.body.style.borderWidth = "0px";		doc.body.className = "htmlarea-content-body";		try { 			doc.body.innerHTML = this._textArea.value;		} catch(e) { 			HTMLArea._appendToLog("[HTMLArea::initIframe]: The HTML document is not well-formed.");			alert(HTMLArea.I18N.msg["HTML-document-not-well-formed"]);			docWellFormed = false;		}	}		// Start undo snapshots	if (this._customUndo) this._timerUndo = window.setInterval("HTMLArea.undoTakeSnapshot(" + this._editorNumber + ");", this.config.undoTimeout);		// Set contents editable	if (docWellFormed) {		if (HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera && !this._initEditMode()) return false;		if (HTMLArea.is_opera) doc.designMode = "on";		if (HTMLArea.is_ie || HTMLArea.is_safari) doc.body.contentEditable = true;		if (HTMLArea.is_ie) doc.selection.empty();		this._editMode = "wysiwyg";		if (doc.body.contentEditable || doc.designMode == "on") HTMLArea._appendToLog("[HTMLArea::initIframe]: Design mode successfully set.");	} else {		this._editMode = "textmode";		this.setMode("docnotwellformedmode");		HTMLArea._appendToLog("[HTMLArea::initIframe]: Design mode could not be set.");	}		// set editor number in iframe and document for retrieval in event handlers	doc._editorNo = this._editorNumber;	if (HTMLArea.is_ie) doc.documentElement._editorNo = this._editorNumber;		// intercept events for updating the toolbar & for keyboard handlers	HTMLArea._addEvents((HTMLArea.is_ie ? doc.body : doc), ["keydown","keypress","mousedown","mouseup","drag"], HTMLArea._editorEvent, true);		// add unload handler	if (!HTMLArea.hasUnloadHandler) {		HTMLArea.hasUnloadHandler = true;		HTMLArea._addEvent((this._iframe.contentWindow ? this._iframe.contentWindow : this._iframe.contentDocument), "unload", HTMLArea.removeEditorEvents);	}		// set cleanWordOnPaste and intercept paste, dragdrop and drop events for wordClean	if (this.config.cleanWordOnPaste) HTMLArea._addEvents((HTMLArea.is_ie ? doc.body : doc), ["paste","dragdrop","drop"], HTMLArea.cleanWordOnPaste, true);	window.setTimeout("HTMLArea.generatePlugins(" + this._editorNumber + ");", 100);};HTMLArea.generatePlugins = function(editorNumber) {	var editor = RTEarea[editorNumber]["editor"];		// check if any plugins have registered generate handlers		// check also if any plugin has a onKeyPress handler	editor._hasPluginWithOnKeyPressHandler = false;	for (var i in editor.plugins) {		var plugin = editor.plugins[i].instance;		if (typeof(plugin.onGenerate) == "function") plugin.onGenerate();		if (typeof(plugin.onGenerateOnce) == "function") {			plugin.onGenerateOnce();			plugin.onGenerateOnce = null;		}		if (typeof(plugin.onKeyPress) == "function") {			editor._hasPluginWithOnKeyPressHandler = true;		}	}	if (typeof(editor.onGenerate) == "function") {		editor.onGenerate();		editor.onGenerate = null;	}	HTMLArea._appendToLog("[HTMLArea::initIframe]: All plugins successfully generated.");	editor.updateToolbar();};/* * When we have a form, on reset, re-initialize the HTMLArea content and update the toolbar */HTMLArea.resetHandler = function(ev) {	if(!ev) var ev = window.event;	var form = (ev.target) ? ev.target : ev.srcElement;	var editor = RTEarea[form._editorNumber]["editor"];	editor.setHTML(editor._textArea.value);	editor.updateToolbar();	var a = form.__msh_prevOnReset;		// call previous reset methods if they were there.	if (typeof(a) != "undefined") {		for (var i=a.length; --i >= 0; ) { a[i](); }	}};/* * Clean up event handlers and object references, undo/redo snapshots, update the textarea for submission */HTMLArea.removeEditorEvents = function(ev) {	if(!ev) var ev = window.event;	HTMLArea._stopEvent(ev);	if (Dialog._modal) {		Dialog._modal.close();		Dialog._modal = null;	}	for (var ed = RTEarea.length; --ed > 0 ;) {		var editor = RTEarea[ed]["editor"];		if(editor) {			RTEarea[ed]["editor"] = null;				// save the HTML content into the original textarea for submit, back/forward, etc.			editor._textArea.value = editor.getHTML();				// release undo/redo snapshots			window.clearInterval(editor._timerUndo);			editor._undoQueue = null;				// release events			if (HTMLArea.is_ie) HTMLArea._cleanup(editor);		}	}	if (HTMLArea._eventCache && !HTMLArea.is_opera) HTMLArea._eventCache.flush();};/* * Switch editor mode; parameter can be "textmode" or "wysiwyg". *  If no parameter was passed, toggle between modes. */HTMLArea.prototype.setMode = function(mode) {	if (typeof(mode) == "undefined") var mode = (this._editMode == "textmode") ? "wysiwyg" : "textmode";	switch (mode) {		case "textmode":		case "docnotwellformedmode":			this._textArea.value = this.getHTML();			this._iframe.style.display = "none";			this._textArea.style.display = "block";			if(this.config.statusBar) {				var statusBarTextMode = document.createElement("span");				statusBarTextMode.className = "statusBarTextMode";				statusBarTextMode.appendChild(document.createTextNode(HTMLArea.I18N.msg["TEXT_MODE"]));				this._statusBar.innerHTML = '';				this._statusBar.appendChild(statusBarTextMode);			}			this._editMode = "textmode";			break;		case "wysiwyg":			if(HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) this._doc.designMode = "off";			try {				if(!this.config.fullPage) this._doc.body.innerHTML = this.getHTML();					else this.setFullHTML(this.getHTML());			} catch(e) {				alert(HTMLArea.I18N.msg["HTML-document-not-well-formed"]);				break;			}			this._textArea.style.display = "none";			this._iframe.style.display = "block";			if(HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) this._doc.designMode = "on";			if(this.config.statusBar) {				this._statusBar.innerHTML = "";				this._statusBar.appendChild(this._statusBarTree);			}			this._editMode = "wysiwyg";			break;		default:			return false;	}	if (!(mode == "docnotwellformedmode")) this.focusEditor();	for (var i in this.plugins) {		var plugin = this.plugins[i].instance;		if (typeof(plugin.onMode) == "function") { plugin.onMode(mode); }	}};/* * Initialize iframe content when in full page mode */HTMLArea.prototype.setFullHTML = function(html) {	var save_multiline = RegExp.multiline;	RegExp.multiline = true;	if(html.match(HTMLArea.RE_doctype)) {		this.setDoctype(RegExp.$1);		html = html.replace(HTMLArea.RE_doctype, "");	};	RegExp.multiline = save_multiline;	if(!HTMLArea.is_ie) {		if(html.match(HTMLArea.RE_head)) this._doc.getElementsByTagName("head")[0].innerHTML = RegExp.$1;		if(html.match(HTMLArea.RE_body)) this._doc.getElementsByTagName("body")[0].innerHTML = RegExp.$1;	} else {		var html_re = /<html>((.|\n)*?)<\/html>/i;		html = html.replace(html_re, "$1");		this._doc.open();		this._doc.write(html);		this._doc.close();		this._doc.body.contentEditable = true;		return true;	};};/*************************************************** *  PLUGINS, STYLESHEETS, AND IMAGE AND POPUP URL'S ***************************************************//* * Create the specified plugin and register it with this HTMLArea */HTMLArea.prototype.registerPlugin = function() {	var plugin = arguments[0];	var args = [];	for (var i=1; i < arguments.length; ++i) { args.push(arguments[i]); }	this.registerPlugin2(plugin, args);};/* * A variant of the function above where the plugin arguments are already packed in an array. * Externally, it should be only used in the full-screen editor code,  * in order to initialize plugins with the same parameters as in the opener window. */HTMLArea.prototype.registerPlugin2 = function(plugin, args) {	if (typeof(plugin) == "string") {		var plugin = eval(plugin);	};	if (typeof(plugin) == "undefined") {		HTMLArea._appendToLog("ERROR [HTMLArea::registerPlugin]: Can't register undefined plugin.");		return false;	};	var obj = new plugin(this, args);	if (obj) {		var clone = {};		var info = plugin._pluginInfo;		for (var i in info) {			clone[i] = info[i];		}		clone.instance = obj;		clone.args = args;		this.plugins[plugin._pluginInfo.name] = clone;	} else {		HTMLArea._appendToLog("ERROR [HTMLArea::registerPlugin]: Can't register plugin " + plugin.toString() + ".");	};};/* * Load the required plugin script and, unless not requested, the language file */HTMLArea.loadPlugin = function(pluginName,noLangFile,url) {	if (typeof(url) == "undefined") {		var dir = _editor_url + "plugins/" + pluginName;		var plugin = pluginName.replace(/([a-z])([A-Z])([a-z])/g, "$1" + "-" + "$2" + "$3").toLowerCase() + ".js";		var plugin_file = dir + "/" + plugin;		HTMLArea.loadScript(plugin_file);		if (typeof(noLangFile) == "undefined" || !noLangFile) {			var plugin_lang = dir + "/lang/" + _editor_lang + ".js";			HTMLArea._scripts.push(plugin_lang);		}	} else {		HTMLArea.loadScript(url);	}};/* * Load a stylesheet file */HTMLArea.loadStyle = function(style, plugin, url) {	if (typeof(url) == "undefined") {		var url = _editor_url || '';		if (typeof(plugin) != "undefined") { url += "plugins/" + plugin + "/"; }		url += style;		if (/^\//.test(style)) { url = style; }	}	var head = document.getElementsByTagName("head")[0];	var link = document.createElement("link");	link.rel = "stylesheet";	link.href = url;	head.appendChild(link);};/* * Load the editor skin */HTMLArea.loadStyle('','',_editor_CSS);/* * Get the url of some image */HTMLArea.prototype.imgURL = function(file, plugin) {	if (typeof(plugin) == "undefined") return _editor_skin + this.config.imgURL + file;		else return _editor_skin + this.config.imgURL + plugin + "/" + file;};/* * Get the url of some popup */HTMLArea.prototype.popupURL = function(file) {	var url = "";	if(file.match(/^plugin:\/\/(.*?)\/(.*)/)) {		var plugin = RegExp.$1;		var popup = RegExp.$2;		if(!/\.html$/.test(popup)) popup += ".html";		url = _editor_url + "plugins/" + plugin + "/popups/" + popup;	} else {		url = _typo3_host_url + _editor_url + this.config.popupURL + file;	}	return url;};/*************************************************** *  EDITOR UTILITIES ***************************************************/HTMLArea.getInnerText = function(el) {	var txt = '', i;	if(el.firstChild) {		for(i=el.firstChild;i;i =i.nextSibling) {			if(i.nodeType == 3) txt += i.data;			else if(i.nodeType == 1) txt += HTMLArea.getInnerText(i);		}	} else {		if(el.nodeType == 3) txt = el.data;	}	return txt;};HTMLArea._wordClean = function(editor,html) {	function clearClass(node) {		var newc = node.className.replace(/(^|\s)mso.*?(\s|$)/ig,' ');		if(newc != node.className) {			node.className = newc;			if(!/\S/.test(node.className)) node.removeAttribute("className");		}	}	function clearStyle(node) {		if (HTMLArea.is_ie) var style = node.style.cssText;			else var style = node.getAttribute("style");		if (style) {			var declarations = style.split(/\s*;\s*/);			for (var i = declarations.length; --i >= 0;) {				if(/^mso|^tab-stops/i.test(declarations[i]) || /^margin\s*:\s*0..\s+0..\s+0../i.test(declarations[i])) declarations.splice(i,1);			}			node.setAttribute("style", declarations.join("; "));		}	}	function stripTag(el) {		if(HTMLArea.is_ie) {			el.outerHTML = HTMLArea.htmlEncode(el.innerText);		} else {			var txt = document.createTextNode(HTMLArea.getInnerText(el));			el.parentNode.insertBefore(txt,el);			el.parentNode.removeChild(el);		}	}	function checkEmpty(el) {		if(/^(span|b|strong|i|em|font)$/i.test(el.tagName) && !el.firstChild) el.parentNode.removeChild(el);	}	function parseTree(root) {		var tag = root.tagName.toLowerCase(), i, next;

⌨️ 快捷键说明

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