Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Cute Editor for .NET
»
Re: Custom Button using the Selected Text
Re: Custom Button using the Selected Text
08-20-2009, 12:15 AM
Kenneth
Joined on 02-13-2008
Posts 3,886
Re: Custom Button using the Selected Text
Reply
Quote
Hi Lozzi,
Try this example
<%@ Page Language=
"C#"
Debug=
"true"
%>
<%@ Register Assembly=
"CuteEditor"
Namespace=
"CuteEditor"
TagPrefix=
"CE"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title>Untitled Page</title>
</head>
<script runat=
"server"
>
protected
override
void
OnLoad(EventArgs e)
{
CuteEditor.ToolControl tc = Editor1.ToolControls[
"insertcustombutonhere"
];
if
(tc !=
null
)
{
HtmlButton button1 =
new
HtmlButton();
button1.InnerText =
"Custom"
;
button1.Attributes[
"onclick"
] =
"handleSelect()"
;
tc.Control.Controls.Add(button1);
}
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 handleSelect()
{
var sel = getSelectedHTML();
editor1.PasteHTML(sel+
'handle select'
);
}
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;
}
</script>
Regards,
Ken
View Complete Thread