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

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

📁 tinyMCE在线编辑器使用手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:

				<span class="reserved">if</span> (!tinyMCE.isMSIE) {
					var isHTML = value.indexOf(<span class="literal">'&lt;'</span>) != -1;
					var sel = <span class="reserved">this</span>.getSel();
					var rng = <span class="reserved">this</span>.getRng();

					<span class="reserved">if</span> (isHTML) {
						<span class="reserved">if</span> (tinyMCE.isSafari) {
							var tmpRng = <span class="reserved">this</span>.getDoc().createRange();

							tmpRng.setStart(<span class="reserved">this</span>.getBody(), 0);
							tmpRng.setEnd(<span class="reserved">this</span>.getBody(), 0);

							value = tmpRng.createContextualFragment(value);
						} <span class="reserved">else</span>
							value = rng.createContextualFragment(value);
					} <span class="reserved">else</span> {
						<span class="comment">// Setup text node</span>
						var el = document.createElement(<span class="literal">"div"</span>);
						el.innerHTML = value;
						value = el.firstChild.nodeValue;
						value = doc.createTextNode(value);
					}

					<span class="comment">// Insert plain text in Safari</span>
					<span class="reserved">if</span> (tinyMCE.isSafari &amp;&amp; !isHTML) {
						<span class="reserved">this</span>.execCommand(<span class="literal">'InsertText'</span>, false, value.nodeValue);
						tinyMCE.triggerNodeChange();
						<span class="reserved">return</span> true;
					} <span class="reserved">else</span> <span class="reserved">if</span> (tinyMCE.isSafari &amp;&amp; isHTML) {
						rng.deleteContents();
						rng.insertNode(value);
						tinyMCE.triggerNodeChange();
						<span class="reserved">return</span> true;
					}

					rng.deleteContents();

					<span class="comment">// If target node is text do special treatment, (Mozilla 1.3 fix)</span>
					<span class="reserved">if</span> (rng.startContainer.nodeType == 3) {
						var node = rng.startContainer.splitText(rng.startOffset);
						node.parentNode.insertBefore(value, node); 
					} <span class="reserved">else</span>
						rng.insertNode(value);

					<span class="reserved">if</span> (!isHTML) {
						<span class="comment">// Removes weird selection trails</span>
						sel.selectAllChildren(doc.body);
						sel.removeAllRanges();

						<span class="comment">// Move cursor to end of content</span>
						var rng = doc.createRange();

						rng.selectNode(value);
						rng.collapse(false);

						sel.addRange(rng);
					} <span class="reserved">else</span>
						rng.collapse(false);

					tinyMCE.fixGeckoBaseHREFBug(2, <span class="reserved">this</span>.getDoc(), value);
				} <span class="reserved">else</span> {
					var rng = doc.selection.createRange();
					var c = value.indexOf(<span class="literal">'&lt;!--'</span>) != -1;

					<span class="comment">// Fix comment bug, add tag before comments</span>
					<span class="reserved">if</span> (c)
						value = tinyMCE.uniqueTag + value;

					<span class="reserved">if</span> (rng.item)
						rng.item(0).outerHTML = value;
					<span class="reserved">else</span>
						rng.pasteHTML(value);

					<span class="comment">// Remove unique tag</span>
					<span class="reserved">if</span> (c) {
						var e = <span class="reserved">this</span>.getDoc().getElementById(<span class="literal">'mceTMPElement'</span>);
						e.parentNode.removeChild(e);
					}
				}

				tinyMCE.triggerNodeChange();
			break;

			case <span class="literal">"mceStartTyping"</span>:
				<span class="reserved">if</span> (tinyMCE.settings[<span class="literal">'custom_undo_redo'</span>] &amp;&amp; <span class="reserved">this</span>.undoRedo.typingUndoIndex == -1) {
					<span class="reserved">this</span>.undoRedo.typingUndoIndex = <span class="reserved">this</span>.undoRedo.undoIndex;
					<span class="reserved">this</span>.execCommand(<span class="literal">'mceAddUndoLevel'</span>);
					<span class="comment">//tinyMCE.debug("mceStartTyping");</span>
				}
				break;

			case <span class="literal">"mceEndTyping"</span>:
				<span class="reserved">if</span> (tinyMCE.settings[<span class="literal">'custom_undo_redo'</span>] &amp;&amp; <span class="reserved">this</span>.undoRedo.typingUndoIndex != -1) {
					<span class="reserved">this</span>.execCommand(<span class="literal">'mceAddUndoLevel'</span>);
					<span class="reserved">this</span>.undoRedo.typingUndoIndex = -1;
					<span class="comment">//tinyMCE.debug("mceEndTyping");</span>
				}
				break;

			case <span class="literal">"mceBeginUndoLevel"</span>:
				<span class="reserved">this</span>.undoRedoLevel = false;
				break;

			case <span class="literal">"mceEndUndoLevel"</span>:
				<span class="reserved">this</span>.undoRedoLevel = true;
				<span class="reserved">this</span>.execCommand(<span class="literal">'mceAddUndoLevel'</span>);
				break;

			case <span class="literal">"mceAddUndoLevel"</span>:
				<span class="reserved">if</span> (tinyMCE.settings[<span class="literal">'custom_undo_redo'</span>] &amp;&amp; <span class="reserved">this</span>.undoRedoLevel) {
					<span class="reserved">if</span> (<span class="reserved">this</span>.undoRedo.add())
						tinyMCE.triggerNodeChange(false);
				}
				break;

			case <span class="literal">"Undo"</span>:
				<span class="reserved">if</span> (tinyMCE.settings[<span class="literal">'custom_undo_redo'</span>]) {
					tinyMCE.execCommand(<span class="literal">"mceEndTyping"</span>);
					<span class="reserved">this</span>.undoRedo.undo();
					tinyMCE.triggerNodeChange();
				} <span class="reserved">else</span>
					<span class="reserved">this</span>.getDoc().execCommand(command, user_interface, value);
				break;

			case <span class="literal">"Redo"</span>:
				<span class="reserved">if</span> (tinyMCE.settings[<span class="literal">'custom_undo_redo'</span>]) {
					tinyMCE.execCommand(<span class="literal">"mceEndTyping"</span>);
					<span class="reserved">this</span>.undoRedo.redo();
					tinyMCE.triggerNodeChange();
				} <span class="reserved">else</span>
					<span class="reserved">this</span>.getDoc().execCommand(command, user_interface, value);
				break;

			case <span class="literal">"mceToggleVisualAid"</span>:
				<span class="reserved">this</span>.visualAid = !<span class="reserved">this</span>.visualAid;
				tinyMCE.handleVisualAid(<span class="reserved">this</span>.getBody(), true, <span class="reserved">this</span>.visualAid, <span class="reserved">this</span>);
				tinyMCE.triggerNodeChange();
				break;

			case <span class="literal">"Indent"</span>:
				<span class="reserved">this</span>.getDoc().execCommand(command, user_interface, value);
				tinyMCE.triggerNodeChange();
				<span class="reserved">if</span> (tinyMCE.isMSIE) {
					var n = tinyMCE.getParentElement(<span class="reserved">this</span>.getFocusElement(), <span class="literal">"blockquote"</span>);
					do {
						<span class="reserved">if</span> (n &amp;&amp; n.nodeName == <span class="literal">"BLOCKQUOTE"</span>) {
							n.removeAttribute(<span class="literal">"dir"</span>);
							n.removeAttribute(<span class="literal">"style"</span>);
						}
					} <span class="reserved">while</span> (n != null &amp;&amp; (n = n.parentNode) != null);
				}
				break;

			case <span class="literal">"removeformat"</span>:
				var text = <span class="reserved">this</span>.selection.getSelectedText();

				<span class="reserved">if</span> (tinyMCE.isOpera) {
					<span class="reserved">this</span>.getDoc().execCommand(<span class="literal">"RemoveFormat"</span>, false, null);
					<span class="reserved">return</span>;
				}

				<span class="reserved">if</span> (tinyMCE.isMSIE) {
					try {
						var rng = doc.selection.createRange();
						rng.execCommand(<span class="literal">"RemoveFormat"</span>, false, null);
					} catch (e) {
						<span class="comment">// Do nothing</span>
					}

					<span class="reserved">this</span>.execCommand(<span class="literal">"SetStyleInfo"</span>, false, {command : <span class="literal">"removeformat"</span>});
				} <span class="reserved">else</span> {
					<span class="reserved">this</span>.getDoc().execCommand(command, user_interface, value);

					<span class="reserved">this</span>.execCommand(<span class="literal">"SetStyleInfo"</span>, false, {command : <span class="literal">"removeformat"</span>});
				}

				<span class="comment">// Remove class</span>
				<span class="reserved">if</span> (text.length == 0)
					<span class="reserved">this</span>.execCommand(<span class="literal">"mceSetCSSClass"</span>, false, <span class="literal">""</span>);

				tinyMCE.triggerNodeChange();
				break;

			default:
				<span class="reserved">this</span>.getDoc().execCommand(command, user_interface, value);

				<span class="reserved">if</span> (tinyMCE.isGecko)
					window.setTimeout(<span class="literal">'tinyMCE.triggerNodeChange(false);'</span>, 1);
				<span class="reserved">else</span>
					tinyMCE.triggerNodeChange();
		}

		<span class="comment">// Add undo level after modification</span>
		<span class="reserved">if</span> (command != <span class="literal">"mceAddUndoLevel"</span> &amp;&amp; command != <span class="literal">"Undo"</span> &amp;&amp; command != <span class="literal">"Redo"</span> &amp;&amp; command != <span class="literal">"mceStartTyping"</span> &amp;&amp; command != <span class="literal">"mceEndTyping"</span>)
			tinyMCE.execCommand(<span class="literal">"mceAddUndoLevel"</span>);
	},

	<span class="comment">/**
	 * Returns a command specific value, for example the current font size.
	 *
	 * <span class="attrib">@param</span> {string} c Command to query value from.
	 * <span class="attrib">@return</span> Command specific value, for example the current font size.
	 * <span class="attrib">@type</span> mixed
	 */</span>
	queryCommandValue : <span class="reserved">function</span>(c) {
		try {
			<span class="reserved">return</span> <span class="reserved">this</span>.getDoc().queryCommandValue(c);
		} catch (e) {
			<span class="reserved">return</span> null;
		}
	},

	<span class="comment">/**
	 * Returns a command specific state, for example if bold is enabled or not.
	 *
	 * <span class="attrib">@param</span> {string} c Command to query state from.
	 * <span class="attrib">@return</span> Command specific state, for example if bold is enabled or not.
	 * <span class="attrib">@type</span> boolean
	 */</span>
	queryCommandState : <span class="reserved">function</span>(c) {
		<span class="reserved">return</span> <span class="reserved">this</span>.getDoc().queryCommandState(c);
	},

	<span class="comment">/**
	 * Gets executed when the editor control instance is added.
	 *
	 * <span class="attrib">@param</span> {HTMLElement} replace_element Element to replace with a editor instance.
	 * <span class="attrib">@param</span> {string} form_element_name Form element name that gets replaced.
	 * <span class="attrib">@param</span> {DOMDocument} target_document Target document reference where the element is located.
	 * <span class="attrib">@private</span>
	 */</span>
	_onAdd : <span class="reserved">function</span>(replace_element, form_element_name, target_document) {
		var hc, th, to, editorTemplate;

		th = <span class="reserved">this</span>.settings[<span class="literal">'theme'</span>];
		to = tinyMCE.themes[th];

		var targetDoc = target_document ? target_document : document;

		<span class="reserved">this</span>.targetDoc = targetDoc;

		tinyMCE.themeURL = tinyMCE.baseURL + <span class="literal">"/themes/"</span> + <span class="reserved">this</span>.settings[<span class="literal">'theme'</span>];
		<span class="reserved">this</span>.settings[<span class="literal">'themeurl'</span>] = tinyMCE.themeURL;

		<span class="reserved">if</span> (!replace_element) {
			alert(<span class="literal">"Error: Could not find the target element."</span>);
			<span class="reserved">return</span> false;
		}

		<span class="reserved">if</span> (to.getEditorTemplate)
			editorTemplate = to.getEditorTemplate(<span class="reserved">this</span>.settings, <span class="reserved">this</span>.editorId);

		var deltaWidth = editorTemplate[<span class="literal">'delta_width'</span>] ? editorTemplate[<span class="literal">'delta_width'</span>] : 0;
		var deltaHeight = editorTemplate[<span class="literal">'delta_height'</span>] ? editorTemplate[<span class="literal">'delta_height'</span>] : 0;
		var html = <span class="literal">'&lt;span id="'</span> + <span class="reserved">this</span>.editorId + <span class="literal">'_parent"&gt;'</span> + editorTemplate[<span class="literal">'html'</span>];

		html = tinyMCE.replaceVar(html, <span class="literal">"editor_id"</span>, <span class="reserved">this</span>.editorId);
		<span class="reserved">this</span>.settings[<span class="literal">'default_document'</span>] = tinyMCE.baseURL + <span class="literal">"/blank.htm"</span>;

		<span class="reserved">this</span>.settings[<span class="literal">'old_width'</span>] = <span class="reserved">this</span>.settings[<span class="literal">'width'</span>];
		<span class="reserved">this</span>.settings[<span class="literal">'old_height'</span>] = <span class="reserved">this</span>.settings[<span class="literal">'height'</span>];

		<span class="comment">// Set default width, height</

⌨️ 快捷键说明

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