| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 2 | <!-- |
|---|
| 3 | Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. |
|---|
| 4 | For 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 — 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 | |
|---|
| 13 | CKEDITOR.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. |
|---|
| 84 | CKEDITOR.config.extraPlugins = 'customenter'; |
|---|
| 85 | |
|---|
| 86 | </script> |
|---|
| 87 | </head> |
|---|
| 88 | <body> |
|---|
| 89 | <h1 class="samples"> |
|---|
| 90 | CKEditor Sample — 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"><p> |
|---|
| 98 | Pete Fritchman <petef@mozilla.com> wrote:</petef@mozilla.com></p> |
|---|
| 99 | <blockquote type="cite"> |
|---|
| 100 | <pre wrap=""> |
|---|
| 101 | ----- Original Message ----- |
|---|
| 102 | </pre> |
|---|
| 103 | <blockquote type="cite"> |
|---|
| 104 | <pre wrap=""> |
|---|
| 105 | Hey, |
|---|
| 106 | |
|---|
| 107 | This is a cited paragraph at second level. |
|---|
| 108 | |
|---|
| 109 | This is another one. |
|---|
| 110 | </pre> |
|---|
| 111 | </blockquote> |
|---|
| 112 | <pre wrap=""> |
|---|
| 113 | Ok, but this is first level citation</pre> |
|---|
| 114 | <blockquote type="cite"> |
|---|
| 115 | <pre wrap=""> |
|---|
| 116 | Another second level. |
|---|
| 117 | </pre> |
|---|
| 118 | </blockquote> |
|---|
| 119 | <pre wrap=""> |
|---|
| 120 | More at first level. |
|---|
| 121 | |
|---|
| 122 | And even more</pre> |
|---|
| 123 | </blockquote> |
|---|
| 124 | <p> |
|---|
| 125 | &nbsp;</p> |
|---|
| 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 © 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> |
|---|