关键词搜索

源码搜索 ×
×

FreeTextBox3.3.0使用总结

发布2011-12-26浏览4762次

详情内容

他妈的!

为了使用这个FreeTextBox,着实折腾了不少时间。

其实我们一直都有用这个东西,不过版本很低,并且是其他同事的代码,我自己不怎么接触,不熟;现在跑到源站点上下载了一个3.3.0。

总结有几大问题:

0、参数配置问题

  1. <FTB:FreeTextBox id="txtContent" OnSaveClick="btnSubmit_Click"
  2. toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontBackColorsMenu|Bold,Italic,Underline,Strikethrough,Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;InsertTableRowAfter,InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,DeleteTableColumn|InsertDiv,EditStyle,InsertImageFromGallery,Preview,SelectAll,WordClean,NetSpell|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save"
  3. Language="zh-CN"
  4. runat="Server"
  5. Width="95%"
  6. Height="400px"
  7. SupportFolder="~/news/ftb/"
  8. JavaScriptLocation="ExternalFile"
  9. DesignModeCss="designmode.css"
  10. ImageGalleryUrl="./ftb/ftb.imagegallery.aspx?rif={0}&cif={0}"
  11. />

其中

language=“zh-CN”,中文

SupportFolder,对应JavaScriptLocation,是存放JS所在的路径。

ImageGalleryUrl,上传图片页面地址,注意它是这样写的:"./ftb/ftb.imagegallery.aspx?rif={0}&cif={0}"

这个{0}系统会自动置换为ImageGalleryPath的值。

ImageGalleryPath,存放上传图片的路径。我在后台,从配置文件里读出设置赋值给它:

txtContent.ImageGalleryPath = System.Configuration.ConfigurationManager.AppSettings["ImgUpload"];


1、汉化问题

1)首先,引用  FreeTextBox   的时候,应当将属性language=“zh-CN”

  1. <FTB:FreeTextBox id="txtContent" OnSaveClick="btnSubmit_Click"
  2. toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontBackColorsMenu|Bold,Italic,Underline,Strikethrough,Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;InsertTableRowAfter,InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,DeleteTableColumn|InsertDiv,EditStyle,InsertImageFromGallery,Preview,SelectAll,WordClean,NetSpell|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save"
  3. Language="zh-CN"
  4. runat="Server"
  5. Width="95%"
  6. Height="400px"
  7. SupportFolder="~/news/ftb/"
  8. JavaScriptLocation="ExternalFile"
  9. DesignModeCss="designmode.css"
  10. ImageGalleryUrl="./ftb/ftb.imagegallery.aspx?rif={0}&cif={0}"
  11. />

2)有些提示,包括插入图片窗口的文字,可以直接修改js文件

这里有一些问题要注意:

引用FreeTextBox的时候,要将

JavaScriptLocation="ExternalFile"
其中,
SupportFolder="~/news/ftb/"
就是JS存放的位置

汉化JS以后,要注意文件的编码问题。我编辑的时候,源文件是GB2312的,要另存为UTF-8编码的。


3)上传图片(image gallery)这个的汉化,要重载控件<FTB:ImageGallery> 的Render事件

  1. public partial class ftb_imagegallery : System.Web.UI.Page
  2. {
  3. protected override void Render(HtmlTextWriter writer)
  4. {
  5. writer.Write(this.ChineseGallery());
  6. }
  7. /// <summary>
  8. /// 获取控件,汉化之
  9. /// </summary>
  10. /// <returns></returns>
  11. private string ChineseGallery()
  12. {
  13. StringWriter writer = new StringWriter(); //提供一个可以写的文本区域
  14. HtmlTextWriter buffer = new HtmlTextWriter(writer); //让htmlWriter操作这个区域,我们就可以获得这个区域里的内容
  15. base.Render(buffer); //先让页面画一遍,让我们得到初始的页面html代码
  16. string html = writer.ToString(); //找到这段代码,我们来处理它,把英文变成汉字
  17. //
  18. html = html.Replace("There are no images:", "现在还没有图片");
  19. html = html.Replace("Upload File", "上传图片");
  20. html = html.Replace("Status</div>", "状态</div>");
  21. html = html.Replace("Selected Image", "选中的图片");
  22. html = html.Replace("Create Folder", "创建目录");
  23. html = html.Replace("Delete Image", "删除该图片");
  24. html = html.Replace("\"Upload\"", "\"上传\"");
  25. html = html.Replace("<legend>Preview", "<legend>预览图片");
  26. html = html.Replace("<legend>Dimensions", "<legend>设置显示尺寸");
  27. html = html.Replace("Original Size", "原图大小");
  28. html = html.Replace("Custom Size", "设置为");
  29. html = html.Replace("Lock image ratio", "锁定尺寸比例");
  30. html = html.Replace("Percentage", "百分比");
  31. html = html.Replace("Image Gallery", "我的像册");
  32. html = html.Replace("<legend>Properties", "<legend>图片属性");
  33. html = html.Replace("Align", "横向排列");
  34. html = html.Replace("Border", "边框");
  35. html = html.Replace("VSpace", "左边距");
  36. html = html.Replace("HSpace", "上边距");
  37. html = html.Replace("Alt", "转换文字");
  38. html = html.Replace("Title", "图片标题");
  39. html = html.Replace("value=\"Insert\"", "value=\"插入到编辑器中\"");
  40. //
  41. return html;
  42. }
  43. }
