Ticket #7354: 7354.html

File 7354.html, 4.3 KB (added by Frederico Caldeira Knabben, 13 years ago)

Plugin prototype.

Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<!--
3Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
4For licensing, see LICENSE.html or http://ckeditor.com/license
5-->
6<html xmlns="http://www.w3.org/1999/xhtml">
7<head>
8        <title>Replace Textareas by Class Name &mdash; CKEditor Sample</title>
9        <meta content="text/html; charset=utf-8" http-equiv="content-type" />
10        <script type="text/javascript" src="/ckeditor/ckeditor_source.js"></script>
11        <script type="text/javascript">
12
13CKEDITOR.plugins.add( 'customenter',
14        {
15                init : function( editor )
16                {
17                        editor.on( 'key', function( ev )
18                                {
19                                        if ( ev.data.keyCode == 13 )    // ENTER
20                                        {
21                                                // Get the elements tree to reach the start of the range.
22                                                var selection = editor.getSelection(),
23                                                        element = selection && selection.getStartElement(),
24                                                        elements = element && ( new CKEDITOR.dom.elementPath( element ) ).elements;
25
26                                                if ( elements )
27                                                {
28                                                        for ( var i = elements.length - 1 ; i >= 0 ; i-- )
29                                                        {
30                                                                var element = elements[ i ]
31                                                                if ( element.is( 'blockquote' ) )
32                                                                {
33                                                                        if ( element.getAttribute( 'type' ) == 'cite' )
34                                                                        {
35                                                                                // Get the range that represents the selection.
36                                                                                var range = editor.getSelection().getRanges()[0];
37
38                                                                                // Cleanup the selected contents.
39                                                                                range.deleteContents();
40
41                                                                                // Split the current block, if any.
42                                                                                var splitInfo = range.splitBlock( 'p' ),
43                                                                                        previousBlock = splitInfo.previousBlock;
44
45                                                                                // It may not split it if we're at the very start of the blockquote.
46                                                                                // At that position, simply do nothing.
47                                                                                if ( previousBlock )
48                                                                                {
49                                                                                        // Create the element that will have the focus.
50                                                                                        var newBlock = editor.document.createElement( 'p' );
51
52                                                                                        // Append the bogus <br> for non IE.
53                                                                                        if ( !CKEDITOR.env.ie )
54                                                                                                newBlock.appendBogus();
55
56                                                                                        // Insert the new element after the split one.
57                                                                                        newBlock.insertAfter( splitInfo.previousBlock );
58
59                                                                                        // If we're still inside the root blockquote, let's break it.
60                                                                                        if ( element.contains( newBlock ) )
61                                                                                                newBlock.breakParent( element );
62
63                                                                                        // Finally move the selection to the new element.
64                                                                                        range.moveToElementEditStart( newBlock );
65                                                                                        range.select();
66                                                                                }
67
68                                                                                // Prevent the default ENTER behavior.
69                                                                                ev.cancel();
70                                                                        }
71
72                                                                        // We'll stop processing at the first <blockquote>, even if it's not a "cite".
73                                                                        return;
74                                                                }
75                                                        }
76                                                }
77                                        }
78                                }
79                                , null, null, 1);       // 1 == High Priority
80                }
81        });     
82
83// Add this plugin to the global configurations.
84CKEDITOR.config.extraPlugins = 'customenter';
85
86        </script>
87</head>
88<body>
89        <h1 class="samples">
90                CKEditor Sample &mdash; Replace Textarea Elements by Class Name
91        </h1>
92
93        <form action="sample_posteddata.php" method="post">
94                <p>
95                        <label for="editor1">
96                                Editor 1:</label>
97                        <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"><pre class="wiki">&lt;p&gt;
98        Pete Fritchman &lt;petef@mozilla.com&gt; wrote:&lt;/petef@mozilla.com&gt;&lt;/p&gt;
99&lt;blockquote type="cite"&gt;
100        &lt;pre wrap=""&gt;
101----- Original Message -----
102&lt;/pre&gt;
103        &lt;blockquote type="cite"&gt;
104                &lt;pre wrap=""&gt;
105Hey,
106
107This is a cited paragraph at second level.
108
109This is another one.
110&lt;/pre&gt;
111        &lt;/blockquote&gt;
112        &lt;pre wrap=""&gt;
113Ok, but this is first level citation&lt;/pre&gt;
114        &lt;blockquote type="cite"&gt;
115                &lt;pre wrap=""&gt;
116Another second level.
117&lt;/pre&gt;
118        &lt;/blockquote&gt;
119        &lt;pre wrap=""&gt;
120More at first level.
121
122And even more&lt;/pre&gt;
123&lt;/blockquote&gt;
124&lt;p&gt;
125        &amp;nbsp;&lt;/p&gt;
126</pre></textarea>
127                </p>
128                <p>
129                        <input type="submit" value="Submit" />
130                </p>
131        </form>
132        <div id="footer">
133                <hr />
134                <p>
135                        CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
136                </p>
137                <p id="copy">
138                        Copyright &copy; 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
139                        Knabben. All rights reserved.
140                </p>
141        </div>
142</body>
143</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy