您的位置:首页 > 其它

FreeTextBox使用详解

2007-08-22 09:12 417 查看
Author: Annerose Date:12/16/2005

版本: FreeTextBox 3.1.1 ASP.NET1.1
1.下载 FreeTextBox 3.1.1 (released 2005/11/08)

http://www.freetextbox.com/downloads.aspx

2. 安装

FreeTextBox 3.0以上版本均支持内部模式,即图片资源和javascript都集成在dll中, 本文仅探讨内部模式(Internal Resources).

1) 把FTBv3-1-1\Framework-1.1\FreetextBox.dll拷入bin目录.

2) 在项目中添加FreetextBox.dll的dll引用

3) Web.config加入如下代码

1<?xml version="1.0" encoding="utf-8" ?>

2 <configuration>

3 <system.web>

4 <httpHandlers>

5 <add verb="GET" path="FtbWebResource.axd" type="FreeTextBoxControls.AssemblyResourceHandler, FreeTextBox" />

6 </httpHandlers>

7 <system.web>

8 <configuration>

3. 使用FreeTextBox

1) aspx页面顶上

<%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>

2) 调用

<FTB:FreeTextBox id="FreeTextBox1" runat="Server" />
3)工具栏皮肤

ToolbarStyleConfiguration = Offoce2003/OfficeXP/Office2000/MAC

4) 得到保存编辑的内容

1 private void InitializeComponent()

2 {

3 // 指向同一个委托

4 this.FreeTextBox1.SaveClick += new System.EventHandler this.FreeTextBox1_SaveClick);

5 this.Button1.Click += new System.EventHandler(this.FreeTextBox1_SaveClick);

6 }

7

8 private void FreeTextBox1_SaveClick(object sender, System.EventArgs e)

9 {

10 divshow.InnerHtml = FreeTextBox1.Text;

11 }
5) 客户端中检测到有潜在危险的 Request.Form 值