这样就可以得到一个汉化的图片上传界面


2、license(许可证)问题

FreeTextBox有一些功能需要许可证。比如插入图片,如果没有许可证,它只弹出一个JS的对话框,让你简单地写个地址,而不是功能比较强的设置界面。我在本地测试时,因为会自动有个许可证,没发现这个问题,等上传到服务器后,才发现这个功能不能使用,大惑不解,搞了好一阵子,超级恶心。

网上有个神人传授了生成许可证的方法,又是DES加密,又是多少空格,我一看头都大了。时间耗不起。

幸好FreeTextBox的作者比较厚道,是否有许可证,目前看,只区别于是否会输出这么一句:

<script type="text/javascript" src="/WebManage/news/ftb/FTB-Pro.js"></script>

本地有许可证

  1. <script type="text/javascript" src="/WebManage/news/ftb/FTB-Utility.js"></script>
  2. <script type="text/javascript" src="/WebManage/news/ftb/FTB-FreeTextBox.js"></script>
  3. <script type="text/javascript" src="/WebManage/news/ftb/FTB-ToolbarItems.js"></script><script type="text/javascript" src="/WebManage/news/ftb/FTB-Pro.js"></script>
  4. <!-- ************************************************* -->
  5. <!-- * FreeTextBox v3 (3.3.0.22838) * -->
  6. <!-- * http://www.freetextbox.com/ * -->
  7. <!-- * ASP.NET HTML editor for PC/IE & Mozilla * -->
  8. <!-- * License Type: LocalhostLicense (To: none) * -->
  9. <!-- ************************************************* -->


服务器上没有许可证

  1. <script type="text/javascript" src="/webmanage/news/ftb/FTB-Utility.js"></script>
  2. <script type="text/javascript" src="/webmanage/news/ftb/FTB-FreeTextBox.js"></script>
  3. <script type="text/javascript" src="/webmanage/news/ftb/FTB-ToolbarItems.js"></script>
  4. <!-- ************************************************ -->
  5. <!-- * FreeTextBox v3 (3.3.0.22838) * -->
  6. <!-- * http://www.freetextbox.com/ * -->
  7. <!-- * ASP.NET HTML editor for PC/IE & Mozilla * -->
  8. <!-- * License Type: NoLicense (To: Unlicensed) * -->
  9. <!-- ************************************************ -->

结果我手动将这句加在控件后面,就可以用插入图片功能了。


  1. <FTB:FreeTextBox id="txtContent" OnSaveClick="btnSubmit_Click"
  2. toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontBackColorsMenu|Bold,Italic,Underline,Strikethrough,Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;InsertTableRowAfter,InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,DeleteTableColumn|InsertDiv,EditStyle,InsertImageFromGallery,Preview,SelectAll,WordClean,NetSpell|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save"
  3. Language="zh-CN"
  4. runat="Server"
  5. Width="95%"
  6. Height="400px"
  7. SupportFolder="~/news/ftb/"
  8. JavaScriptLocation="ExternalFile"
  9. DesignModeCss="designmode.css"
  10. ImageGalleryUrl="./ftb/ftb.imagegallery.aspx?rif={0}&cif={0}"
  11. />
  12. <script type="text/javascript" src="/WebManage/news/ftb/FTB-Pro.js"></script>

注意要加在后面。放控件前面不行。不知道为什么。


3、IE及IE内核浏览器兼容问题

体现在上传图片这里。

用FF、Chrome浏览器都没问题,但IE6\7以及基于这些内核的酷狗也,360也,一打开图片上传,就死机。这个跟是否有许可证没有关系,估计是跟JS有关系。因为在官方DEMO上,我用同样的浏览器去试,一点问题没有。看页面源代码,它没有直接引用JS,应该是靠控件自己输出JS模式的。

后来,将FTB-ImageGallery.js里的2句代码注释了就好了。


  1. function FTB_ResizeGalleryArea() {
  2. gallery = document.getElementById('Gallery');
  3. galleryTop = document.getElementById('GalleryTop');
  4. galleryBottom = document.getElementById('GalleryBottom');
  5. sideBar = document.getElementById('GallerySideBar');
  6. if (FTB_Browser.isIE) {
  7. // check window height
  8. if (document.body.offsetHeight < (galleryTop.offsetHeight + galleryBottom.offsetHeight + sideBar.offsetHeight) ) {
  9. window.resizeTo(750, galleryTop.offsetHeight + galleryBottom.offsetHeight + sideBar.offsetHeight+100);
  10. }
  11. //这段代码会死机
  12. //gallery.style.height = document.body.offsetHeight - (galleryTop.offsetHeight + galleryBottom.offsetHeight);
  13. //gallery.style.width = document.body.offsetWidth - sideBar.offsetWidth;
  14. } else {
  15. if (window.innerHeight < (galleryTop.offsetHeight + galleryBottom.offsetHeight + sideBar.offsetHeight) ) {
  16. window.resizeTo(750, galleryTop.offsetHeight + galleryBottom.offsetHeight + sideBar.offsetHeight+100);
  17. }
  18. gallery.style.height = window.innerHeight - (galleryTop.offsetHeight + galleryBottom.offsetHeight);
  19. gallery.style.width = window.innerWidth - sideBar.offsetWidth;
  20. }
  21. };





相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载