| 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 | <head> |
|---|
| 8 | <meta charset="utf-8"> |
|---|
| 9 | <title>Replace Textareas by Class Name — CKEditor Sample</title> |
|---|
| 10 | <script src="../ckeditor.js"></script> |
|---|
| 11 | <link rel="stylesheet" href="sample.css"> |
|---|
| 12 | <script> |
|---|
| 13 | |
|---|
| 14 | function selectTable() { |
|---|
| 15 | var editor = CKEDITOR.instances.editor1; |
|---|
| 16 | |
|---|
| 17 | var selection = editor.getSelection(); |
|---|
| 18 | var ancestor = selection.getCommonAncestor(); |
|---|
| 19 | var element = (ancestor) ? ancestor.getAscendant("table") : null; |
|---|
| 20 | if (element) |
|---|
| 21 | { |
|---|
| 22 | selection.selectElement(element); |
|---|
| 23 | console.log('selected element is', element.getName()); |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | </script> |
|---|
| 28 | </head> |
|---|
| 29 | <body> |
|---|
| 30 | <h1 class="samples"> |
|---|
| 31 | <a href="index.html">CKEditor Samples</a> » Replace Textarea Elements by Class Name |
|---|
| 32 | </h1> |
|---|
| 33 | <div class="description"> |
|---|
| 34 | <p> |
|---|
| 35 | This sample shows how to automatically replace all <code><textarea></code> elements |
|---|
| 36 | of a given class with a CKEditor instance. |
|---|
| 37 | </p> |
|---|
| 38 | <p> |
|---|
| 39 | To replace a <code><textarea></code> element, simply assign it the <code>ckeditor</code> |
|---|
| 40 | class, as in the code below: |
|---|
| 41 | </p> |
|---|
| 42 | <pre class="samples"> |
|---|
| 43 | <textarea <strong>class="ckeditor</strong>" name="editor1"></textarea> |
|---|
| 44 | </pre> |
|---|
| 45 | <p> |
|---|
| 46 | Note that other <code><textarea></code> attributes (like <code>id</code> or <code>name</code>) need to be adjusted to your document. |
|---|
| 47 | </p> |
|---|
| 48 | </div> |
|---|
| 49 | <form action="sample_posteddata.php" method="post"> |
|---|
| 50 | <p> |
|---|
| 51 | <label for="editor1"> |
|---|
| 52 | Editor 1: |
|---|
| 53 | </label> |
|---|
| 54 | <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"> |
|---|
| 55 | </textarea> |
|---|
| 56 | </p> |
|---|
| 57 | <p> |
|---|
| 58 | <input type="submit" value="Submit"> |
|---|
| 59 | <input onclick="selectTable();" type="button" value="Select Table"> |
|---|
| 60 | </p> |
|---|
| 61 | </form> |
|---|
| 62 | <div id="footer"> |
|---|
| 63 | <hr> |
|---|
| 64 | <p> |
|---|
| 65 | CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> |
|---|
| 66 | </p> |
|---|
| 67 | <p id="copy"> |
|---|
| 68 | Copyright © 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico |
|---|
| 69 | Knabben. All rights reserved. |
|---|
| 70 | </p> |
|---|
| 71 | </div> |
|---|
| 72 | </body> |
|---|
| 73 | </html> |
|---|
| 74 | |
|---|