Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 lars 1
<!DOCTYPE html>
2
<!--
3
Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
4
For licensing, see LICENSE.md or http://ckeditor.com/license
5
-->
6
<html>
7
 
8
    <head>
9
        <meta charset="utf-8">
10
        <title>Using API to Customize Dialog Windows &mdash; CKEditor Sample</title>
11
        <script src="../../../ckeditor.js"></script>
12
        <link rel="stylesheet" href="../../../samples/sample.css">
13
        <meta name="ckeditor-sample-name" content="Using the JavaScript API to customize dialog windows">
14
        <meta name="ckeditor-sample-group" content="Advanced Samples">
15
        <meta name="ckeditor-sample-description" content="Using the dialog windows API to customize dialog windows without changing the original editor code.">
16
        <style>
17
            .cke_button__mybutton_icon {
18
                display: none !important;
19
            }
20
 
21
            .cke_button__mybutton_label {
22
                display: inline !important;
23
            }
24
        </style>
25
        <script>
26
            CKEDITOR.on('instanceCreated', function(ev)
27
            {
28
                var editor = ev.editor;
29
                // Listen for the "pluginsLoaded" event, so we are sure that the
30
                // "dialog" plugin has been loaded and we are able to do our
31
                // customizations.
32
                editor.on('pluginsLoaded', function()
33
                {
34
                    // If our custom dialog has not been registered, do that now.
35
                    if (!CKEDITOR.dialog.exists('myDialog'))
36
                    {
37
                        // We need to do the following trick to find out the dialog
38
                        // definition file URL path. In the real world, you would simply
39
                        // point to an absolute path directly, like "/mydir/mydialog.js".
40
                        var href = document.location.href.split('/');
41
                        href.pop();
42
                        href.push('assets/my_dialog.js');
43
                        href = href.join('/');
44
                        // Finally, register the dialog.
45
                        CKEDITOR.dialog.add('myDialog', href);
46
                    }
47
                    // Register the command used to open the dialog.
48
                    editor.addCommand('myDialogCmd', new CKEDITOR.dialogCommand('myDialog'));
49
                    // Add the a custom toolbar buttons, which fires the above
50
                    // command..
51
                    editor.ui.add('MyButton', CKEDITOR.UI_BUTTON,
52
                    {
53
                        label: 'My Dialog',
54
                        command: 'myDialogCmd'
55
                    });
56
                });
57
            });
58
            // When opening a dialog, its "definition" is created for it, for
59
            // each editor instance. The "dialogDefinition" event is then
60
            // fired. We should use this event to make customizations to the
61
            // definition of existing dialogs.
62
            CKEDITOR.on('dialogDefinition', function(ev)
63
            {
64
                // Take the dialog name and its definition from the event data.
65
                var dialogName = ev.data.name;
66
                var dialogDefinition = ev.data.definition;
67
                // Check if the definition is from the dialog we're
68
                // interested on (the "Link" dialog).
69
                if (dialogName == 'myDialog' && ev.editor.name == 'editor2')
70
                {
71
                    // Get a reference to the "Link Info" tab.
72
                    var infoTab = dialogDefinition.getContents('tab1');
73
                    // Add a new text field to the "tab1" tab page.
74
                    infoTab.add(
75
                    {
76
                        type: 'text',
77
                        label: 'My Custom Field',
78
                        id: 'customField',
79
                        'default': 'Sample!',
80
                        validate: function()
81
                        {
82
                            if ((/\d/).test(this.getValue())) return 'My Custom Field must not contain digits';
83
                        }
84
                    });
85
                    // Remove the "select1" field from the "tab1" tab.
86
                    infoTab.remove('select1');
87
                    // Set the default value for "input1" field.
88
                    var input1 = infoTab.get('input1');
89
                    input1['default'] = 'www.example.com';
90
                    // Remove the "tab2" tab page.
91
                    dialogDefinition.removeContents('tab2');
92
                    // Add a new tab to the "Link" dialog.
93
                    dialogDefinition.addContents(
94
                    {
95
                        id: 'customTab',
96
                        label: 'My Tab',
97
                        accessKey: 'M',
98
                        elements: [
99
                        {
100
                            id: 'myField1',
101
                            type: 'text',
102
                            label: 'My Text Field'
103
                        },
104
                        {
105
                            id: 'myField2',
106
                            type: 'text',
107
                            label: 'Another Text Field'
108
                        }]
109
                    });
110
                    // Provide the focus handler to start initial focus in "customField" field.
111
                    dialogDefinition.onFocus = function()
112
                    {
113
                        var urlField = this.getContentElement('tab1', 'customField');
114
                        urlField.select();
115
                    };
116
                }
117
            });
118
            var config = {
119
                extraPlugins: 'dialog',
120
                toolbar: [
121
                    ['MyButton']
122
                ]
123
            };
124
        </script>
125
    </head>
126
 
127
    <body>
128
        <h1 class="samples">
129
            <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Using CKEditor Dialog API </h1>
130
        <div class="description">
131
            <p> This sample shows how to use the
132
                <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.dialog">CKEditor Dialog API</a> to customize CKEditor dialog windows without changing the original editor code. The following customizations are being done in the example below: </p>
133
            <p> For details on how to create this setup check the source code of this sample page. </p>
134
        </div>
135
        <p>A custom dialog is added to the editors using the <code>pluginsLoaded</code> event, from an external
136
            <a target="_blank" href="assets/my_dialog.js">dialog definition file</a>:</p>
137
        <ol>
138
            <li>
139
                <strong>Creating a custom dialog window</strong> &ndash; "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li>
140
            <li>
141
                <strong>Creating a custom button</strong> &ndash; Add button to open the dialog with "My Dialog" toolbar button.</li>
142
        </ol>
143
        <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
144
        <script>
145
            // Replace the <textarea id="editor1"> with an CKEditor instance.
146
            CKEDITOR.replace('editor1', config);
147
        </script>
148
        <p>The below editor modify the dialog definition of the above added dialog using the <code>dialogDefinition</code> event:</p>
149
        <ol>
150
            <li>
151
                <strong>Adding dialog tab</strong> &ndash; Add new tab "My Tab" to dialog window.</li>
152
            <li>
153
                <strong>Removing a dialog window tab</strong> &ndash; Remove "Second Tab" page from the dialog window.</li>
154
            <li>
155
                <strong>Adding dialog window fields</strong> &ndash; Add "My Custom Field" to the dialog window.</li>
156
            <li>
157
                <strong>Removing dialog window field</strong> &ndash; Remove "Select Field" selection field from the dialog window.</li>
158
            <li>
159
                <strong>Setting default values for dialog window fields</strong> &ndash; Set default value of "Text Field" text field. </li>
160
            <li>
161
                <strong>Setup initial focus for dialog window</strong> &ndash; Put initial focus on "My Custom Field" text field. </li>
162
        </ol>
163
        <textarea cols="80" id="editor2" name="editor2" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
164
        <script>
165
            // Replace the <textarea id="editor1"> with an CKEditor instance.
166
            CKEDITOR.replace('editor2', config);
167
        </script>
168
        <div id="footer">
169
            <hr>
170
            <p> CKEditor - The text editor for the Internet -
171
                <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
172
            </p>
173
            <p id="copy"> Copyright &copy; 2003-2014,
174
                <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p>
175
        </div>
176
    </body>
177
 
178
</html>