seamlessfield.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.SeamlessField</title>
  11. <script src="../../base.js"></script>
  12. <script>
  13. goog.require('goog.dom');
  14. goog.require('goog.editor.SeamlessField');
  15. </script>
  16. <link rel="stylesheet" href="../css/demo.css">
  17. <style>
  18. #editMe {
  19. border: 1px solid grey;
  20. width: 600px;
  21. }
  22. #wrapper {
  23. background-color: #87CEFA;
  24. }
  25. h1 {
  26. font-family: courier;
  27. color: red;
  28. }
  29. p {
  30. margin: 0;
  31. background-color: lightgrey;
  32. }
  33. li {
  34. list-style-type: lower-greek;
  35. }
  36. table p {
  37. margin: 3px;
  38. background-color: white;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <h1>goog.editor.SeamlessField</h1>
  44. <p>This is a very basic demonstration of how to make a region editable, that
  45. blends in with the surrounding page, even if the editable content is inside
  46. an iframe.</p>
  47. <input type="button" value="Make Editable" onclick="makeFieldEditable();" />
  48. <input type="button" value="Make Uneditable"
  49. onclick="makeFieldUneditable();" />
  50. <br>
  51. <div id="wrapper">
  52. <br><br>
  53. <div id="editMe">I am a regular div.
  54. Click <b>"Make Editable"</b> above to transform me into an editable region.
  55. I'll grow and shrink with my content!
  56. And I'll inherit styles from the parent document.
  57. <h1>Heading styled by outer document.</h1>
  58. <ol>
  59. <li>And lists too! One!</li>
  60. <li>Two!</li>
  61. </ol>
  62. <p>Paragraph 1</p>
  63. <table><tr><td>
  64. <p>Inherited CSS works!</p>
  65. </td></tr></table>
  66. </div>
  67. <br><br>
  68. </div>
  69. <hr>
  70. <p><b>Current field contents</b>
  71. (updates as contents of the editable field above change):<br>
  72. <textarea id="fieldContents" style="height:100px;width:400px;"></textarea><br>
  73. <input type="button" value="Set Field Contents"
  74. onclick="myField.setHtml(false, goog.dom.getElement('fieldContents').value);" />
  75. (Use to set contents of the editable field to the contents of this textarea)
  76. </p>
  77. <script>
  78. var myField = new goog.editor.SeamlessField('editMe');
  79. function makeFieldEditable() {
  80. goog.events.listen(myField, goog.editor.Field.EventType.DELAYEDCHANGE,
  81. updateFieldContents);
  82. myField.makeEditable();
  83. updateFieldContents();
  84. }
  85. function makeFieldUneditable() {
  86. myField.makeUneditable();
  87. }
  88. function updateFieldContents() {
  89. goog.dom.getElement('fieldContents').value = myField.getCleanContents();
  90. }
  91. </script>
  92. </body>
  93. </html>