<%@ Page language="c#" function FTB_Underline(ftbName) {

FTB_Format(ftbName,'underline');

如果再深究下去,仔细跟踪下这段js的代码又可以它调用FTB_Format这段代码(在FreeTextBox-MainScript.js中)。

function FTB_Format(ftbName,commandName) {

editor = FTB_GetIFrame(ftbName);

if (FTB_IsHtmlMode(ftbName)) return;

editor.focus();

editor.document.execCommand(commandName,'',null);

}

它正是通过document的execCommand方法来实现效果的,查MSDN文挡可以发现它对应执行的正是Underline的命令参数。

execCommand可以执行的命令参数:

Command Identifiers

2D-Position

Allows absolutely positioned elements to be moved by dragging.

AbsolutePosition

Sets an element's position property to "absolute."

BackColor

Sets or retrieves the background color of the current selection.

BlockDirLTR

Not currently supported.

BlockDirRTL

Not currently supported.

Bold

Toggles the current selection between bold and nonbold.

BrowseMode

Not currently supported.

ClearAuthenticationCache

Clears all authentication credentials from the cache. Applies only to execCommand.

Copy

Copies the current selection to the clipboard.

CreateBookmark

Creates a bookmark anchor or retrieves the name of a bookmark anchor for the current selection or insertion point.

CreateLink

Inserts a hyperlink on the current selection, or displays a dialog box enabling the user to specify a URL to insert as a hyperlink on the current selection.

Cut

Copies the current selection to the clipboard and then deletes it.

Delete

Deletes the current selection.

DirLTR

Not currently supported.

DirRTL

Not currently supported.

EditMode

Not currently supported.

FontName

Sets or retrieves the font for the current selection.

FontSize

Sets or retrieves the font size for the current selection.

ForeColor

Sets or retrieves the foreground (text) color of the current selection.

FormatBlock

Sets the current block format tag.

Indent

Increases the indent of the selected text by one indentation increment.

InlineDirLTR

Not currently supported.

InlineDirRTL

Not currently supported.

InsertButton

Overwrites a button control on the text selection.

InsertFieldset

Overwrites a box on the text selection.

InsertHorizontalRule

Overwrites a horizontal line on the text selection.

InsertIFrame

Overwrites an inline frame on the text selection.

InsertImage

Overwrites an image on the text selection.

InsertInputButton

Overwrites a button control on the text selection.

InsertInputCheckbox

Overwrites a check box control on the text selection.

InsertInputFileUpload

Overwrites a file upload control on the text selection.

InsertInputHidden

Inserts a hidden control on the text selection.

InsertInputImage

Overwrites an image control on the text selection.

InsertInputPassword

Overwrites a password control on the text selection.

InsertInputRadio

Overwrites a radio control on the text selection.

InsertInputReset

Overwrites a reset control on the text selection.

InsertInputSubmit

Overwrites a submit control on the text selection.

InsertInputText

Overwrites a text control on the text selection.

InsertMarquee

Overwrites an empty marquee on the text selection.

InsertOrderedList

Toggles the text selection between an ordered list and a normal format block.

InsertParagraph

Overwrites a line break on the text selection.

InsertSelectDropdown

Overwrites a drop-down selection control on the text selection.

InsertSelectListbox

Overwrites a list box selection control on the text selection.

InsertTextArea

Overwrites a multiline text input control on the text selection.

InsertUnorderedList

Toggles the text selection between an ordered list and a normal format block.

Italic

Toggles the current selection between italic and nonitalic.

JustifyCenter

Centers the format block in which the current selection is located.

JustifyFull

Not currently supported.

JustifyLeft

Left-justifies the format block in which the current selection is located.

JustifyNone

Not currently supported.

JustifyRight

Right-justifies the format block in which the current selection is located.

LiveResize

Causes the MSHTML Editor to update an element's appearance continuously during a resizing or moving operation, rather than updating only at the completion of the move or resize.

MultipleSelection

Allows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys.

Open

Not currently supported.

Outdent

Decreases by one increment the indentation of the format block in which the current selection is located.

OverWrite

Toggles the text-entry mode between insert and overwrite.

Paste

Overwrites the contents of the clipboard on the current selection.

PlayImage

Not currently supported.

Print

Opens the print dialog box so the user can print the current page.

Redo

Not currently supported.

Refresh

Refreshes the current document.

RemoveFormat

Removes the formatting tags from the current selection.

RemoveParaFormat

Not currently supported.

SaveAs

Saves the current Web page to a file.

SelectAll

Selects the entire document.

SizeToControl

Not currently supported.

SizeToControlHeight

Not currently supported.

SizeToControlWidth

Not currently supported.

Stop

Not currently supported.

StopImage

Not currently supported.

StrikeThrough

Not currently supported.

Subscript

Not currently supported.

Superscript

Not currently supported.

UnBookmark

Removes any bookmark from the current selection.

Underline

Toggles the current selection between underlined and not underlined.

Undo

Not currently supported.

Unlink

Removes any hyperlink from the current selection.

Unselect

Clears the current selection.

基本上每个命令参数都可以在FTB的FreeTextBoxControls中找到对应的实现类,如果觉得有些没有实现,自己参照已经实现的功能来增加也十分简单和方便。

FTB还提供了公开的接口,例如继承于ToolbarButton可以实现对应的工具按钮,继承于ToolbarDropDownList则实现下拉式选择(如选择字体那种),对应javascript的方法只须传递对应的方法名字符串给类即可,自己写的javascript可以放在js中,也可以放在ScriptBlock的字符串参数里面,前者前端查看源码看不到,后者则将整个函数源码传回,一切都十分公开和方便。

这种思路是否也和ASP.NET的思路类似?

由于javascript可以被多种浏览器支持(估计有些小兼容问题,可以通过javascript来兼容),因此FTB可以在多种环境下正常工作。现在用的这个blog系统(.Text)也用了FTB,但版本是1.6.3.26037(汉化版),有兴趣可以在发表文章的地方查看网页源代码看看,就会发现好多的FTB_XXX的javascript函数。这些在2.0已经全部集中放到FreeTextBox-ToolbarItemsSrcipt.js和FreeTextBox-MainScript.js中了,应该说这样比较归一些。

如果担心FTB的免费协议对商业用途有些影响的话,自己根据这个思路来开发一个适合自己产品用的所见即所得编辑器控件应该也不是难事。

2D-Position 允许通过拖曳移动绝对定位的对象。

AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。

BackColor 设置或获取当前选中区的背景颜色。

BlockDirLTR 目前尚未支持。

BlockDirRTL 目前尚未支持。

Bold 切换当前选中区的粗体显示与否。

BrowseMode 目前尚未支持。

Copy 将当前选中区复制到剪贴板。

CreateBookmark 创建一个书签锚或获取当前选中区或插入点的书签锚的名称。

CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级链接的 URL。

Cut 将当前选中区复制到剪贴板并删除之。

Delete 删除当前选中区。

DirLTR 目前尚未支持。

DirRTL 目前尚未支持。

EditMode 目前尚未支持。

FontName 设置或获取当前选中区的字体。

FontSize 设置或获取当前选中区的字体大小。

ForeColor 设置或获取当前选中区的前景(文本)颜色。

FormatBlock 设置当前块格式化标签。

Indent 增加选中文本的缩进。

InlineDirLTR 目前尚未支持。

InlineDirRTL 目前尚未支持。

InsertButton 用按钮控件覆盖当前选中区。

InsertFieldset 用方框覆盖当前选中区。

InsertHorizontalRule 用水平线覆盖当前选中区。

InsertIFrame 用内嵌框架覆盖当前选中区。

InsertImage 用图像覆盖当前选中区。

InsertInputButton 用按钮控件覆盖当前选中区。

InsertInputCheckbox 用复选框控件覆盖当前选中区。

InsertInputFileUpload 用文件上载控件覆盖当前选中区。

InsertInputHidden 插入隐藏控件覆盖当前选中区。

InsertInputImage 用图像控件覆盖当前选中区。

InsertInputPassword 用密码控件覆盖当前选中区。

InsertInputRadio 用单选钮控件覆盖当前选中区。

InsertInputReset 用重置控件覆盖当前选中区。

InsertInputSubmit 用提交控件覆盖当前选中区。

InsertInputText 用文本控件覆盖当前选中区。

InsertMarquee 用空字幕覆盖当前选中区。

InsertOrderedList 切换当前选中区是编号列表还是常规格式化块。

InsertParagraph 用换行覆盖当前选中区。

InsertSelectDropdown 用下拉框控件覆盖当前选中区。

InsertSelectListbox 用列表框控件覆盖当前选中区。

InsertTextArea 用多行文本输入控件覆盖当前选中区。

InsertUnorderedList 切换当前选中区是项目符号列表还是常规格式化块。

Italic 切换当前选中区斜体显示与否。

JustifyCenter 将当前选中区在所在格式化块置中。

JustifyFull 目前尚未支持。

JustifyLeft 将当前选中区所在格式化块左对齐。

JustifyNone 目前尚未支持。

JustifyRight 将当前选中区所在格式化块右对齐。

LiveResize 迫使 MSHTML 编辑器在缩放或移动过程中持续更新元素外观,而不是只在移动或缩放完成后更新。

MultipleSelection 允许当用户按住 Shift 或 Ctrl 键时一次选中多于一个站点可选元素。

Open 目前尚未支持。

Outdent 减少选中区所在格式化块的缩进。

OverWrite 切换文本状态的插入和覆盖。

Paste 用剪贴板内容覆盖当前选中区。

PlayImage 目前尚未支持。

Print 打开打印对话框以便用户可以打印当前页。

Redo 目前尚未支持。

Refresh 刷新当前文档。

RemoveFormat 从当前选中区中删除格式化标签。

RemoveParaFormat 目前尚未支持。

SaveAs 将当前 Web 页面保存为文件。

SelectAll 选中整个文档。

SizeToControl 目前尚未支持。

SizeToControlHeight 目前尚未支持。

SizeToControlWidth 目前尚未支持。

Stop 目前尚未支持。

StopImage 目前尚未支持。

StrikeThrough 目前尚未支持。

Subscript 目前尚未支持。

Superscript 目前尚未支持。

UnBookmark 从当前选中区中删除全部书签。

Underline 切换当前选中区的下划线显示与否。

Undo 目前尚未支持。

Unlink 从当前选中区中删除全部超级链接。

Unselect 清除当前选中区的选中状态。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: