FreeTextBox的实现机制

      刚开始试用FTB2.0的时候,感觉FTB真的很神,居然可以在网页状态实现编辑过程的What you see is what you get。看完FTB的文档(其实也不是很多的东西,估计就是用个NDOC或者什么类似的工具生成的SDK文档)又仔细试做了几个程序,觉得FTB的实现思路不复杂,但十分巧妙。它通过FTB这个中间部件将客户端(浏览器)的程序(javascript代码)和后台程序(C#写的aspx等ASP.NET代码)紧密结合,从而实现了这种所见即所得的效果。

FTB的结构主要有三个命名空间组成:
FreeTextBoxControls,FreeTextBoxControls.Design和FreeTextBoxControls.Support。

       使用得最多的是FreeTextBoxControls,基本上用到的界面部件都来自于这里,例如ToolBar上每个功能Button可以在这里找到映射,而每个Button又对应着javascrip中的一个函数功能。

例如:下划线这个功能,有个Underline的类(继承于ToolbarButton)实现,而这个类实际调用客户端的一段javascript代码FTB_Underline(在FreeTextBox-ToolbarItemsSrcipt.js中)。

None.gif function  FTB_Underline(ftbName) { 
None.gif    FTB_Format(ftbName,'underline'); 
None.gif

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

None.gif function  FTB_Format(ftbName,commandName) {
None.gif    editor 
=  FTB_GetIFrame(ftbName);
None.gif
None.gif    
if  (FTB_IsHtmlMode(ftbName))  return ;
None.gif    editor.focus();
None.gif    editor.document.execCommand(commandName,'',
null );
None.gif
None.gif}
None.gif

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

execCommand可以执行的命令参数:

None.gif Command Identifiers
None.gif2D-Position
None.gifAllows absolutely positioned elements to be moved by dragging.
None.gif
None.gifAbsolutePosition
None.gifSets an element's position property to "absolute."
None.gif
None.gifBackColor
None.gifSets or retrieves the background color of the current selection.
None.gif
None.gifBlockDirLTR
None.gifNot currently supported.
None.gif
None.gifBlockDirRTL
None.gifNot currently supported.
None.gif
None.gifBold
None.gifToggles the current selection between bold and nonbold.
None.gif
None.gifBrowseMode
None.gifNot currently supported.
None.gif
None.gifClearAuthenticationCache
None.gifClears all authentication credentials from the cache. Applies only to execCommand.
None.gif
None.gifCopy
None.gifCopies the current selection to the clipboard.
None.gif
None.gifCreateBookmark
None.gifCreates a bookmark anchor or retrieves the name of a bookmark anchor for the current selection or insertion point.
None.gif
None.gifCreateLink
None.gifInserts 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.
None.gif
None.gifCut
None.gifCopies the current selection to the clipboard and then deletes it.
None.gif
None.gifDelete
None.gifDeletes the current selection.
None.gif
None.gifDirLTR
None.gifNot currently supported.
None.gif
None.gifDirRTL
None.gifNot currently supported.
None.gif
None.gifEditMode
None.gifNot currently supported.
None.gif
None.gifFontName
None.gifSets or retrieves the font for the current selection.
None.gif
None.gifFontSize
None.gifSets or retrieves the font size for the current selection.
None.gif
None.gifForeColor
None.gifSets or retrieves the foreground (text) color of the current selection.
None.gif
None.gifFormatBlock
None.gifSets the current block format tag.
None.gif
None.gifIndent
None.gifIncreases the indent of the selected text by one indentation increment.
None.gif
None.gifInlineDirLTR
None.gifNot currently supported.
None.gif
None.gifInlineDirRTL
None.gifNot currently supported.
None.gif
None.gifInsertButton
None.gifOverwrites a button control on the text selection.
None.gif
None.gifInsertFieldset
None.gifOverwrites a box on the text selection.
None.gif
None.gifInsertHorizontalRule
None.gifOverwrites a horizontal line on the text selection.
None.gif
None.gifInsertIFrame
None.gifOverwrites an inline frame on the text selection.
None.gif
None.gifInsertImage
None.gifOverwrites an image on the text selection.
None.gif
None.gifInsertInputButton
None.gifOverwrites a button control on the text selection.
None.gif
None.gifInsertInputCheckbox
None.gifOverwrites a check box control on the text selection.
None.gif
None.gifInsertInputFileUpload
None.gifOverwrites a file upload control on the text selection.
None.gif
None.gifInsertInputHidden
None.gifInserts a hidden control on the text selection.
None.gif
None.gifInsertInputImage
None.gifOverwrites an image control on the text selection.
None.gif
None.gifInsertInputPassword
None.gifOverwrites a password control on the text selection.
None.gif
None.gifInsertInputRadio
None.gifOverwrites a radio control on the text selection.
None.gif
None.gifInsertInputReset
None.gifOverwrites a reset control on the text selection.
None.gif
None.gifInsertInputSubmit
None.gifOverwrites a submit control on the text selection.
None.gif
None.gifInsertInputText
None.gifOverwrites a text control on the text selection.
None.gif
None.gifInsertMarquee
None.gifOverwrites an empty marquee on the text selection.
None.gif
None.gifInsertOrderedList
None.gifToggles the text selection between an ordered list and a normal format block.
None.gif
None.gifInsertParagraph
None.gifOverwrites a line break on the text selection.
None.gif
None.gifInsertSelectDropdown
None.gifOverwrites a drop-down selection control on the text selection.
None.gif
None.gifInsertSelectListbox
None.gifOverwrites a list box selection control on the text selection.
None.gif
None.gifInsertTextArea
None.gifOverwrites a multiline text input control on the text selection.
None.gif
None.gifInsertUnorderedList
None.gifToggles the text selection between an ordered list and a normal format block.
None.gif
None.gifItalic
None.gifToggles the current selection between italic and nonitalic.
None.gif
None.gifJustifyCenter
None.gifCenters the format block in which the current selection is located.
None.gif
None.gifJustifyFull
None.gifNot currently supported.
None.gif
None.gifJustifyLeft
None.gifLeft-justifies the format block in which the current selection is located.
None.gif
None.gifJustifyNone
None.gifNot currently supported.
None.gif
None.gifJustifyRight
None.gifRight-justifies the format block in which the current selection is located.
None.gif
None.gifLiveResize
None.gifCauses 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.
None.gif
None.gifMultipleSelection
None.gifAllows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys.
None.gif
None.gifOpen
None.gifNot currently supported.
None.gif
None.gifOutdent
None.gifDecreases by one increment the indentation of the format block in which the current selection is located.
None.gif
None.gifOverWrite
None.gifToggles the text-entry mode between insert and overwrite.
None.gif
None.gifPaste
None.gifOverwrites the contents of the clipboard on the current selection.
None.gif
None.gifPlayImage
None.gifNot currently supported.
None.gif
None.gifPrint
None.gifOpens the print dialog box so the user can print the current page.
None.gif
None.gifRedo
None.gifNot currently supported.
None.gif
None.gifRefresh
None.gifRefreshes the current document.
None.gif
None.gifRemoveFormat
None.gifRemoves the formatting tags from the current selection.
None.gif
None.gifRemoveParaFormat
None.gifNot currently supported.
None.gif
None.gifSaveAs
None.gifSaves the current Web page to a file.
None.gif
None.gifSelectAll
None.gifSelects the entire document.
None.gif
None.gifSizeToControl
None.gifNot currently supported.
None.gif
None.gifSizeToControlHeight
None.gifNot currently supported.
None.gif
None.gifSizeToControlWidth
None.gifNot currently supported.
None.gif
None.gifStop
None.gifNot currently supported.
None.gif
None.gifStopImage
None.gifNot currently supported.
None.gif
None.gifStrikeThrough
None.gifNot currently supported.
None.gif
None.gifSubscript
None.gifNot currently supported.
None.gif
None.gifSuperscript
None.gifNot currently supported.
None.gif
None.gifUnBookmark
None.gifRemoves any bookmark from the current selection.
None.gif
None.gifUnderline
None.gifToggles the current selection between underlined and not underlined.
None.gif
None.gifUndo
None.gifNot currently supported.
None.gif
None.gifUnlink
None.gifRemoves any hyperlink from the current selection.
None.gif
None.gifUnselect
None.gifClears the current selection.
None.gif
None.gif

       基本上每个命令参数都可以在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的免费协议对商业用途有些影响的话,自己根据这个思路来开发一个适合自己产品用的所见即所得编辑器控件应该也不是难事。

转载于:https://www.cnblogs.com/lhnicker/archive/2006/09/22/511448.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值