原創|其它|編輯:郝浩|2012-10-25 14:44:07.000|閱讀 387 次
概述:本文解釋了如何在編輯器內創建和集成自定義工具欄,并將其嵌入到其編輯器。
# 界面/圖表報表/文檔/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@fc6vip.cn
文章轉載自:慧都控件網