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

📄 overview-summary-tinymce_engine.class.js.html

📁 tinyMCE在线编辑器使用手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:
	 * <span class="attrib">@param</span> {HTMLElement} replace_element HTML element object to replace.
	 * <span class="attrib">@param</span> {string} form_element_name HTML form element name,
	 * <span class="attrib">@param</span> {DOMDocument} target_document Target document that holds the element.
	 */</span>
	addMCEControl : <span class="reserved">function</span>(replace_element, form_element_name, target_document) {
		var id = <span class="literal">"mce_editor_"</span> + tinyMCE.idCounter++;
		var inst = new TinyMCE_Control(tinyMCE.settings);

		inst.editorId = id;
		<span class="reserved">this</span>.instances[id] = inst;

		inst._onAdd(replace_element, form_element_name, target_document);
	},

	<span class="comment">/**
	 * Removes a TinyMCE editor control instance by id.
	 *
	 * <span class="attrib">@param</span> {string} editor_id Id of editor instance to remove.
	 */</span>
	removeMCEControl : <span class="reserved">function</span>(editor_id) {
		var inst = tinyMCE.getInstanceById(editor_id);

		<span class="reserved">if</span> (inst) {
			inst.switchSettings();

			editor_id = inst.editorId;
			var html = tinyMCE.getContent(editor_id);

			<span class="comment">// Remove editor instance from instances array</span>
			var tmpInstances = new Array();
			<span class="reserved">for</span> (var instanceName in tinyMCE.instances) {
				var instance = tinyMCE.instances[instanceName];
				<span class="reserved">if</span> (!tinyMCE.isInstance(instance))
					continue;

				<span class="reserved">if</span> (instanceName != editor_id)
						tmpInstances[instanceName] = instance;
			}
			tinyMCE.instances = tmpInstances;

			tinyMCE.selectedElement = null;
			tinyMCE.selectedInstance = null;

			<span class="comment">// Remove element</span>
			var replaceElement = document.getElementById(editor_id + <span class="literal">"_parent"</span>);
			var oldTargetElement = inst.oldTargetElement;
			var targetName = oldTargetElement.nodeName.toLowerCase();

			<span class="reserved">if</span> (targetName == <span class="literal">"textarea"</span> || targetName == <span class="literal">"input"</span>) {
				<span class="comment">// Just show the old text area</span>
				replaceElement.parentNode.removeChild(replaceElement);
				oldTargetElement.style.display = <span class="literal">"inline"</span>;
				oldTargetElement.value = html;
			} <span class="reserved">else</span> {
				oldTargetElement.innerHTML = html;

				replaceElement.parentNode.insertBefore(oldTargetElement, replaceElement);
				replaceElement.parentNode.removeChild(replaceElement);
			}
		}
	},

	<span class="comment">/**
	 * Moves the contents from a TinyMCE editor control instance to the hidden textarea
	 * that got replaced with TinyMCE. This is executed automaticly on for example form submit.
	 *
	 * <span class="attrib">@param</span> {boolean} skip_cleanup Optional Skip cleanup, simply move the contents as fast as possible.
	 * <span class="attrib">@param</span> {boolean} skip_callback Optional Skip callback, don't call the save_callback function.
	 */</span>
	triggerSave : <span class="reserved">function</span>(skip_cleanup, skip_callback) {
		<span class="comment">// Cleanup and set all form fields</span>
		<span class="reserved">for</span> (var n in tinyMCE.instances) {
			var inst = tinyMCE.instances[n];
			<span class="reserved">if</span> (!tinyMCE.isInstance(inst))
				continue;

			inst.switchSettings();

			tinyMCE.settings[<span class="literal">'preformatted'</span>] = false;

			<span class="comment">// Default to false</span>
			<span class="reserved">if</span> (typeof(skip_cleanup) == <span class="literal">"undefined"</span>)
				skip_cleanup = false;

			<span class="comment">// Default to false</span>
			<span class="reserved">if</span> (typeof(skip_callback) == <span class="literal">"undefined"</span>)
				skip_callback = false;

			tinyMCE._setHTML(inst.getDoc(), inst.getBody().innerHTML);

			<span class="comment">// Remove visual aids when cleanup is disabled</span>
			<span class="reserved">if</span> (inst.settings[<span class="literal">'cleanup'</span>] == false) {
				tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);
				tinyMCE._setEventsEnabled(inst.getBody(), true);
			}

			tinyMCE._customCleanup(inst, <span class="literal">"submit_content_dom"</span>, inst.contentWindow.document.body);
			var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst, inst.getDoc(), <span class="reserved">this</span>.settings, inst.getBody(), <span class="reserved">this</span>.visualAid, true, true);
			htm = tinyMCE._customCleanup(inst, <span class="literal">"submit_content"</span>, htm);

			<span class="reserved">if</span> (!skip_callback &amp;&amp; tinyMCE.settings[<span class="literal">'save_callback'</span>] != <span class="literal">""</span>)
				var content = eval(tinyMCE.settings[<span class="literal">'save_callback'</span>] + <span class="literal">"(inst.formTargetElementId,htm,inst.getBody());"</span>);

			<span class="comment">// Use callback content if available</span>
			<span class="reserved">if</span> ((typeof(content) != <span class="literal">"undefined"</span>) &amp;&amp; content != null)
				htm = content;

			<span class="comment">// Replace some weird entities (Bug: #1056343)</span>
			htm = tinyMCE.regexpReplace(htm, <span class="literal">"&amp;#40;"</span>, <span class="literal">"("</span>, <span class="literal">"gi"</span>);
			htm = tinyMCE.regexpReplace(htm, <span class="literal">"&amp;#41;"</span>, <span class="literal">")"</span>, <span class="literal">"gi"</span>);
			htm = tinyMCE.regexpReplace(htm, <span class="literal">"&amp;#59;"</span>, <span class="literal">";"</span>, <span class="literal">"gi"</span>);
			htm = tinyMCE.regexpReplace(htm, <span class="literal">"&amp;#34;"</span>, <span class="literal">"&amp;quot;"</span>, <span class="literal">"gi"</span>);
			htm = tinyMCE.regexpReplace(htm, <span class="literal">"&amp;#94;"</span>, <span class="literal">"^"</span>, <span class="literal">"gi"</span>);

			<span class="reserved">if</span> (inst.formElement)
				inst.formElement.value = htm;
		}
	},

	<span class="comment">/**
	 * Resets a forms TinyMCE instances based on form index.
	 *
	 * <span class="attrib">@param</span> {int} form_index Form index to reset.
	 */</span>
	resetForm : <span class="reserved">function</span>(form_index) {
		var i, inst, n, formObj = document.forms[form_index];

		<span class="reserved">for</span> (n in tinyMCE.instances) {
			inst = tinyMCE.instances[n];

			<span class="reserved">if</span> (!tinyMCE.isInstance(inst))
				continue;

			inst.switchSettings();

			<span class="reserved">for</span> (i=0; i&lt;formObj.elements.length; i++) {
				<span class="reserved">if</span> (inst.formTargetElementId == formObj.elements[i].name)
					inst.getBody().innerHTML = inst.startContent;
			}
		}
	},

	<span class="comment">/**
	 * Executes a command on a specific editor instance by id.
	 *
	 * <span class="attrib">@param</span> {string} editor_id TinyMCE editor control instance id to perform comman on.
	 * <span class="attrib">@param</span> {string} command Command name to execute, for example mceLink or Bold.
	 * <span class="attrib">@param</span> {boolean} user_interface True/false state if a UI (dialog) should be presented or not.
	 * <span class="attrib">@param</span> {object} value Optional command value, this can be anything.
	 * <span class="attrib">@param</span> {boolean} focus True/false if the editor instance should be focused first.
	 */</span>
	execInstanceCommand : <span class="reserved">function</span>(editor_id, command, user_interface, value, focus) {
		var inst = tinyMCE.getInstanceById(editor_id);
		<span class="reserved">if</span> (inst) {
			<span class="reserved">if</span> (typeof(focus) == <span class="literal">"undefined"</span>)
				focus = true;

			<span class="reserved">if</span> (focus)
				inst.contentWindow.focus();

			<span class="comment">// Reset design mode if lost</span>
			inst.autoResetDesignMode();

			<span class="reserved">this</span>.selectedElement = inst.getFocusElement();
			<span class="reserved">this</span>.selectedInstance = inst;
			tinyMCE.execCommand(command, user_interface, value);

			<span class="comment">// Cancel event so it doesn't call onbeforeonunlaod</span>
			<span class="reserved">if</span> (tinyMCE.isMSIE &amp;&amp; window.event != null)
				tinyMCE.cancelEvent(window.event);
		}
	},

	<span class="comment">/**
	 * Executes a command on the selected or last selected TinyMCE editor control instance. This function also handles
	 * some non instance specific commands like mceAddControl, mceRemoveControl, mceHelp or mceFocus.
	 *
	 * <span class="attrib">@param</span> {string} command Command name to execute, for example mceLink or Bold.
	 * <span class="attrib">@param</span> {boolean} user_interface True/false state if a UI (dialog) should be presented or not.
	 * <span class="attrib">@param</span> {object} value Optional command value, this can be anything.
	 */</span>
	execCommand : <span class="reserved">function</span>(command, user_interface, value) {
		<span class="comment">// Default input</span>
		user_interface = user_interface ? user_interface : false;
		value = value ? value : null;

		<span class="reserved">if</span> (tinyMCE.selectedInstance)
			tinyMCE.selectedInstance.switchSettings();

		switch (command) {
			case <span class="literal">'mceHelp'</span>:
				tinyMCE.openWindow({
					file : <span class="literal">'about.htm'</span>,
					width : 480,
					height : 380
				}, {
					tinymce_version : tinyMCE.majorVersion + <span class="literal">"."</span> + tinyMCE.minorVersion,
					tinymce_releasedate : tinyMCE.releaseDate,
					inline : <span class="literal">"yes"</span>
				});
			<span class="reserved">return</span>;

			case <span class="literal">'mceFocus'</span>:
				var inst = tinyMCE.getInstanceById(value);
				<span class="reserved">if</span> (inst)
					inst.contentWindow.focus();
			<span class="reserved">return</span>;

⌨️ 快捷键说明

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