Debian Codegraph @

closure-library/closure/goog/demos/editor/field_basic.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <meta http-equiv="X-UA-Compatible" content="IE=edge">
11 <title>goog.editor.Field</title>
12 <script src="../../base.js"></script>
13 <script>
14 goog.require('goog.dom');
15 goog.require('goog.editor.Field');
16 </script>
17 <link rel="stylesheet" href="../css/demo.css">
18 <style>
19 #editMe {
20 width: 300px;
21 height: 150px;
22 background-color: white;
23 border: 1px solid grey;
24 }
25 </style>
26 </head>
27 <body>
28 <h1>goog.editor.Field</h1>
29 <p>This is a very basic demonstration of how to make a region editable.</p>
30 <input type="button" value="Make Editable" onclick="makeFieldEditable();" />
31 <input type="button" value="Make Uneditable"
32 onclick="makeFieldUneditable();" />
33 <br><br>
34 <div id="editMe">I am a regular div. Click "Make Editable" above to transform me into an editable region.</div>
35 <hr>
36 <p><b>Current field contents</b>
37 (updates as contents of the editable field above change):<br>
38 <textarea id="fieldContents" style="height:100px;width:400px;"></textarea><br>
39 <input type="button" value="Set Field Contents"
40 onclick="myField.setHtml(false, goog.dom.getElement('fieldContents').value);" />
41 (Use to set contents of the editable field to the contents of this textarea)
42 </p>
43
44 <script>
45 var myField = new goog.editor.Field('editMe');
46
47 function makeFieldEditable() {
48 goog.events.listen(myField, goog.editor.Field.EventType.LOAD,
49 handleFieldLoad);
50 goog.events.listen(myField, goog.editor.Field.EventType.DELAYEDCHANGE,
51 updateFieldContents);
52
53 myField.makeEditable();
54 updateFieldContents();
55 }
56
57 function makeFieldUneditable() {
58 myField.makeUneditable();
59 }
60
61 function handleFieldLoad() {
62 // Not necessary, just demoing how to perform an action after the editable
63 // field is loaded. This focuses the field and gives you a blinking cursor
64 // at the start.
65 myField.focusAndPlaceCursorAtStart();
66 }
67
68 function updateFieldContents() {
69 goog.dom.getElement('fieldContents').value = myField.getCleanContents();
70 }
71
72 </script>
73 </body>
74 </html>