📄 htmlarea.js
字号:
if((HTMLArea.is_ie && root.scopeName != 'HTML') || (!HTMLArea.is_ie && /:/.test(tag)) || /o:p/.test(tag)) { stripTag(root); return false; } else { clearClass(root); clearStyle(root); for (i=root.firstChild;i;i=next) { next = i.nextSibling; if(i.nodeType == 1 && parseTree(i)) { checkEmpty(i); } } } return true; } parseTree(html);};HTMLArea.wordCleanLater = function(editorNumber,doUpdateToolbar) { var editor = RTEarea[editorNumber]["editor"]; HTMLArea._wordClean(editor, editor._doc.body); if (doUpdateToolbar) editor.updateToolbar();};/* * Handler for paste, dragdrop and drop events */HTMLArea.cleanWordOnPaste = function(ev) { if(!ev) var ev = window.event; var target = (ev.target) ? ev.target : ev.srcElement; var owner = (target.ownerDocument) ? target.ownerDocument : target; while (HTMLArea.is_ie && owner.parentElement ) { // IE5.5 does not report any ownerDocument owner = owner.parentElement; } // if we dropped an image dragged from the TYPO3 Browser, let's close the browser window if (typeof(browserWin) != "undefined") browserWin.close(); window.setTimeout("HTMLArea.wordCleanLater(" + owner._editorNo + ", true);", 250);};HTMLArea.prototype.forceRedraw = function() { this._doc.body.style.visibility = "hidden"; this._doc.body.style.visibility = "visible";};/* * Focus the editor iframe document or the textarea. */HTMLArea.prototype.focusEditor = function() { switch (this._editMode) { case "wysiwyg" : try { if (HTMLArea.is_safari || HTMLArea.is_opera) this._doc.focus(); else this._iframe.contentWindow.focus(); } catch(e) { }; break; case "textmode": this._textArea.focus(); break; } return this._doc;};HTMLArea.undoTakeSnapshot = function(editorNumber) { var editor = RTEarea[editorNumber]["editor"]; if (editor._doc) editor._undoTakeSnapshot();};/* * Take a snapshot of the current contents for undo */HTMLArea.prototype._undoTakeSnapshot = function() { var curTime = (new Date()).getTime(); var newOne = true; if(this._undoPos >= this.config.undoSteps) { // remove the first element this._undoQueue.shift(); --this._undoPos; } // New undo slot should be used if this is first undoTakeSnapshot call or if undoTimeout is elapsed if (this._undoPos < 0 || this._undoQueue[this._undoPos].time < curTime - this.config.undoTimeout) { ++this._undoPos; } else { newOne = false; } // use the fasted method (getInnerHTML); var txt = this.getInnerHTML(); if (newOne){ // If previous slot contain same text new one should not be used if(this._undoPos == 0 || this._undoQueue[this._undoPos - 1].text != txt){ this._undoQueue[this._undoPos] = { text: txt, time: curTime }; this._undoQueue.length = this._undoPos + 1; } else { this._undoPos--; } } else { if(this._undoQueue[this._undoPos].text != txt){ this._undoQueue[this._undoPos].text = txt; this._undoQueue.length = this._undoPos + 1; } }};HTMLArea.setUndoQueueLater = function(editorNumber,op) { var editor = RTEarea[editorNumber]["editor"]; if (op == "undo") { editor.setHTML(editor._undoQueue[--editor._undoPos].text); } else if (op == "redo") { if(editor._undoPos < editor._undoQueue.length - 1) editor.setHTML(editor._undoQueue[++editor._undoPos].text); }};HTMLArea.prototype.undo = function() { if(this._undoPos > 0){ // Make sure we would not loose any changes this._undoTakeSnapshot(); if (!HTMLArea.is_opera) this.setHTML(this._undoQueue[--this._undoPos].text); else window.setTimeout("HTMLArea.setUndoQueueLater(" + this._editorNumber + ", 'undo');", 10); }};HTMLArea.prototype.redo = function() { if(this._undoPos < this._undoQueue.length - 1) { // Make sure we would not loose any changes this._undoTakeSnapshot(); // Previous call could make undo queue shorter if (!HTMLArea.is_opera) { if(this._undoPos < this._undoQueue.length - 1) this.setHTML(this._undoQueue[++this._undoPos].text); } else { window.setTimeout("HTMLArea.setUndoQueueLater(" + this._editorNumber + ", 'redo');", 10); } }};/* * Update the enabled/disabled/active state of the toolbar elements */HTMLArea.updateToolbar = function(editorNumber) { var editor = RTEarea[editorNumber]["editor"]; editor.updateToolbar(); editor._timerToolbar = null;};HTMLArea.prototype.updateToolbar = function(noStatus) { var doc = this._doc, text = (this._editMode == "textmode"), selection = this.hasSelectedText(), ancestors = null, cls = new Array(), txt, txtClass, i, cmd, inContext, match, matchAny, k, j, n, commandState; if(!text) { ancestors = this.getAllAncestors(); if(this.config.statusBar && !noStatus) { // Unhook previous events handlers if(this._statusBarTree.hasChildNodes()) { for (i = this._statusBarTree.firstChild; i; i = i.nextSibling) { if(i.nodeName.toLowerCase() == "a") { HTMLArea._removeEvents(i,["click", "contextmenu, mousedown"], HTMLArea.statusBarHandler); i.el = null; i.editor = null; } } } this._statusBarTree.innerHTML = ''; this._statusBarTree.appendChild(document.createTextNode(HTMLArea.I18N.msg["Path"] + ": ")); // clear for (i = ancestors.length; --i >= 0;) { var el = ancestors[i]; if(!el) continue; var a = document.createElement("a"); a.href = "#"; a.el = el; a.editor = this; if (!HTMLArea.is_opera) { HTMLArea._addEvents(a, ["click", "contextmenu"], HTMLArea.statusBarHandler); } else { HTMLArea._addEvents(a, ["mousedown", "click"], HTMLArea.statusBarHandler); } txt = el.tagName.toLowerCase(); a.title = el.style.cssText; if (el.id) { txt += "#" + el.id; } if (el.className) { txtClass = ""; cls = el.className.trim().split(" "); for(j = cls.length; j > 0;) { if(!HTMLArea.reservedClassNames.test(cls[--j])) { txtClass = "." + cls[j]; } } txt += txtClass; } a.appendChild(document.createTextNode(txt)); this._statusBarTree.appendChild(a); if (i != 0) this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb))); } } } for (i in this._toolbarObjects) { var btn = this._toolbarObjects[i]; cmd = i; // Determine if the button should be enabled inContext = true; if (btn.context && !text) { inContext = false; var attrs = []; var contexts = []; if (/(.*)\[(.*?)\]/.test(btn.context)) { contexts = RegExp.$1.split(","); attrs = RegExp.$2.split(","); } else { contexts = btn.context.split(","); } for (j = contexts.length; --j >= 0;) contexts[j] = contexts[j].toLowerCase(); matchAny = (contexts[0] == "*"); for (k = 0; k < ancestors.length; ++k) { if (!ancestors[k]) continue; match = false; for (j = contexts.length; --j >= 0;) match = match || (ancestors[k].tagName.toLowerCase() == contexts[j]); if (matchAny || match) { inContext = true; for (j = attrs.length; --j >= 0;) { if (!eval("ancestors[k]." + attrs[j])) { inContext = false; break; } } if (inContext) break; } } } if (cmd == "CreateLink") btn.state("enabled", (!text || btn.text) && (inContext || selection)); else btn.state("enabled", (!text || btn.text) && inContext && (selection || !btn.selection)); if (typeof(cmd) == "function") { continue; }; // look-it-up in the custom dropdown boxes var dropdown = this.config.customSelects[cmd]; if((!text || btn.text) && (typeof(dropdown) != "undefined")) { dropdown.refresh(this); continue; } switch (cmd) { case "FontName": case "FontSize": if(!text) try { var value = ("" + doc.queryCommandValue(cmd)).toLowerCase(); if(!value) { document.getElementById(btn.elementId).selectedIndex = 0; break; } // We rely on the fact that the variable in config has the same name as button name in the toolbar. var options = this.config[cmd]; k = 0; for (j in options) { if((j.toLowerCase() == value) || (options[j].substr(0, value.length).toLowerCase() == value)) { document.getElementById(btn.elementId).selectedIndex = k; throw "ok"; } ++k; } document.getElementById(btn.elementId).selectedIndex = 0; } catch(e) {} break; case "FormatBlock": var blocks = [ ]; for(var i in this.config['FormatBlock']) { blocks[blocks.length] = this.config['FormatBlock'][i]; } var deepestAncestor = this._getFirstAncestor(this._getSelection(), blocks); if(deepestAncestor) { for(var x= 0; x < blocks.length; x++) { if(blocks[x].toLowerCase() == deepestAncestor.tagName.toLowerCase()) document.getElementById(btn.elementId).selectedIndex = x; } } else { document.getElementById(btn.elementId).selectedIndex = 0; } break; case "TextIndicator": if(!text) { try {with (document.getElementById(btn.elementId).style) { backgroundColor = HTMLArea._makeColor(doc.queryCommandValue((HTMLArea.is_ie || HTMLArea.is_safari) ? "BackColor" : "HiliteColor")); // Mozilla if(/transparent/i.test(backgroundColor)) { backgroundColor = HTMLArea._makeColor(doc.queryCommandValue("BackColor")); } color = HTMLArea._makeColor(doc.queryCommandValue("ForeColor")); fontFamily = doc.queryCommandValue("FontName"); // Check if queryCommandState is available fontWeight = "normal"; fontStyle = "normal"; try { fontWeight = doc.queryCommandState("Bold") ? "bold" : "normal"; } catch(ex) { fontWeight = "normal"; }; try { fontStyle = doc.queryCommandState("Italic") ? "italic" : "normal"; } catch(ex) { fontStyle = "normal"; }; }} catch (e) { // alert(e + "\n\n" + cmd); } } break; case "HtmlMode": btn.state("active", text); break; case "LeftToRight": case "RightToLeft": var el = this.getParentElement(); while (el && !HTMLArea.isBlockElement(el)) { el = el.parentNode; } if (el) btn.state("active",(el.style.direction == ((cmd == "RightToLeft") ? "rtl" : "ltr"))); break; case "Bold": case "Italic": case "StrikeThrough": case "Underline": case "Subscript": case "Superscript": case "JustifyLeft": case "JustifyCenter": case "JustifyRight": case "JustifyFull": case "Indent": case "Outdent": case "InsertOrderedList": case "InsertUnorderedList": commandState = false; if(!text) try { commandState = doc.queryCommandState(cmd); } catch(e) { commandState = false; } btn.state("active",commandState); break; default: break; } } if (this._customUndo) this._undoTakeSnapshot(); for (i in this.plugins) { var plugin = this.plugins[i].instance; if (typeof(plugin.onUpdateToolbar) == "function") plugin.onUpdateToolbar(); }};/*************************************************** * DOM TREE MANIPULATION ***************************************************//* * Surround the currently selected HTML source code with the given tags. * Delete the selection, if any. */HTMLArea.prototype.surroundHTML = function(startTag,endTag) { this.insertHTML(startTag + this.getSelectedHTML().replace(HTMLArea.Reg_body, "") + endTag);};/* * Change the tag name of a node. */HTMLArea.prototype.convertNode = function(el,newTagName) { var newel = this._doc.createElement(newTagName), p = el.parentNode; while (el.firstChild) newel.appendChild(el.firstChild); p.insertBefore(newel, el); p.removeChild(el); return newel;};/* * Find a parent of an element with a specified tag */HTMLArea.getElementObject = function(el,tagName) { var oEl = el; while (oEl != null && oEl.nodeName.toLowerCase() != tagName) oEl = oEl.parentNode; return oEl;};/* * Make XHTML-compliant nested list */HTMLArea.prototype.makeNes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -