📄 htmlarea.js
字号:
/**************************************************************** Copyright notice** (c) 2002-2004, interactivetools.com, inc.* (c) 2003-2004 dynarch.com* (c) 2004-2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>* All rights reserved** This script is part of the TYPO3 project. The TYPO3 project is* free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** The GNU General Public License can be found at* http://www.gnu.org/copyleft/gpl.html.* A copy is found in the textfile GPL.txt and important notices to the license* from the author is found in LICENSE.txt distributed with these scripts.*** This script is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** This script is a modified version of a script published under the htmlArea License.* A copy of the htmlArea License may be found in the textfile HTMLAREA_LICENSE.txt.** This copyright notice MUST APPEAR in all copies of the script!***************************************************************//* * Main script of TYPO3 htmlArea RTE * * TYPO3 CVS ID: $Id: htmlarea.js 2656 2007-11-02 20:40:23Z stanrolland $ *//*************************************************** * EDITOR INITIALIZATION AND CONFIGURATION ***************************************************//* * Set some basic paths */if (typeof(_editor_url) == "string") { // Leave exactly one backslash at the end of _editor_url _editor_url = _editor_url.replace(/\x2f*$/, '/');} else { alert("WARNING: _editor_url is not set!"); var _editor_url = '';}if (typeof(_editor_skin) == "string") _editor_skin = _editor_skin.replace(/\x2f*$/, '/'); else var _editor_skin = _editor_url + "skins/default/";if (typeof(_editor_CSS) != "string") var _editor_CSS = _editor_url + "skins/default/htmlarea.css";if (typeof(_editor_edited_content_CSS) != "string") var _editor_edited_content_CSS = _editor_skin + "htmlarea-edited-content.css";if (typeof(_editor_lang) == "string") _editor_lang = _editor_lang ? _editor_lang.toLowerCase() : "en";/* * HTMLArea object constructor. */var HTMLArea = function(textarea, config) { if (HTMLArea.checkSupportedBrowser()) { if (typeof(config) == "undefined") this.config = new HTMLArea.Config(); else this.config = config; this._htmlArea = null; this._textArea = textarea; this._editMode = "wysiwyg"; this.plugins = {}; this._timerToolbar = null; this._undoQueue = new Array(); this._undoPos = -1; this._customUndo = true; this.doctype = ''; this.eventHandlers = {}; }};/* * Browser identification */HTMLArea.agt = navigator.userAgent.toLowerCase();HTMLArea.is_opera = (HTMLArea.agt.indexOf("opera") != -1);HTMLArea.is_ie = (HTMLArea.agt.indexOf("msie") != -1) && !HTMLArea.is_opera;HTMLArea.is_safari = (HTMLArea.agt.indexOf("webkit") != -1);HTMLArea.is_gecko = (navigator.product == "Gecko") || HTMLArea.is_opera;// Check on MacOS Wamcom version 1.3 but exclude Firefox rv 1.8.1.3HTMLArea.is_wamcom = (HTMLArea.agt.indexOf("wamcom") != -1) || (HTMLArea.is_gecko && HTMLArea.agt.indexOf("1.3") != -1 && HTMLArea.agt.indexOf(".1.3") == -1);/* * A log for troubleshooting */HTMLArea._debugMode = false;if (typeof(_editor_debug_mode) != "undefined") HTMLArea._debugMode = _editor_debug_mode;HTMLArea._appendToLog = function(str){ if(HTMLArea._debugMode) { var log = document.getElementById("HTMLAreaLog"); if(log) { log.appendChild(document.createTextNode(str)); log.appendChild(document.createElement("br")); } }};/* * Using compressed scripts */HTMLArea._compressedScripts = false;if (typeof(_editor_compressed_scripts) != "undefined") HTMLArea._compressedScripts = _editor_compressed_scripts;/* * Localization of core script */HTMLArea.I18N = HTMLArea_langArray;/* * Build array of scripts to be loaded */HTMLArea.is_loaded = false;HTMLArea.onload = function(){ HTMLArea.is_loaded = true; HTMLArea._appendToLog("All scripts successfully loaded.");};HTMLArea.loadTimer;HTMLArea._scripts = [];HTMLArea._scriptLoaded = [];HTMLArea._request = [];HTMLArea.loadScript = function(url, plugin) { if (plugin) url = _editor_url + "/plugins/" + plugin + '/' + url; if (HTMLArea.is_opera) url = _typo3_host_url + url; if (HTMLArea._compressedScripts && url.indexOf("compressed") == -1) url = url.replace(/\.js$/gi, "-compressed.js"); HTMLArea._scripts.push(url);};HTMLArea.loadScript(RTEarea[0]["popupwin"] ? RTEarea[0]["popupwin"] : _editor_url + "popupwin.js");if(HTMLArea.is_gecko) HTMLArea.loadScript(RTEarea[0]["htmlarea-gecko"] ? RTEarea[0]["htmlarea-gecko"] : _editor_url + "htmlarea-gecko.js");if(HTMLArea.is_ie) HTMLArea.loadScript(RTEarea[0]["htmlarea-ie"] ? RTEarea[0]["htmlarea-ie"] : _editor_url + "htmlarea-ie.js");/* * Get a script using asynchronous XMLHttpRequest */HTMLArea.MSXML_XMLHTTP_PROGIDS = new Array("Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP");HTMLArea.XMLHTTPResponseHandler = function (i) { return (function() { var url = HTMLArea._scripts[i]; if (HTMLArea._request[i].readyState != 4) return; if (HTMLArea._request[i].status == 200) { try { eval(HTMLArea._request[i].responseText); HTMLArea._scriptLoaded[i] = true; i = null; } catch (e) { HTMLArea._appendToLog("ERROR [HTMLArea::getScript]: Unable to get script " + url + ": " + e); } } else { HTMLArea._appendToLog("ERROR [HTMLArea::getScript]: Unable to get " + url + " . Server reported " + HTMLArea._request[i].status); } });};HTMLArea._getScript = function (i,asynchronous,url) { if (typeof(url) == "undefined") var url = HTMLArea._scripts[i]; if (typeof(asynchronous) == "undefined") var asynchronous = true; if (window.XMLHttpRequest) HTMLArea._request[i] = new XMLHttpRequest(); else if (window.ActiveXObject) { var success = false; for (var k = 0; k < HTMLArea.MSXML_XMLHTTP_PROGIDS.length && !success; k++) { try { HTMLArea._request[i] = new ActiveXObject(HTMLArea.MSXML_XMLHTTP_PROGIDS[k]); success = true; } catch (e) { } } if (!success) return false; } var request = HTMLArea._request[i]; if (request) { request.open("GET", url, asynchronous); if (asynchronous) request.onreadystatechange = HTMLArea.XMLHTTPResponseHandler(i); if (window.XMLHttpRequest) request.send(null); else if (window.ActiveXObject) request.send(); if (!asynchronous) { if (request.status == 200) return request.responseText; else return ''; } return true; } else { return false; }};/* * Wait for the loading process to complete */HTMLArea.checkInitialLoad = function() { var scriptsLoaded = true; for (var i = HTMLArea._scripts.length; --i >= 0;) { scriptsLoaded = scriptsLoaded && HTMLArea._scriptLoaded[i]; } if(HTMLArea.loadTimer) window.clearTimeout(HTMLArea.loadTimer); if (scriptsLoaded) { HTMLArea.is_loaded = true; HTMLArea._appendToLog("[HTMLArea::init]: All scripts successfully loaded."); HTMLArea._appendToLog("[HTMLArea::init]: Editor url set to: " + _editor_url); HTMLArea._appendToLog("[HTMLArea::init]: Editor skin CSS set to: " + _editor_CSS); HTMLArea._appendToLog("[HTMLArea::init]: Editor content skin CSS set to: " + _editor_edited_content_CSS); if (window.ActiveXObject) { for (var i = HTMLArea._scripts.length; --i >= 0;) { HTMLArea._request[i].onreadystatechange = new Function(); HTMLArea._request[i] = null; } } } else { HTMLArea.loadTimer = window.setTimeout("HTMLArea.checkInitialLoad();", 200); return false; }};/* * Get all the scripts */HTMLArea.init = function() { HTMLArea._eventCache = HTMLArea._eventCacheConstructor(); if (window.XMLHttpRequest || window.ActiveXObject) { try { var success = true; for (var i = HTMLArea._scripts.length; --i >= 0 && success;) success = success && HTMLArea._getScript(i); } catch (e) { HTMLArea._appendToLog("ERROR [HTMLArea::init]: Unable to use XMLHttpRequest: "+ e); } if (success) { HTMLArea.checkInitialLoad(); } else { if (HTMLArea.is_ie) window.setTimeout('if (window.document.getElementById("pleasewait1")) { window.document.getElementById("pleasewait1").innerHTML = HTMLArea.I18N.msg["ActiveX-required"]; } else { alert(HTMLArea.I18N.msg["ActiveX-required"]); };', 200); } } else { if (HTMLArea.is_ie) alert(HTMLArea.I18N.msg["ActiveX-required"]); }};/* * Compile some regular expressions */HTMLArea.RE_tagName = /(<\/|<)\s*([^ \t\n>]+)/ig;HTMLArea.RE_doctype = /(<!doctype((.|\n)*?)>)\n?/i;HTMLArea.RE_head = /<head>((.|\n)*?)<\/head>/i;HTMLArea.RE_body = /<body>((.|\n)*?)<\/body>/i;HTMLArea.Reg_body = new RegExp("<\/?(body)[^>]*>", "gi");HTMLArea.Reg_entities = new RegExp("&([0-9]+);", "gi");HTMLArea.reservedClassNames = /htmlarea/;HTMLArea.RE_email = /([0-9a-z]+([a-z0-9_-]*[0-9a-z])*){1}(\.[0-9a-z]+([a-z0-9_-]*[0-9a-z])*)*@([0-9a-z]+([a-z0-9_-]*[0-9a-z])*\.)+[a-z]{2,9}/i;HTMLArea.RE_url = /(https?:\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,})+\.[a-z]{2,5}(:[0-9]+)?(\/\S+)*)/i;/* * Editor configuration object constructor */HTMLArea.Config = function () { this.version = "3.0"; this.width = "auto"; this.height = "auto"; // enable creation of a status bar? this.statusBar = true; // maximum size of the undo queue this.undoSteps = 20; // the time interval at which undo samples are taken: 1/2 sec. this.undoTimeout = 500; // whether the toolbar should be included in the size or not. this.sizeIncludesToolbar = true; // if true then HTMLArea will retrieve the full HTML, starting with the <HTML> tag. this.fullPage = false; // if the site is secure, create a secure iframe this.useHTTPS = false; // for Mozilla this.useCSS = false; this.enableMozillaExtension = true; this.disableEnterParagraphs = false; this.removeTrailingBR = false; // style included in the iframe document this.editedContentStyle = _editor_edited_content_CSS; // content style this.pageStyle = ""; // set to true if you want Word code to be cleaned upon Paste this.cleanWordOnPaste = true; // enable the 'Target' field in the Make Link dialog this.makeLinkShowsTarget = true; // remove tags (these have to be a regexp, or null if this functionality is not desired) this.htmlRemoveTags = null; // remove tags and any contents (these have to be a regexp, or null if this functionality is not desired) this.htmlRemoveTagsAndContents = null; // remove comments this.htmlRemoveComments = false; // custom tags (these have to be a regexp, or null if this functionality is not desired) this.customTags = null; // BaseURL included in the iframe document this.baseURL = document.baseURI || document.URL; if(this.baseURL && this.baseURL.match(/(.*)\/([^\/]+)/)) this.baseURL = RegExp.$1 + "/"; // URL-s this.imgURL = "images/"; this.popupURL = "popups/"; this.btnList = { Bold: ["Bold", "ed_format_bold", false, function(editor) {editor.execCommand("Bold");}], Italic: ["Italic", "ed_format_italic", false, function(editor) {editor.execCommand("Italic");}], Underline: ["Underline", "ed_format_underline", false, function(editor) {editor.execCommand("Underline");}], StrikeThrough: ["Strikethrough", "ed_format_strike", false, function(editor) {editor.execCommand("StrikeThrough");}], Subscript: ["Subscript", "ed_format_sub", false, function(editor) {editor.execCommand("Subscript");}], Superscript: ["Superscript", "ed_format_sup", false, function(editor) {editor.execCommand("Superscript");}], JustifyLeft: ["Justify Left", "ed_align_left.gif", false, function(editor) {editor.execCommand("JustifyLeft");}], JustifyCenter: ["Justify Center", "ed_align_center.gif", false, function(editor) {editor.execCommand("JustifyCenter");}], JustifyRight: ["Justify Right", "ed_align_right.gif", false, function(editor) {editor.execCommand("JustifyRight");}], JustifyFull: ["Justify Full", "ed_align_justify.gif", false, function(editor) {editor.execCommand("JustifyFull");}], InsertOrderedList: ["Ordered List", "ed_list_num.gif", false, function(editor) {editor.execCommand("InsertOrderedList");}], InsertUnorderedList: ["Bulleted List", "ed_list_bullet", false, function(editor) {editor.execCommand("InsertUnorderedList");}], Outdent: ["Decrease Indent", "ed_indent_less.gif", false, function(editor) {editor.execCommand("Outdent");}], Indent: ["Increase Indent", "ed_indent_more.gif", false, function(editor) {editor.execCommand("Indent");}], ForeColor: ["Font Color", "ed_color_fg.gif",false, function(editor) {editor.execCommand("ForeColor");}], HiliteColor: ["Background Color", "ed_color_bg.gif",false, function(editor) {editor.execCommand("HiliteColor");}], InsertHorizontalRule: ["Horizontal Rule", "ed_hr.gif",false, function(editor) {editor.execCommand("InsertHorizontalRule");}], CreateLink: ["Insert Web Link", "ed_link.gif", false, function(editor) {editor.execCommand("CreateLink", true);}, "a", false, true], InsertImage: ["Insert/Modify Image", "ed_image.gif", false, function(editor) {editor.execCommand("InsertImage");}], InsertTable: ["Insert Table", "insert_table.gif", false, function(editor) {editor.execCommand("InsertTable");}], HtmlMode: ["Toggle HTML Source", "ed_html.gif", true, function(editor) {editor.execCommand("HtmlMode");}], SelectAll: ["SelectAll", "", true, function(editor) {editor.execCommand("SelectAll");}, null, true, false], SplitBlock: ["Toggle Container Block", "ed_splitblock.gif", false, function(editor) {editor.execCommand("SplitBlock");}], About: ["About this editor", "ed_about.gif", true, function(editor) {editor.execCommand("About");}], Undo: ["Undoes your last action", "ed_undo.gif", false, function(editor) {editor.execCommand("Undo");}], Redo: ["Redoes your last action", "ed_redo.gif", false, function(editor) {editor.execCommand("Redo");}], Cut: ["Cut selection", "ed_cut.gif", false, function(editor,command,obj) {editor.execCommand("Cut");}], Copy: ["Copy selection", "ed_copy.gif", false, function(editor,command,obj) {editor.execCommand("Copy");}], Paste: ["Paste from clipboard", "ed_paste.gif", false, function(editor,command,obj) {editor.execCommand("Paste");}], SelectAll: ["SelectAll", "", true, function(editor) {editor.execCommand("SelectAll");}, null, true, false], LeftToRight: ["Direction left to right", "ed_left_to_right.gif", false, function(editor) {editor.execCommand("LeftToRight");}], RightToLeft: ["Direction right to left", "ed_right_to_left.gif", false, function(editor) {editor.execCommand("RightToLeft");}] }; // Default hotkeys this.hotKeyList = { a: "SelectAll", b: "Bold", i: "Italic", u: "Underline", s: "StrikeThrough", l: "JustifyLeft", e: "JustifyCenter", r: "JustifyRight", j: "JustifyFull", n: "FormatBlock", v: "Paste", 0: "CleanWord", z: "Undo", y: "Redo" }; // Initialize tooltips from the I18N module, generate correct image path for (var i in this.btnList) { var btn = this.btnList[i]; if (typeof(HTMLArea.I18N.tooltips[i.toLowerCase()]) != "undefined") btn[0] = HTMLArea.I18N.tooltips[i.toLowerCase()]; if (typeof(btn[1]) == "string") btn[1] = _editor_skin + this.imgURL + btn[1]; else btn[1][0] = _editor_skin + this.imgURL + btn[1][0]; } this.customSelects = {};};/* * Register a new button with the configuration. * It can be called with all arguments, or with only one (first one). When called with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -