Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Rich Text Editor for .NET and ...
»
Re: selection to node
Re: selection to node
01-09-2014, 11:18 PM
Jeff
Joined on 02-22-2011
Posts 126
Re: selection to node
Reply
Quote
Dear Marvin,
I write a demo with mark
if
(info.Arguments[1] ==
"DoMark"
) {
var
nodes = editor.ExtractRangeNodes(
false
);
var
pointnode = editor.GetPointNode();
if
(nodes.length == 0)
return;
var
root = pointnode;
if
(!root.Contains(nodes[0]))
root = root.GetParent();
if
(nodes.length == 1) {
//select 1 node
if
(nodes[0].GetName() ==
"mark"
|| (root.GetName() ==
"mark"
&& root.GetChildCount() == 1)) {
//self is mark node
alert(root.GetName() ==
"mark"
? root.GetAttribute(
"data-value"
) : nodes[0].GetAttribute(
"data-value"
));
}
else
{
var
mark = editor.ParseHtmlCode(
"<mark data-value=\"1\"></mark>"
)[0];
editor.SurroundNode(mark);
editor.Focus();
}
}
else
{
//select multiple nodes
if
(root.GetName() ==
"mark"
&& root.GetChildCount() <= nodes.length) {
//surround with mark node
alert(root.GetAttribute(
"data-value"
));
}
else
{
var
html = editor.ExtractRangeHTML(
true
);
var
mark =
"<mark data-value=\"2\">"
+ html +
"</mark>"
;
editor.InsertHTML(mark);
editor.Focus();
}
}
}
Regards,
Jeff
View Complete Thread