1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""> |
---|
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 Textarea by Code — CKEditor Sample</title> |
---|
10 | <script src="../ckeditor.js"></script> |
---|
11 | <link href="sample.css" rel="stylesheet"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <h1 class="samples"> |
---|
15 | <a href="index.html">CKEditor Samples</a> » Replace Textarea Elements Using JavaScript Code |
---|
16 | </h1> |
---|
17 | <form action="sample_posteddata.php" method="post"> |
---|
18 | <div class="description"> |
---|
19 | <p> |
---|
20 | This editor is using an <code><iframe></code> element-based editing area, provided by the <strong>Wysiwygarea</strong> plugin. |
---|
21 | </p> |
---|
22 | <pre class="samples"> |
---|
23 | CKEDITOR.replace( '<em>textarea_id</em>' ) |
---|
24 | </pre> |
---|
25 | </div> |
---|
26 | <button type="button" onclick="scrollToParagraph('#p1');">Scroll to Paragraph 1</button> |
---|
27 | <button type="button" onclick="scrollToParagraph('#p2');">Scroll to Paragraph 2</button> |
---|
28 | <button type="button" onclick="scrollToParagraph('#p3');">Scroll to Paragraph 3</button> |
---|
29 | <div id="editor1"> |
---|
30 | |
---|
31 | </div> |
---|
32 | <script> |
---|
33 | |
---|
34 | // This call can be placed at any point after the |
---|
35 | // <textarea>, or inside a <head><script> in a |
---|
36 | // window.onload event handler. |
---|
37 | |
---|
38 | // Replace the <textarea id="editor"> with an CKEditor |
---|
39 | // instance, using default configurations. |
---|
40 | |
---|
41 | var editor = CKEDITOR.replace( 'editor1', { |
---|
42 | allowedContent: true |
---|
43 | } ); |
---|
44 | |
---|
45 | editor.on('instanceReady', function() { |
---|
46 | editor.setData("<p id='p1'>p1</p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p id='p2'>p2</p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p id='p3'>p3</p>"); |
---|
47 | }); |
---|
48 | |
---|
49 | window.scrollToParagraph = function (selector) { |
---|
50 | console.log(selector); |
---|
51 | console.log(editor.document.getBody().find(selector)); |
---|
52 | CKEDITOR.instances.editor1.document.getBody().find(selector).getItem(0).scrollIntoView(); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | </script> |
---|
57 | <p> |
---|
58 | <input type="submit" value="Submit"> |
---|
59 | </p> |
---|
60 | </form> |
---|
61 | <div id="footer"> |
---|
62 | <hr> |
---|
63 | <p> |
---|
64 | CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> |
---|
65 | </p> |
---|
66 | <p id="copy"> |
---|
67 | Copyright © 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico |
---|
68 | Knabben. All rights reserved. |
---|
69 | </p> |
---|
70 | </div> |
---|
71 | </body> |
---|
72 | </html> |
---|