In WebTextEditor, you have 6 choices for ToolBarMode. They are Complete, Custom, Minimal, None, Rich, and Standard. We couldn’t change or edit the existing built-in ToolBar menu because those are created using ourengine.
First step, we make our Custom ToolBar menu. In this case, I tried to create a new symbol in ToolBar. You can put this code inInitializeToolBar event
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;
// image that used for ToolBar menu icon
cmdNew.Image = "./images/other/smiley5.gif";
// make item in ToolBar menu
cmdNew.CommandType = WebTextEditorToolCommandType.InsertSymbol;
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 OnToolBarClickclient-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's 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;
}
Files
You can download the sample of this code in here.
References
For more information about WebTextEditor and its feature, see WebTextEditor features.
For additional how-to topics, videos, knowledge base and other learning resources available for WebTextEditor, see WebTextEditor Support.
Note: This is a "QUICK PUBLISH" article created directly from within the Intersoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.