彩票走势图

巧用WebUI Studio WebTextEditor编辑器创建和集成自定义工具栏

原创|其它|编辑:郝浩|2012-10-25 14:44:07.000|阅读 349 次

概述:本文解释了如何在编辑器内创建和集成自定义工具栏,并将其嵌入到其编辑器。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

本文解释了WebUI Studio WebTextEditor如何在编辑器内创建和集成自定义工具栏,并将其嵌入到其编辑器。

WebTextEditor 中有 6 个ToolBarMode选项 。它们分别是Complete, Custom, Minimal, None, Rich和 Standard。我们不能更改或编辑现有的内置工具栏菜单,因为那些是用我们的引擎创建的。

制作自定义工具栏( Custom ToolBar )菜单,也就是在工具栏中创建一个新元件,将下列代码放入 InitializeToolBar 事件即可:

protected void WebTextEditor1_InitializeToolBar(object sender, ISNet.WebUI.WebTextEditor.WebTextEditorToolBarArgs e)
{
   WebTextEditorToolBar tb = e.GetToolBarByCategory(WebTextEditorToolBarCategory.Standard);
   if (tb != null)
   {
      WebTextEditorToolCommandCollection commands = tb.ToolCommands;
      WebTextEditorToolCommand cmdNew = new WebTextEditorToolCommand();
      cmdNew.Name = "customSymbol";
      cmdNew.Text = "Custom Symbols";
      cmdNew.Type = WebTextEditorToolBarCommandType.DropDownButton;
      cmdNew.DisplayMode = WebTextEditorToolBarCommandDisplayMode.Image;
      cmdNew.CommandType = WebTextEditorToolCommandType.InsertSymbol;
      cmdNew.Image = "./images/other/smiley5.gif";  // image that used for ToolBar menu icon
      cmdNew.CommandType = WebTextEditorToolCommandType.InsertSymbol;
      // make item in ToolBar menu
      WebTextEditorToolItem newItem1 = new WebTextEditorToolItem();
      newItem1.Text = "‰";
      newItem1.Name = "perMille";
      WebTextEditorToolItem newItem2 = new WebTextEditorToolItem();
      newItem2.Text = "•";
      newItem2.Name = "dot";
      WebTextEditorToolItem newItem3 = new WebTextEditorToolItem();
      newItem3.Text = "?";
      newItem3.Name = "lambda";
      cmdNew.Items.Add(newItem1);
      cmdNew.Items.Add(newItem2);
      cmdNew.Items.Add(newItem3);
      commands.Add(cmdNew);
   }
}
Next step, you can add the event handler when item in
ToolBar is being clicked in Javascript. You can add this code in OnToolBarClick
client-side event:function toolbarclick(controlId, command, commandSection) {
   var WebTextEditor1 = ISGetObject("WebTextEditor1");
   if (command.Name == "customSymbol") {
      command.Items.GetNamedItem("perMille").OnItemClick = "perMille";
      command.Items.GetNamedItem("dot").OnItemClick = "dot";
      command.Items.GetNamedItem("lambda").OnItemClick = "lambda";
   }
   return true;
}

To insert the symbol to the WebTextEditor content, you will
need to use some scripts. However, we will need to add additional codes in IE
because it behaves differently not like the others. function perMille() {
   var WebTextEditor1 = ISGetObject("WebTextEditor1");
   var contentWindow = WebTextEditor1.GetSelectedSectionElement().contentWindow;
   if (IS.moz || IS.chrome) {
      contentWindow.document.execCommand("insertHTML", null, "‰");
   }
   else if (IS.ie) {
      if (WebTextEditor1.LastCursorPosition == null) {
         contentWindow.focus();
         var range = WebTextEditor1.GetRange();
         window.setTimeout(function () { range.pasteHTML("‰") }, 10);
      }
      else {
         WebTextEditor1.LastCursorPosition.text = WebTextEditor1.LastCursorPosition.text + "‰";
      }
   }
   return true;
}
function dot() {
   var WebTextEditor1 = ISGetObject("WebTextEditor1");
   var contentWindow = WebTextEditor1.GetSelectedSectionElement().contentWindow;
   if (IS.moz || IS.chrome) {
      contentWindow.document.execCommand("insertHTML", null, "•");
   }
   else if (IS.ie) {
      if (WebTextEditor1.LastCursorPosition == null) {
         contentWindow.focus();
         var range = WebTextEditor1.GetRange();
         window.setTimeout(function () { range.pasteHTML("•") }, 10);
      }
      else {
         WebTextEditor1.LastCursorPosition.text = WebTextEditor1.LastCursorPosition.text + "•";
      }
   }
   return true;
}
       
function lambda() {
   var WebTextEditor1 = ISGetObject("WebTextEditor1");
   var contentWindow = WebTextEditor1.GetSelectedSectionElement().contentWindow;
   if (IS.moz || IS.chrome) {
      contentWindow.document.execCommand("insertHTML", null, "?");
   }
   else if (IS.ie) {
      if (WebTextEditor1.LastCursorPosition == null) {
         contentWindow.focus();
         var range = WebTextEditor1.GetRange();
         window.setTimeout(function () { range.pasteHTML("?") }, 10);
      }
      else {
         WebTextEditor1.LastCursorPosition.text = WebTextEditor1.LastCursorPosition.text + "?";
      }
   }
   return true;
}

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP