field_basic.html 2.2 KB

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