📄 htmlarea.js
字号:
* only one argument it must be an object with the following properties: * id, tooltip, image, textMode, action, context. Examples: * * 1. config.registerButton("my-hilite", "Hilite text", "my-hilite.gif", false, function(editor) {...}, context); * 2. config.registerButton({ * id : "my-hilite", // Unique id for the button * tooltip : "Hilite text", // the tooltip * image : "my-hilite.gif", // image to be displayed in the toolbar * textMode : false, // disabled in text mode * action : function(editor) { // called when the button is clicked * editor.surroundHTML('<span class="hilite">', '</span>'); * }, * context : "p" // will be disabled if not inside a <p> element * hide : false // hide in menu and show only in context menu * selection : false // will be disabled if there is no selection * }); */HTMLArea.Config.prototype.registerButton = function(id,tooltip,image,textMode,action,context,hide,selection) { var the_id; switch (typeof(id)) { case "string": the_id = id; break; case "object": the_id = id.id; break; default: HTMLArea._appendToLog("ERROR [HTMLArea.Config::registerButton]: invalid arguments"); return false; } if (typeof(this.customSelects[the_id]) != "undefined") HTMLArea._appendToLog("WARNING [HTMLArea.Config::registerButton]: A dropdown with the same ID " + id + " already exists."); if (typeof(this.btnList[the_id]) != "undefined") HTMLArea._appendToLog("WARNING [HTMLArea.Config::registerButton]: A button with the same ID " + id + " already exists."); switch (typeof(id)) { case "string": if (typeof(hide) == "undefined") var hide = false; if (typeof(selection) == "undefined") var selection = false; this.btnList[id] = [tooltip, image, textMode, action, context, hide, selection]; break; case "object": if (typeof(id.hide) == "undefined") id.hide = false; if (typeof(id.selection) == "undefined") id.selection = false; this.btnList[id.id] = [id.tooltip, id.image, id.textMode, id.action, id.context, id.hide, id.selection]; break; }};/* * Register a dropdown box with the editor configuration. */HTMLArea.Config.prototype.registerDropdown = function(object) { if (typeof(this.customSelects[object.id]) != "undefined") HTMLArea._appendToLog("WARNING [HTMLArea.Config::registerDropdown]: A dropdown with the same ID " + object.id + " already exists."); if (typeof(this.btnList[object.id]) != "undefined") HTMLArea._appendToLog("WARNING [HTMLArea.Config::registerDropdown]: A button with the same ID " + object.id + " already exists."); this.customSelects[object.id] = object;};/*************************************************** * EDITOR FRAMEWORK ***************************************************//* * Update the state of a toolbar element. * This function is member of a toolbar element object, unnamed object created by createButton or createSelect functions. */HTMLArea.setButtonStatus = function(id,newval) { var oldval = this[id]; var el = document.getElementById(this.elementId); if (oldval != newval) { switch (id) { case "enabled": if (newval) { if (!HTMLArea.is_wamcom) { HTMLArea._removeClass(el, "buttonDisabled"); HTMLArea._removeClass(el.parentNode, "buttonDisabled"); } el.disabled = false; } else { if (!HTMLArea.is_wamcom) { HTMLArea._addClass(el, "buttonDisabled"); HTMLArea._addClass(el.parentNode, "buttonDisabled"); } el.disabled = true; } break; case "active": if (newval) { HTMLArea._addClass(el, "buttonPressed"); HTMLArea._addClass(el.parentNode, "buttonPressed"); } else { HTMLArea._removeClass(el, "buttonPressed"); HTMLArea._removeClass(el.parentNode, "buttonPressed"); } break; } this[id] = newval; }};/* * Create a new line in the toolbar */HTMLArea.newLine = function(toolbar) { tb_line = document.createElement("ul"); tb_line.className = "tb-line"; toolbar.appendChild(tb_line); return tb_line;};/* * Add a toolbar element to the current line or group */HTMLArea.addTbElement = function(element, tb_line, first_cell_on_line) { var tb_cell = document.createElement("li"); if (first_cell_on_line) tb_cell.className = "tb-first-cell"; else tb_cell.className = "tb-cell"; HTMLArea._addClass(tb_cell, element.className); tb_line.appendChild(tb_cell); tb_cell.appendChild(element); if(element.style.display == "none") { tb_cell.style.display = "none"; if(HTMLArea._hasClass(tb_line, "tb-group")) tb_line.style.display = "none"; if(HTMLArea._hasClass(tb_cell.previousSibling, "separator")) tb_cell.previousSibling.style.display = "none"; } return false;};/* * Create a new group on the current line */HTMLArea.addTbGroup = function(tb_line, first_cell_on_line) { var tb_group = document.createElement("ul"); tb_group.className = "tb-group"; HTMLArea.addTbElement(tb_group, tb_line, first_cell_on_line); return tb_group;};/* * Create a combo box and add it to the toolbar */HTMLArea.prototype.createSelect = function(txt,tb_line,first_cell_on_line,labelObj) { var options = null, cmd = null, context = null, tooltip = "", newObj = { created : false, el : null, first : first_cell_on_line, labelUsed : false }; switch (txt) { case "FontSize": case "FontName": case "FormatBlock": options = this.config[txt]; tooltip = HTMLArea.I18N.tooltips[txt.toLowerCase()]; cmd = txt; break; default: cmd = txt; var dropdown = this.config.customSelects[cmd]; if (typeof(dropdown) != "undefined") { options = dropdown.options; context = dropdown.context; if (typeof(dropdown.tooltip) != "undefined") tooltip = dropdown.tooltip; } break; } if(options) { newObj["el"] = document.createElement("select"); newObj["el"].className = "select"; newObj["el"].title = tooltip; newObj["el"].id = this._editorNumber + "-" + txt; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); var obj = { name : txt, // field name elementId : newObj["el"].id, // unique id for the UI element enabled : true, // is it enabled? text : false, // enabled in text mode? cmd : cmd, // command ID state : HTMLArea.setButtonStatus, // for changing state context : context, editorNumber : this._editorNumber }; this._toolbarObjects[txt] = obj; newObj["el"]._obj = obj; if (labelObj["labelRef"]) { labelObj["el"].htmlFor = newObj["el"].id; newObj["labelUsed"] = true; } HTMLArea._addEvent(newObj["el"], "change", HTMLArea.toolBarButtonHandler); for (var i in options) { var op = document.createElement("option"); op.innerHTML = i; op.value = options[i]; if (txt == "FontName" && !this.config.disablePCexamples) { if (HTMLArea.is_gecko) op.setAttribute("style", "font-family:" + op.value + ";"); else op.style.cssText = "font-family:" + op.value + ";"; } newObj["el"].appendChild(op); } newObj["created"] = true; } return newObj;};/* * Create a button and add it to the toolbar */HTMLArea.prototype.createButton = function (txt,tb_line,first_cell_on_line,labelObj) { var btn = null, btnImg = null, newObj = { created : false, el : null, first : first_cell_on_line, labelUsed : false }; switch (txt) { case "separator": newObj["el"] = document.createElement("div"); newObj["el"].className = "separator"; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); newObj["created"] = true; break; case "space": newObj["el"] = document.createElement("div"); newObj["el"].className = "space"; newObj["el"].innerHTML = " "; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); newObj["created"] = true; break; case "TextIndicator": newObj["el"] = document.createElement("div"); newObj["el"].appendChild(document.createTextNode("A")); newObj["el"].className = "indicator"; newObj["el"].title = HTMLArea.I18N.tooltips.textindicator; newObj["el"].id = this._editorNumber + "-" + txt; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); var obj = { name : txt, elementId : newObj["el"].id, enabled : true, active : false, text : false, cmd : "TextIndicator", state : HTMLArea.setButtonStatus }; this._toolbarObjects[txt] = obj; newObj["created"] = true; break; default: btn = this.config.btnList[txt]; } if(!newObj["created"] && btn) { newObj["el"] = document.createElement("button"); newObj["el"].title = btn[0]; newObj["el"].className = "button"; newObj["el"].id = this._editorNumber + "-" + txt; if (btn[5]) newObj["el"].style.display = "none"; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); var obj = { name : txt, // the button name elementId : newObj["el"].id, // unique id for the UI element enabled : true, // is it enabled? active : false, // is it pressed? text : btn[2], // enabled in text mode? cmd : btn[3], // the command ID state : HTMLArea.setButtonStatus, // for changing state context : btn[4] || null, // enabled in a certain context? selection : btn[6], // disabled when no selection? editorNumber : this._editorNumber }; this._toolbarObjects[txt] = obj; newObj["el"]._obj = obj; if (labelObj["labelRef"]) { labelObj["el"].htmlFor = newObj["el"].id; newObj["labelUsed"] = true; } HTMLArea._addEvents(newObj["el"],["mouseover", "mouseout", "mousedown", "click"], HTMLArea.toolBarButtonHandler); if (typeof(btn[1]) != "string" && HTMLArea.is_ie) { var btnImgContainer = document.createElement("div"); btnImgContainer.className = "buttonImgContainer"; btnImgContainer.innerHTML = '<img src="' + btn[1][0] + '" style="position: relative; top: -' + (18*(btn[1][1]+1)) + 'px; left: -' + (18*(btn[1][2]+1)) + 'px;" alt="' + btn[0] + '" />'; newObj["el"].appendChild(btnImgContainer); } else { newObj["el"].className += " " + txt; if (this.plugins["TYPO3Browsers"] && (txt == "CreateLink" || txt == "InsertImage")) newObj["el"].className += "-TYPO3Browsers"; } newObj["created"] = true; } return newObj;};/* * Create a label and add it to the toolbar */HTMLArea.createLabel = function(txt,tb_line,first_cell_on_line) { var newObj = { created : false, el : null, labelRef : false, first : first_cell_on_line }; if (/^([IT])\[(.*?)\]/.test(txt)) { var l7ed = RegExp.$1 == "I"; // localized? var label = RegExp.$2; if (l7ed) label = HTMLArea.I18N.dialogs[label]; newObj["el"] = document.createElement("label"); newObj["el"].className = "label"; newObj["el"].innerHTML = label; newObj["labelRef"] = true; newObj["created"] = true; newObj["first"] = HTMLArea.addTbElement(newObj["el"], tb_line, first_cell_on_line); } return newObj;};/* * Create the toolbar and append it to the _htmlarea. */HTMLArea.prototype._createToolbar = function () { var j, k, code, n = this.config.toolbar.length, m, tb_line = null, tb_group = null, first_cell_on_line = true, labelObj = new Object(), tbObj = new Object(); var toolbar = document.createElement("div"); this._toolbar = toolbar; toolbar.className = "toolbar"; toolbar.unselectable = "1"; this._toolbarObjects = new Object(); for (j = 0; j < n; ++j) { tb_line = HTMLArea.newLine(toolbar); if(!this.config.keepButtonGroupTogether) HTMLArea._addClass(tb_line, "free-float"); first_cell_on_line = true; tb_group = null; var group = this.config.toolbar[j]; m = group.length; for (k = 0; k < m; ++k) { code = group[k]; if (code == "linebreak") { tb_line = HTMLArea.newLine(toolbar); if(!this.config.keepButtonGroupTogether) HTMLArea._addClass(tb_line, "free-float"); first_cell_on_line = true; tb_group = null; } else { if ((code == "separator" || first_cell_on_line) && this.config.keepButtonGroupTogether) { tb_group = HTMLArea.addTbGroup(tb_line, first_cell_on_line); first_cell_on_line = false; } created = false; if (/^([IT])\[(.*?)\]/.test(code)) { labelObj = HTMLArea.createLabel(code, (tb_group?tb_group:tb_line), first_cell_on_line); created = labelObj["created"] ; first_cell_on_line = labelObj["first"]; } if (!created) { tbObj = this.createButton(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -