Ticket #13806: ckeditor222.html

File ckeditor222.html, 2.4 KB (added by Jakub Ś, 8 years ago)
Line 
1<html>
2<head>
3        <script src="../ckeditor.js"></script>
4
5        <script type="text/javascript">
6                var pluginName = 'testWidget';
7
8                CKEDITOR.config.height = 200;
9                CKEDITOR.config.width = 'auto';
10                CKEDITOR.config.extraPlugins = pluginName;
11
12
13                function addWidgetPlugin() {
14
15                        CKEDITOR.plugins.add(pluginName, {
16                                requires: 'widget',
17                                startNode: null,
18                                endNode: null,
19
20                                init: function(editor) {
21                                        editor.widgets.add(pluginName, {
22                                                button: pluginName,
23
24                                                mask: true,
25
26                                                upcast: function(element) {
27                                                        return element.name == pluginName;
28                                                },
29
30                                        });
31
32                                        editor.addCommand('insert', {
33                                                exec: function() {
34                                                        var divC = editor.document.createElement("div");
35                                                        editor.insertElement(divC);
36                                                        var div = editor.document.createElement("div");                                                 
37                                                        div.setText('abc');                                                     
38                                                        divC.append(div);
39                                                        widget = editor.widgets.initOn( div, pluginName );
40                                                        widget.focus();
41                                                }
42                                        });
43                                        editor.ui.addButton( pluginName, {
44                                                label: pluginName,
45                                                command: 'insert',
46                                        });
47
48                                        var bookmark = 'bookmark',
49                                                that = this, realBookmark;
50
51                                        editor.addCommand(bookmark, {
52                                                exec: function() {
53
54                                                        if ( realBookmark ) {
55                                                                console.log('there');   
56                                                               
57                                                                var sel = editor.getSelection(), 
58                                                                        range = sel.getRanges()[0];
59                                                                       
60                                                                range.moveToBookmark( realBookmark );   
61                                                                sel.selectRanges( [ range ] );
62                                                                //range.select();
63                                                                range.scrollIntoView();
64                                                               
65                                                                realBookmark = null;
66                                                                return;
67                                                        }
68
69                                                        var sel = editor.getSelection();
70                                                        editor.lockSelection(sel);
71                                                        var range = sel.getRanges()[0];
72                                                        if (range) {
73                                                                range.trim();
74                                                                console.log('here');
75                                                                realBookmark = range.createBookmark(true);
76                                                                that.startNode = editor.document.getById(realBookmark.startNode);
77
78
79                                                                that.endNode = editor.document.getById(realBookmark.endNode);
80
81                                                                console.log('realBookmark created:');
82                                                                console.log(editor.getData());
83                                                        }
84
85                                                        editor.unlockSelection(sel);
86                                                }
87                                        });
88                                        editor.ui.addButton( bookmark, {
89                                                label: bookmark,
90                                                command: bookmark
91                                        });
92                                }
93                        });
94                }
95
96                addWidgetPlugin();
97
98                var initSample =  function() {
99                        var editorElement = CKEDITOR.document.getById( 'editor' );
100                        CKEDITOR.replace( 'editor' );
101                };
102
103        </script>
104</head>
105<body>
106        <div id="editor">
107        <script type="text/javascript">
108                initSample();
109        </script>
110</body>
111</html>
112
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy