helloworld.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <!--
  3. Copywrite 2009 Google Inc. All Rights Reserved.
  4. -->
  5. <html>
  6. <!--
  7. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  8. Use of this source code is governed by the Apache License, Version 2.0.
  9. See the COPYING file for details.
  10. -->
  11. <head>
  12. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  13. <title>goog.editor Hello World plugins Demo</title>
  14. <script src="../../base.js"></script>
  15. <script src="deps.js"></script>
  16. <script>
  17. goog.require('goog.dom');
  18. goog.require('goog.editor.Field');
  19. goog.require('goog.editor.Field.EventType');
  20. goog.require('goog.demos.editor.HelloWorld');
  21. goog.require('goog.demos.editor.HelloWorldDialogPlugin');
  22. </script>
  23. <link rel="stylesheet" href="../css/demo.css">
  24. <link rel="stylesheet" href="../../css/dialog.css" />
  25. <style>
  26. #editMe {
  27. width: 600px;
  28. height: 300px;
  29. background-color: white;
  30. border: 1px solid grey;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <h1>goog.editor Hello World plugins Demo</h1>
  36. <p>This is a demonstration of an editable field with the two sample plugins
  37. installed: goog.editor.plugins.HelloWorld and
  38. goog.editor.plugins.HelloWorldDialogPlugin.</p>
  39. <br>
  40. <button onclick='doHelloWorld()'>Hello World</button>
  41. <button onclick='doHelloWorldDialog()'>Hello World Dialog</button><br>
  42. <div id='editMe'><ul>
  43. <li>Click <b>Hello World</b> to insert "Hello World!".</li>
  44. <li>Click <b>Hello World Dialog</b> to open a dialog where you can customize
  45. your hello world message to be inserted.</li>
  46. </ul>The hello world message will be inserted at the cursor, or will replace
  47. the selected text.</div>
  48. <hr>
  49. <p><b>Current field contents</b>
  50. (updates as contents of the editable field above change):<br>
  51. <textarea id="fieldContents" style="height:100px;width:400px;"></textarea><br>
  52. <input type="button" value="Set Field Contents"
  53. onclick="myField.setHtml(false, goog.dom.getElement('fieldContents').value);" />
  54. (Use to set contents of the editable field to the contents of this textarea)
  55. </p>
  56. <script>
  57. function doHelloWorld() {
  58. myField.execCommand(goog.demos.editor.HelloWorld.COMMAND.HELLO_WORLD);
  59. }
  60. function doHelloWorldDialog() {
  61. myField.execCommand(
  62. goog.demos.editor.HelloWorldDialogPlugin.Command.HELLO_WORLD_DIALOG);
  63. }
  64. function updateFieldContents() {
  65. goog.dom.getElement('fieldContents').value = myField.getCleanContents();
  66. }
  67. // Create an editable field.
  68. var myField = new goog.editor.Field('editMe');
  69. // Create and register all of the editing plugins you want to use.
  70. myField.registerPlugin(new goog.demos.editor.HelloWorld());
  71. myField.registerPlugin(new goog.demos.editor.HelloWorldDialogPlugin());
  72. // Watch for field changes, to display below.
  73. goog.events.listen(myField, goog.editor.Field.EventType.DELAYEDCHANGE,
  74. updateFieldContents);
  75. myField.makeEditable();
  76. updateFieldContents();
  77. // Workaround for bug where on page load hello world doesn't work because
  78. // the field doesn't have focus yet.
  79. myField.focusAndPlaceCursorAtStart();
  80. </script>
  81. </body>
  82. </html>