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