editor.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <html>
  2. <!--
  3. Copyright 2009 The Closure Library Authors. All Rights Reserved.
  4. Use of this source code is governed by the Apache License, Version 2.0.
  5. See the COPYING file for details.
  6. -->
  7. <!--
  8. -->
  9. <head>
  10. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  11. <title>goog.editor Demo</title>
  12. <script src="../../base.js"></script>
  13. <script>
  14. goog.require('goog.dom');
  15. goog.require('goog.editor.Command');
  16. goog.require('goog.editor.Field');
  17. goog.require('goog.editor.plugins.BasicTextFormatter');
  18. goog.require('goog.editor.plugins.EnterHandler');
  19. goog.require('goog.editor.plugins.HeaderFormatter');
  20. goog.require('goog.editor.plugins.LinkBubble');
  21. goog.require('goog.editor.plugins.LinkDialogPlugin');
  22. goog.require('goog.editor.plugins.ListTabHandler');
  23. goog.require('goog.editor.plugins.LoremIpsum');
  24. goog.require('goog.editor.plugins.RemoveFormatting');
  25. goog.require('goog.editor.plugins.SpacesTabHandler');
  26. goog.require('goog.editor.plugins.UndoRedo');
  27. goog.require('goog.ui.editor.DefaultToolbar');
  28. goog.require('goog.ui.editor.ToolbarController');
  29. </script>
  30. <link rel="stylesheet" href="../css/demo.css">
  31. <link rel="stylesheet" href="../../css/button.css" />
  32. <link rel="stylesheet" href="../../css/dialog.css" />
  33. <link rel="stylesheet" href="../../css/linkbutton.css" />
  34. <link rel="stylesheet" href="../../css/menu.css">
  35. <link rel="stylesheet" href="../../css/menuitem.css">
  36. <link rel="stylesheet" href="../../css/menuseparator.css">
  37. <link rel="stylesheet" href="../../css/tab.css" />
  38. <link rel="stylesheet" href="../../css/tabbar.css" />
  39. <link rel="stylesheet" href="../../css/toolbar.css" />
  40. <link rel="stylesheet" href="../../css/colormenubutton.css" />
  41. <link rel="stylesheet" href="../../css/palette.css" />
  42. <link rel="stylesheet" href="../../css/colorpalette.css" />
  43. <link rel="stylesheet" href="../../css/editor/bubble.css" />
  44. <link rel="stylesheet" href="../../css/editor/dialog.css" />
  45. <link rel="stylesheet" href="../../css/editor/linkdialog.css" />
  46. <link rel="stylesheet" href="../../css/editortoolbar.css" />
  47. <style>
  48. #editMe {
  49. width: 600px;
  50. height: 300px;
  51. background-color: white;
  52. border: 1px solid grey;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <h1>goog.editor Demo</h1>
  58. <p>This is a demonstration of a editable field, with installed plugins,
  59. hooked up to a toolbar.</p>
  60. <br>
  61. <div id='toolbar' style='width:602px'></div>
  62. <div id='editMe'></div>
  63. <hr>
  64. <p><b>Current field contents</b>
  65. (updates as contents of the editable field above change):<br>
  66. <textarea id="fieldContents" style="height:100px;width:400px;"></textarea><br>
  67. <input type="button" value="Set Field Contents"
  68. onclick="myField.setHtml(false, goog.dom.getElement('fieldContents').value);" />
  69. (Use to set contents of the editable field to the contents of this textarea)
  70. </p>
  71. <script>
  72. function updateFieldContents() {
  73. goog.dom.getElement('fieldContents').value = myField.getCleanContents();
  74. }
  75. // Create an editable field.
  76. var myField = new goog.editor.Field('editMe');
  77. // Create and register all of the editing plugins you want to use.
  78. myField.registerPlugin(new goog.editor.plugins.BasicTextFormatter());
  79. myField.registerPlugin(new goog.editor.plugins.RemoveFormatting());
  80. myField.registerPlugin(new goog.editor.plugins.UndoRedo());
  81. myField.registerPlugin(new goog.editor.plugins.ListTabHandler());
  82. myField.registerPlugin(new goog.editor.plugins.SpacesTabHandler());
  83. myField.registerPlugin(new goog.editor.plugins.EnterHandler());
  84. myField.registerPlugin(new goog.editor.plugins.HeaderFormatter());
  85. myField.registerPlugin(
  86. new goog.editor.plugins.LoremIpsum('Click here to edit'));
  87. myField.registerPlugin(
  88. new goog.editor.plugins.LinkDialogPlugin());
  89. myField.registerPlugin(new goog.editor.plugins.LinkBubble());
  90. // Specify the buttons to add to the toolbar, using built in default buttons.
  91. var buttons = [
  92. goog.editor.Command.BOLD,
  93. goog.editor.Command.ITALIC,
  94. goog.editor.Command.UNDERLINE,
  95. goog.editor.Command.FONT_COLOR,
  96. goog.editor.Command.BACKGROUND_COLOR,
  97. goog.editor.Command.FONT_FACE,
  98. goog.editor.Command.FONT_SIZE,
  99. goog.editor.Command.LINK,
  100. goog.editor.Command.UNDO,
  101. goog.editor.Command.REDO,
  102. goog.editor.Command.UNORDERED_LIST,
  103. goog.editor.Command.ORDERED_LIST,
  104. goog.editor.Command.INDENT,
  105. goog.editor.Command.OUTDENT,
  106. goog.editor.Command.JUSTIFY_LEFT,
  107. goog.editor.Command.JUSTIFY_CENTER,
  108. goog.editor.Command.JUSTIFY_RIGHT,
  109. goog.editor.Command.SUBSCRIPT,
  110. goog.editor.Command.SUPERSCRIPT,
  111. goog.editor.Command.STRIKE_THROUGH,
  112. goog.editor.Command.REMOVE_FORMAT
  113. ];
  114. var myToolbar = goog.ui.editor.DefaultToolbar.makeToolbar(buttons,
  115. goog.dom.getElement('toolbar'));
  116. // Hook the toolbar into the field.
  117. var myToolbarController =
  118. new goog.ui.editor.ToolbarController(myField, myToolbar);
  119. // Watch for field changes, to display below.
  120. goog.events.listen(myField, goog.editor.Field.EventType.DELAYEDCHANGE,
  121. updateFieldContents);
  122. myField.makeEditable();
  123. updateFieldContents();
  124. </script>
  125. </body>
  126. </html>