/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ /* -*- tab-width: 4 -*- */ dojo.provide("dojo.widget.RichText"); dojo.provide("dojo.widget.html.RichText"); dojo.require("dojo.widget.*"); dojo.require("dojo.dom"); dojo.require("dojo.html"); dojo.require("dojo.event.*"); dojo.require("dojo.style"); dojo.require("dojo.string"); // used to save content try { document.write(''); }catch(e){ } dojo.widget.defineWidget( "dojo.widget.html.RichText", dojo.widget.HtmlWidget, { /** whether to inherit the parent's width or simply use 100% */ inheritWidth: false, focusOnLoad: true, /** * If a save name is specified the content is saved and restored if the * editor is not properly closed after editing has started. */ saveName: "", _content: "", /* set height to fix the editor at a specific height, with scrolling */ height: null, /** The minimum height that the editor should have */ minHeight: "1em", isClosed: true, isLoaded: false, /** whether to use the active-x object in IE */ useActiveX: false, /* whether to use relative URLs for images - if this is enabled images will be given absolute URLs when inside the editor but will be changed to use relative URLs (to the current page) on save */ relativeImageUrls: false, _SEPARATOR: "@@**%%__RICHTEXTBOUNDRY__%%**@@", // contentFilters: [], /* defaultContentCleaner: function(content){ if(!dojo.render.html.ie){ return content; } content = content.replace(/\x20/g, " "); // alert(content); return content; }, */ /* Init *******/ fillInTemplate: function(){ this.open(); // add the formatting functions var funcs = ["queryCommandEnabled", "queryCommandState", "queryCommandValue", "execCommand"]; for(var i = 0; i < funcs.length; i++){ dojo.event.connect("around", this, funcs[i], this, "_normalizeCommand"); } // backwards compatibility, needs to be removed dojo.event.connect(this, "onKeyPressed", this, "afterKeyPress"); dojo.event.connect(this, "onKeyPress", this, "keyPress"); dojo.event.connect(this, "onKeyDown", this, "keyDown"); dojo.event.connect(this, "onKeyUp", this, "keyUp"); // add default some key handlers var ctrl = this.KEY_CTRL; var exec = function (cmd, arg) { return arguments.length == 1 ? function () { this.execCommand(cmd); } : function () { this.execCommand(cmd, arg); } } this.addKeyHandler("b", ctrl, exec("bold")); this.addKeyHandler("i", ctrl, exec("italic")); this.addKeyHandler("u", ctrl, exec("underline")); this.addKeyHandler("a", ctrl, exec("selectall")); //this.addKeyHandler("k", ctrl, exec("createlink", "")); //this.addKeyHandler("K", ctrl, exec("unlink")); this.addKeyHandler("s", ctrl, function () { this.save(true); }); this.addKeyHandler("1", ctrl, exec("formatblock", "h1")); this.addKeyHandler("2", ctrl, exec("formatblock", "h2")); this.addKeyHandler("3", ctrl, exec("formatblock", "h3")); this.addKeyHandler("4", ctrl, exec("formatblock", "h4")); this.addKeyHandler("\\", ctrl, exec("insertunorderedlist")); if(!dojo.render.html.ie){ this.addKeyHandler("Z", ctrl, exec("redo")); } }, events: ["onBlur", "onFocus", "onKeyPress", "onKeyDown", "onKeyUp", "onClick"], /** * Transforms the node referenced in this.domNode into a rich text editing * node. This can result in the creation and replacement with an