FreeTextBox實現機制
FTB的結構主要有三個名稱空間組成:
FreeTextBoxControls,FreeTextBoxControls.Design和FreeTextBoxControls.Support。
使用得最多的是FreeTextBoxControls,基本上用到的介面部件都來自於這裡,例如ToolBar上每個功能Button可以在這裡找到對映,而每個Button又對應著javascrip中的一個函式功能。
例如:下劃線這個功能,有個Underline的類(繼承於ToolbarButton)實現,而這個類實際呼叫客戶端的一段javascript程式碼FTB_Underline(在FreeTextBox-ToolbarItemsSrcipt.js中)。
FTB_Format(ftbName,'underline');
如果再深究下去,仔細跟蹤下這段js的程式碼又可以它呼叫FTB_Format這段程式碼(在FreeTextBox-MainScript.js中)。
editor = FTB_GetIFrame(ftbName);
if (FTB_IsHtmlMode(ftbName)) return;
editor.focus();
editor.document.execCommand(commandName,'',null);
}
它正是通過document的execCommand方法來實現效果的,查MSDN文擋可以發現它對應執行的正是Underline的命令引數。
execCommand可以執行的命令引數:
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.
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的免費協議對商業用途有些影響的話,自己根據這個思路來開發一個適合自己產品用的所見即所得編輯器控制元件應該也不是難事。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-157107/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- NX實現機制淺析
- 事務機制如何實現
- Js非同步機制的實現JS非同步
- docker 實現 Redis 的哨兵機制DockerRedis
- Spring AOP 的實現機制Spring
- Spring IOC容器實現機制Spring
- imp_implementationWithBlock()的實現機制BloC
- Objective-C block 實現機制ObjectBloC
- NodeJS實現websocket代理機制NodeJSWeb
- HashMap的內部實現機制HashMap
- spring aop的實現機制Spring
- Java反射機制實現與原理Java反射
- Oracle Mutex實現機制(轉帖)OracleMutex
- Java實現配置載入機制Java
- MySQL中的MVCC實現機制MySqlMVC
- 併發機制的底層實現
- Nginx accept鎖的機制和實現Nginx
- Istio流量管理實現機制深度解析
- Android RollBack機制實現原理剖析Android
- javascript事件機制底層實現原理JavaScript事件
- Flink原理與實現:Window機制
- IPC實現機制(一)---pipe(匿名管道)
- solr修改評分機制實現排序Solr排序
- Django許可權機制的實現Django
- Java實現生命週期管理機制Java
- Android程式間通訊–訊息機制及IPC機制實現薦Android
- Redis的記憶體和實現機制Redis記憶體
- Kafka核心中的分散式機制實現Kafka分散式
- 聊聊心跳機制及netty心跳實現Netty
- 深入理解事件機制的實現事件
- 詳解Apache Dubbo的SPI實現機制Apache
- Golang利用select實現超時機制Golang
- 實現一個“計劃任務”機制
- [轉載]Spring AOP的實現機制Spring
- Binder機制分析(3)—— 實現自己的Service
- Android 的 Handler 機制實現原理分析Android
- Java 日誌快取機制的實現Java快取
- Python 中 import 的機制與實現PythonImport