原創(chuàng)|其它|編輯:郝浩|2012-10-25 14:44:07.000|閱讀 387 次
概述:本文解釋了如何在編輯器內(nèi)創(chuàng)建和集成自定義工具欄,并將其嵌入到其編輯器。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
本文解釋了WebUI Studio WebTextEditor如何在編輯器內(nèi)創(chuàng)建和集成自定義工具欄,并將其嵌入到其編輯器。
WebTextEditor 中有 6 個(gè)ToolBarMode選項(xiàng) 。它們分別是Complete, Custom, Minimal, None, Rich和 Standard。我們不能更改或編輯現(xiàn)有的內(nèi)置工具欄菜單,因?yàn)槟切┦怯梦覀兊囊鎰?chuàng)建的。
制作自定義工具欄( Custom ToolBar )菜單,也就是在工具欄中創(chuàng)建一個(gè)新元件,將下列代碼放入 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; }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)