Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Cute Editor for .NET
»
Re: How to add buttons with function of inserting mark/tag ?
Re: How to add buttons with function of inserting mark/tag ?
04-04-2010, 9:28 PM
Kenneth
Joined on 02-13-2008
Posts 3,886
Re: How to add buttons with function of inserting mark/tag ?
Reply
Quote
Hi
sageking2
,
Try the example below
<%@ Page Language=
"C#"
%>
<%@ Register TagPrefix=
"CE"
Namespace=
"CuteEditor"
Assembly=
"CuteEditor"
%>
<html>
<head>
</head>
<script runat=
"server"
>
protected
override
void
OnLoad(EventArgs e)
{
CuteEditor.ToolControl tc = editor1.ToolControls[
"insertcustombutonhere"
];
Image Image2 =
new
Image();
Image2.ToolTip =
"Insert today's date"
;
Image2.ImageUrl =
"tools.gif"
;
Image2.CssClass =
"CuteEditorButton"
;
Image2.Attributes[
"onclick"
] =
"addMyTag()"
;
tc.Control.Controls.Add(Image2);
base
.OnLoad(e);
}
</script>
<body>
<form id=
"Form1"
runat=
"server"
>
<CE:Editor ID=
"editor1"
runat=
"server"
TemplateItemList=
"insertcustombutonhere"
>
</CE:Editor>
</form>
</body>
</html>
<script>
var editor1=document.getElementById(
"<%= editor1.ClientID %>"
);
function getSelectedHTML(){
// get the active editor window
var editwin = editor1.GetWindow();
// get the active editor document
var editdoc = editor1.GetDocument();
var rng=
null
,html=
""
;
if
(document.selection && document.selection.createRange){
rng=editdoc.selection.createRange();
html=rng.htmlText||
""
;
}
else
if
(window.getSelection){
rng=editwin.getSelection();
if
(rng.rangeCount > 0 && window.XMLSerializer){
rng=rng.getRangeAt(0);
html=
new
XMLSerializer().serializeToString(rng.cloneContents());
}
}
return
html;
}
function addMyTag()
{
editor1.PasteHTML(
"<vi>"
+getSelectedHTML()+
"</vi>"
);
}
</script>
Regards,
Ken
View Complete Thread