aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/editor/field_basic.html
blob: 69a46dc34354a75155cc3bcb255e9f51027301c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>goog.editor.Field</title>
  <script src="../../base.js"></script>
  <script>
    goog.require('goog.dom');
    goog.require('goog.editor.Field');
  </script>
  <link rel="stylesheet" href="../css/demo.css">
  <style>
    #editMe {
      width: 300px;
      height: 150px;
      background-color: white;
      border: 1px solid grey;
    }
  </style>
</head>
<body>
  <h1>goog.editor.Field</h1>
  <p>This is a very basic demonstration of how to make a region editable.</p>
  <input type="button" value="Make Editable" onclick="makeFieldEditable();" />
  <input type="button" value="Make Uneditable"
      onclick="makeFieldUneditable();" />
  <br><br>
  <div id="editMe">I am a regular div.  Click "Make Editable" above to transform me into an editable region.</div>
  <hr>
  <p><b>Current field contents</b>
  (updates as contents of the editable field above change):<br>
  <textarea id="fieldContents" style="height:100px;width:400px;"></textarea><br>
  <input type="button" value="Set Field Contents"
      onclick="myField.setHtml(false, goog.dom.getElement('fieldContents').value);" />
  (Use to set contents of the editable field to the contents of this textarea)
  </p>

  <script>
  var myField = new goog.editor.Field('editMe');

  function makeFieldEditable() {
    goog.events.listen(myField, goog.editor.Field.EventType.LOAD,
        handleFieldLoad);
    goog.events.listen(myField, goog.editor.Field.EventType.DELAYEDCHANGE,
        updateFieldContents);

    myField.makeEditable();
    updateFieldContents();
  }

  function makeFieldUneditable() {
    myField.makeUneditable();
  }

  function handleFieldLoad() {
    // Not necessary, just demoing how to perform an action after the editable
    // field is loaded.  This focuses the field and gives you a blinking cursor
    // at the start.
    myField.focusAndPlaceCursorAtStart();
  }

  function updateFieldContents() {
    goog.dom.getElement('fieldContents').value = myField.getCleanContents();
  }

  </script>
</body>
</html>