1 | <html> |
---|
2 | <head> |
---|
3 | <script src="//cdn.ckeditor.com/4.4.7/standard-all/ckeditor.js" type="text/javascript" ></script> |
---|
4 | </head> |
---|
5 | <body> |
---|
6 | <div> |
---|
7 | <div id='add'>add</div> |
---|
8 | <div id='remove'>remove</div> |
---|
9 | </div> |
---|
10 | <div id='editors'></div> |
---|
11 | |
---|
12 | |
---|
13 | <script> |
---|
14 | |
---|
15 | var add = document.getElementById('add'); |
---|
16 | add.addEventListener('click', function() { |
---|
17 | |
---|
18 | // ************************************************************* CREATE EDITOR ************** |
---|
19 | var editors = document.getElementById('editors'); |
---|
20 | var newDiv = document.createElement('div'); |
---|
21 | editors.appendChild(newDiv); |
---|
22 | |
---|
23 | var disableContentFilter = true; |
---|
24 | var rightToLeft = false; |
---|
25 | var items = 'Bold,Italic,Strike,Underline,TextColor,BGColor,Font,FontSize,NumberedList,BulletedList,Outdent,Indent,Blockquote,Link,Unlink,Anchor,HorizontalRuleSpecialChar,RemoveFormat,Undo,Redo,Source'; |
---|
26 | var shortcuts = ''; |
---|
27 | |
---|
28 | var config = { |
---|
29 | resize_enabled : false, |
---|
30 | enterMode : CKEDITOR.ENTER_DIV, |
---|
31 | removeButtons : '', |
---|
32 | disableNativeSpellChecker : false, |
---|
33 | browserContextMenuOnCtrl : false, |
---|
34 | removePlugins : 'elementspath,magicline,tabletools,liststyle,contextmenu', |
---|
35 | extraPlugins : 'colorbutton,floatpanel,panel,panelbutton,button,font,richcombo,listblock', |
---|
36 | entities : false, |
---|
37 | extraAllowedContent : 'p[id];img[!src,alt];h1;h2;h3;div;pre;fieldset;legend;*{*}', |
---|
38 | disallowedContent : '*[on*]' |
---|
39 | }; |
---|
40 | if (disableContentFilter) { |
---|
41 | config.allowedContent = true; |
---|
42 | } |
---|
43 | if (rightToLeft) { |
---|
44 | config.contentsLangDirection = 'rtl'; |
---|
45 | } |
---|
46 | config.toolbar = [ { |
---|
47 | items : [] |
---|
48 | } ]; |
---|
49 | var itemsArray = items.split(","); |
---|
50 | for (var i = 0; i < itemsArray.length; i++) { |
---|
51 | config.toolbar[0].items.push(itemsArray[i]); |
---|
52 | } |
---|
53 | |
---|
54 | var shortcutArray = shortcuts.split(","); |
---|
55 | for (var i = 0; i < shortcutArray.length; i++) { |
---|
56 | var itemsArray = shortcutArray[i].split("+"); |
---|
57 | var code = 0; |
---|
58 | for (var j = 0; j < itemsArray.length; j++) { |
---|
59 | if (itemsArray[j] == "CKEDITOR.CTRL") |
---|
60 | code += CKEDITOR.CTRL; |
---|
61 | else if (itemsArray[j] == "CKEDITOR.SHIFT") |
---|
62 | code += CKEDITOR.SHIFT; |
---|
63 | else if (itemsArray[j] == "CKEDITOR.ALT") |
---|
64 | code += CKEDITOR.ALT; |
---|
65 | else |
---|
66 | code += parseInt(itemsArray[j]); |
---|
67 | } |
---|
68 | CKEDITOR.config.blockedKeystrokes.push(code); |
---|
69 | } |
---|
70 | |
---|
71 | var editor = CKEDITOR.appendTo(newDiv, config, ''); |
---|
72 | newDiv.id = editor.name; |
---|
73 | editor = null; |
---|
74 | |
---|
75 | |
---|
76 | // ************************************************************* |
---|
77 | }); |
---|
78 | |
---|
79 | var remove = document.getElementById('remove'); |
---|
80 | remove.addEventListener('click', function() { |
---|
81 | |
---|
82 | // ************************************************************* REMOVE EDITOR ************** |
---|
83 | var editors = document.getElementById('editors'); |
---|
84 | var editorElement = editors.childNodes[editors.childNodes.length - 1]; |
---|
85 | |
---|
86 | var editor = CKEDITOR.instances[editorElement.id]; |
---|
87 | editor.removeAllListeners(); |
---|
88 | editor.destroy(); |
---|
89 | |
---|
90 | editors.removeChild(editorElement); |
---|
91 | // ************************************************************* |
---|
92 | }); |
---|
93 | </script> |
---|
94 | </body> |
---|
95 | </html> |
---|