📄 htmlarea.js
字号:
} if (!created) { tbObj = this.createSelect(code, (tb_group?tb_group:tb_line), first_cell_on_line, labelObj); created = tbObj["created"]; first_cell_on_line = tbObj["first"]; if(tbObj["labelUsed"]) labelObj["labelRef"] = false; } if (!created) HTMLArea._appendToLog("ERROR [HTMLArea::createToolbar]: Unknown toolbar item: " + code); } } } tb_line = HTMLArea.newLine(toolbar); this._htmlArea.appendChild(toolbar);};/* * Handle toolbar element events handler */HTMLArea.toolBarButtonHandler = function(ev) { if(!ev) var ev = window.event; var target = (ev.target) ? ev.target : ev.srcElement; while (target.tagName.toLowerCase() == "img" || target.tagName.toLowerCase() == "div") target = target.parentNode; var obj = target._obj; var editorNumber = obj["editorNumber"]; var editor = RTEarea[editorNumber]["editor"]; if (obj.enabled) { switch (ev.type) { case "mouseover": HTMLArea._addClass(target, "buttonHover"); HTMLArea._addClass(target.parentNode, "buttonHover"); break; case "mouseout": HTMLArea._removeClass(target, "buttonHover"); HTMLArea._removeClass(target.parentNode, "buttonHover"); HTMLArea._removeClass(target, "buttonActive"); HTMLArea._removeClass(target.parentNode, "buttonActive"); if (obj.active) { HTMLArea._addClass(target, "buttonPressed"); HTMLArea._addClass(target.parentNode, "buttonPressed"); } break; case "mousedown": HTMLArea._addClass(target, "buttonActive"); HTMLArea._addClass(target.parentNode, "buttonActive"); HTMLArea._removeClass(target, "buttonPressed"); HTMLArea._removeClass(target.parentNode, "buttonPressed"); HTMLArea._stopEvent(ev); break; case "click": HTMLArea._removeClass(target, "buttonActive"); HTMLArea._removeClass(target.parentNode, "buttonActive"); HTMLArea._removeClass(target, "buttonHover"); HTMLArea._removeClass(target.parentNode, "buttonHover"); obj.cmd(editor, obj.name, obj); HTMLArea._stopEvent(ev); break; case "change": editor.focusEditor(); var value = target.options[target.selectedIndex].value; switch (obj.name) { case "FontName": case "FontSize": editor.execCommand(obj.name, false, value); break; case "FormatBlock": (HTMLArea.is_ie || HTMLArea.is_safari) && (value = "<" + value + ">"); editor.execCommand(obj.name, false, value); break; default: var dropdown = editor.config.customSelects[obj.name]; if (typeof(dropdown) != "undefined") dropdown.action(editor); else HTMLArea._appendToLog("ERROR [HTMLArea::toolBarButtonHandler]: Combo box " + obj.name + " not registered."); } } }};/* * Create the status bar */HTMLArea.prototype._createStatusBar = function() { var statusBar = document.createElement("div"); this._statusBar = statusBar; statusBar.className = "statusBar"; if (!this.config.statusBar) statusBar.style.display = "none"; var statusBarTree = document.createElement("span"); this._statusBarTree = statusBarTree; statusBarTree.className = "statusBarTree"; statusBar.appendChild(statusBarTree); statusBarTree.appendChild(document.createTextNode(HTMLArea.I18N.msg["Path"] + ": ")); this._htmlArea.appendChild(statusBar);};/* * Create the htmlArea iframe and replace the textarea with it. */HTMLArea.prototype.generate = function () { // get the textarea and hide it var textarea = this._textArea; if (typeof(textarea) == "string") { textarea = HTMLArea.getElementById("textarea", textarea); this._textArea = textarea; } textarea.style.display = "none"; // create the editor framework and insert the editor before the textarea var htmlarea = document.createElement("div"); htmlarea.className = "htmlarea"; htmlarea.style.width = textarea.style.width; this._htmlArea = htmlarea; textarea.parentNode.insertBefore(htmlarea, textarea); if(textarea.form) { // we have a form, on reset, re-initialize the HTMLArea content and update the toolbar var f = textarea.form; if (typeof(f.onreset) == "function") { var funcref = f.onreset; if (typeof(f.__msh_prevOnReset) == "undefined") f.__msh_prevOnReset = []; f.__msh_prevOnReset.push(funcref); } f._editorNumber = this._editorNumber; HTMLArea._addEvent(f, "reset", HTMLArea.resetHandler); } // create & append the toolbar this._createToolbar(); HTMLArea._appendToLog("[HTMLArea::generate]: Toolbar successfully created."); // create and append the IFRAME var iframe = document.createElement("iframe"); if (HTMLArea.is_ie || HTMLArea.is_safari || HTMLArea.is_wamcom) { iframe.setAttribute("src",_editor_url + "popups/blank.html"); } else if (HTMLArea.is_opera) { iframe.setAttribute("src",_typo3_host_url + _editor_url + "popups/blank.html"); } else { iframe.setAttribute("src","javascript:void(0);"); } iframe.className = "editorIframe"; if (!this.config.statusBar) iframe.className += " noStatusBar"; htmlarea.appendChild(iframe); this._iframe = iframe; // create & append the status bar this._createStatusBar(); // size the iframe this.sizeIframe(2); HTMLArea._appendToLog("[HTMLArea::generate]: Editor iframe successfully created."); this.initIframe(); return this;};/* * Size the iframe according to user's prefs or initial textarea */HTMLArea.prototype.sizeIframe = function(diff) { var height = (this.config.height == "auto" ? (this._textArea.style.height) : this.config.height); var textareaHeight = height; // All nested tabs and inline levels in the sorting order they were applied: this.nested = {}; this.nested.all = RTEarea[this._editorNumber].tceformsNested; this.nested.sorted = HTMLArea.simplifyNested(this.nested.all); // Clone the array instead of using a reference (this.accessParentElements will change the array): var parentElements = (this.nested.sorted && this.nested.sorted.length ? [].concat(this.nested.sorted) : []); // Walk through all nested tabs and inline levels to make a correct positioning: var dimensions = this.accessParentElements(parentElements, 'this.getDimensions()'); if(height.indexOf("%") == -1) { height = parseInt(height) - diff; if (this.config.sizeIncludesToolbar) { this._initialToolbarOffsetHeight = dimensions.toolbar.height; height -= dimensions.toolbar.height; height -= dimensions.statusbar.height; } if (height < 0) height = 0; textareaHeight = (height - 4); if (textareaHeight < 0) textareaHeight = 0; height += "px"; textareaHeight += "px"; } this._iframe.style.height = height; this._textArea.style.height = textareaHeight; var textareaWidth = (this.config.width == "auto" ? this._textArea.style.width : this.config.width); var iframeWidth = textareaWidth; if(textareaWidth.indexOf("%") == -1) { iframeWidth = parseInt(textareaWidth) + "px"; textareaWidth = parseInt(textareaWidth) - diff; if (textareaWidth < 0) textareaWidth = 0; textareaWidth += 'px'; } this._iframe.style.width = "100%"; if (HTMLArea.is_opera) this._iframe.style.width = iframeWidth; this._textArea.style.width = textareaWidth;};/** * Get the dimensions of the toolbar and statusbar. * * @return object An object with width/height pairs for statusbar and toolbar. * @author Oliver Hader <oh@inpublica.de> */HTMLArea.prototype.getDimensions = function() { return { toolbar: {width: this._toolbar.offsetWidth, height: this._toolbar.offsetHeight}, statusbar: {width: this._statusBar.offsetWidth, height: this._statusBar.offsetHeight} };};/** * Access an inline relational element or tab menu and make it "accesible". * If a parent object has the style "display: none", offsetWidth & offsetHeight are '0'. * * @params object callbackFunc: A function to be called, when the embedded objects are "accessible". * @return object An object returned by the callbackFunc. * @author Oliver Hader <oh@inpublica.de> */HTMLArea.prototype.accessParentElements = function(parentElements, callbackFunc) { var result = {}; if (parentElements.length) { var currentElement = parentElements.pop(); var elementStyle = document.getElementById(currentElement).style; var actionRequired = (elementStyle.display == 'none' ? true : false); if (actionRequired) { var originalVisibility = elementStyle.visibility; var originalPosition = elementStyle.position; elementStyle.visibility = 'hidden'; elementStyle.position = 'absolute'; elementStyle.display = ''; } result = this.accessParentElements(parentElements, callbackFunc); if (actionRequired) { elementStyle.display = 'none'; elementStyle.position = originalPosition; elementStyle.visibility = originalVisibility; } } else { result = eval(callbackFunc); } return result;};/** * Simplify the array of nested levels. Create an indexed array with the correct names of the elements. * * @param object nested: The array with the nested levels * @return object The simplified array * @author Oliver Hader <oh@inpublica.de> */HTMLArea.simplifyNested = function(nested) { var i, type, level, max, simplifiedNested=[]; if (nested && nested.length) { if (nested[0][0]=='inline') { nested = inline.findContinuedNestedLevel(nested, nested[0][1]); } for (i=0, max=nested.length; i<max; i++) { type = nested[i][0]; level = nested[i][1]; if (type=='tab') { simplifiedNested.push(level+'-DIV'); } else if (type=='inline') { simplifiedNested.push(level+'_fields'); } } } return simplifiedNested;};/* * Initialize the iframe */HTMLArea.initIframe = function(editorNumber) { var editor = RTEarea[editorNumber]["editor"]; editor.initIframe();};HTMLArea.prototype.initIframe = function() { if (this._initIframeTimer) window.clearTimeout(this._initIframeTimer); if (!this._iframe || (!this._iframe.contentWindow && !this._iframe.contentDocument)) { this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50); return false; } else if (this._iframe.contentWindow) { if (!this._iframe.contentWindow.document || !this._iframe.contentWindow.document.documentElement) { this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50); return false; } } else if (!this._iframe.contentDocument.documentElement) { this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50); return false; } var doc = this._iframe.contentWindow ? this._iframe.contentWindow.document : this._iframe.contentDocument; this._doc = doc; if (!this.config.fullPage) { var head = doc.getElementsByTagName("head")[0]; if (!head) { head = doc.createElement("head"); doc.documentElement.appendChild(head); } if (this.config.baseURL && !HTMLArea.is_opera) { var base = doc.getElementsByTagName("base")[0]; if (!base) { base = doc.createElement("base"); base.href = this.config.baseURL; head.appendChild(base); } HTMLArea._appendToLog("[HTMLArea::initIframe]: Iframe baseURL set to: " + this.config.baseURL); } var link0 = doc.getElementsByTagName("link")[0]; if (!link0) { link0 = doc.createElement("link"); link0.rel = "stylesheet"; link0.href = this.config.editedContentStyle; head.appendChild(link0); HTMLArea._appendToLog("[HTMLArea::initIframe]: Skin CSS set to: " + this.config.editedContentStyle); } if (this.config.defaultPageStyle) { var link = doc.getElementsByTagName("link")[1]; if (!link) { link = doc.createElement("link"); link.rel = "stylesheet"; link.href = this.config.defaultPageStyle; head.appendChild(link); } HTMLArea._appendToLog("[HTMLArea::initIframe]: Override CSS set to: " + this.config.defaultPageStyle); } if (this.config.pageStyle) { var link = doc.getElementsByTagName("link")[2]; if (!link) { link = doc.createElement("link"); link.rel = "stylesheet"; link.href = this.config.pageStyle; head.appendChild(link); } HTMLArea._appendToLog("[HTMLArea::initIframe]: Content CSS set to: " + this.config.pageStyle); } } else { var html = this._textArea.value; this.setFullHTML(html); } HTMLArea._appendToLog("[HTMLArea::initIframe]: Editor iframe head successfully initialized."); this.stylesLoaded();};/* * Finalize editor Iframe initialization after loading the style sheets */HTMLArea.stylesLoaded = function(editorNumber) { var editor = RTEarea[editorNumber]["editor"]; editor.stylesLoaded();};HTMLArea.prototype.stylesLoaded = function() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -