Hi, I am using kendo ui editor and I created a custom tool to clean format.
I need to register an entry to undoRedoStack to make the changes reverted when pressing ctrl+z and redo changes when pressing ctrl+y.
This is the fragment of what I have done:
I need to register an entry to undoRedoStack to make the changes reverted when pressing ctrl+z and redo changes when pressing ctrl+y.
This is the fragment of what I have done:
01.
var
editor = $(
"#symptom-editor, #resolve-editor"
).kendoEditor({
02.
tools: [
03.
"formatBlock"
,
04.
"bold"
,
05.
"italic"
,
06.
"underline"
,
07.
"insertUnorderedList"
,
08.
"insertOrderedList"
,
09.
"indent"
,
10.
"outdent"
,
11.
"createLink"
,
12.
"insertImage"
,
13.
{
14.
name:
"formatting"
,
15.
tooltip:
"Insert code syntax"
,
16.
items: [
17.
{ text:
"C#"
, value:
"pre.brush-csharp"
},
18.
{ text:
"C++"
, value:
"pre.brush-cpp"
},
19.
{ text:
"CSS"
, value:
"pre.brush-css"
},
20.
{ text:
"Java"
, value:
"pre.brush-java"
},
21.
{ text:
"JavaScript"
, value:
"pre.brush-js"
},
22.
{ text:
"Perl"
, value:
"pre.brush-perl"
},
23.
{ text:
"PHP"
, value:
"pre.brush-php"
},
24.
{ text:
"Python"
, value:
"pre.brush-py"
},
25.
{ text:
"Ruby"
, value:
"pre.brush-ruby"
},
26.
{ text:
"SASS"
, value:
"pre.brush-sass"
},
27.
{ text:
"SQL"
, value:
"pre.brush-sql"
},
28.
{ text:
"Visual Basic"
, value:
"pre.brush-vb"
},
29.
{ text:
"HTML / XML"
, value:
"pre.brush-xml"
}
30.
]
31.
},
32.
{
33.
name:
"clearFormat"
,
34.
tooltip:
"Clear format"
35.
},
36.
"viewHtml"
37.
],
38.
stylesheets: [
39.
"css/kendo.editor-custom.css"
40.
],
41.
keyup:
function
(e) {
42.
$(
".vld-tooltip"
).remove();
43.
},
44.
execute:
function
(e) {
45.
var
editor =
this
,
46.
sel = editor.getSelection(),
47.
element = sel.baseNode.parentNode,
48.
stateBefore;
49.
switch
(e.name) {
50.
case
"clearformat"
:
51.
//saves the current history
52.
stateBefore = editor.undoRedoStack.stack;
53.
//cleans the style and class attributes
54.
element.innerHTML = $(element).attr({
"class"
:
null
,
"style"
:
null
}).html();
55.
//TODO: Create an entry to stack
56.
//editor.undoRedoStack.stack = stateBefore;
57.
//editor.undoRedoStack.currentCommandIndex = stateBefore.length - 1;
58.
break
;
59.
case
"formatting"
:
60.
//TODO: clean the children <pre> tags
61.
break
;
62.
}
63.
}
//end execute
64.
});
//end kendoEditor
As a mentioned, I would like to support undo and redo throught the undoRedoStack.
Also, I am re-using the formatting / formatBlock command, I would like to create a new one that behaves like the formatting command. How do I can make it?
Thank you very much for your help.