Ticket #1357: sample01.html

File sample01.html, 3.2 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

this file will show the state of the selection while it changes.

Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<!--
3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
5 *
6 * == BEGIN LICENSE ==
7 *
8 * Licensed under the terms of any of the following licenses at your
9 * choice:
10 *
11 *  - GNU General Public License Version 2 or later (the "GPL")
12 *    http://www.gnu.org/licenses/gpl.html
13 *
14 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15 *    http://www.gnu.org/licenses/lgpl.html
16 *
17 *  - Mozilla Public License Version 1.1 or later (the "MPL")
18 *    http://www.mozilla.org/MPL/MPL-1.1.html
19 *
20 * == END LICENSE ==
21 *
22 * Sample page.
23-->
24<html xmlns="http://www.w3.org/1999/xhtml">
25<head>
26        <title>FCKeditor - Sample</title>
27        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
28        <meta name="robots" content="noindex, nofollow" />
29        <link href="../sample.css" rel="stylesheet" type="text/css" />
30        <script type="text/javascript" src="../../fckeditor.js"></script>
31</head>
32<body>
33        <h1>
34                FCKeditor - JavaScript - Sample 1
35        </h1>
36        <div>
37                This sample displays a normal HTML form with an FCKeditor with full features enabled.
38        </div>
39        <hr />
40        <form action="sampleposteddata.asp" method="post" target="_blank">
41                <script type="text/javascript">
42<!--
43// Automatically calculates the editor base path based on the _samples directory.
44// This is usefull only for these samples. A real application should use something like this:
45// oFCKeditor.BasePath = '/fckeditor/' ;        // '/fckeditor/' is the default value.
46var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;
47
48var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
49oFCKeditor.BasePath     = sBasePath ;
50oFCKeditor.Height       = 300 ;
51oFCKeditor.Value        = '<p>This is some <strong>sample text<\/strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor<\/a>.<\/p>' ;
52oFCKeditor.Create() ;
53//-->
54                </script>
55                <br />
56                <input type="submit" value="Submit" />
57        </form>
58        <div id="output"></div>
59        <script type="text/javascript">
60
61function FCKeditor_OnComplete( editorInstance )
62{
63        FCKSelection = editorInstance.Selection ;
64        editorInstance.Events.AttachEvent( 'OnSelectionChange', updateSelection ) ;
65}
66
67var output;
68var FCKSelection;
69
70function updateSelection()
71{
72        var text = '';
73
74        // The selected node (not valid if nothing is selected)
75        var node = FCKSelection.GetSelectedElement() ;
76        if (node) {
77                text = 'Selected node: ' + node.nodeName ;
78        }
79        // Parent
80        var parent = FCKSelection.GetParentElement() ;
81        if ( parent )
82        {
83                text += '<br>Parent node: ' + parent.nodeName;
84        }
85        if (!output)
86                output = document.getElementById('output');
87
88        output.innerHTML = text;
89}
90
91        </script>
92        <hr>
93        Press "Select all", the info above will say that the current node is P and its parent node is HTML.<br>
94        the problem is in FCKSelection.GetParentElement, oSel is BODY, not P
95<pre>
96        // make the common case fast - for collapsed/nearly collapsed selections just return anchor.parent.
97        if ( oSel.anchorNode && oSel.anchorNode == oSel.focusNode )
98                return oSel.anchorNode.parentNode ;
99</pre>
100</body>
101</html>
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy