|
| 1 | +<!-- |
| 2 | +This example demonstrates how to consume the Scribe |
| 3 | +editor using RequireJS and the AMD module syntax. |
| 4 | +
|
| 5 | +Note that you'll need to install scribe's dependencies through |
| 6 | +`bower install`. See http://bower.io/ if you are unfamiliar. |
| 7 | +--> |
| 8 | +<style> |
| 9 | + button { |
| 10 | + height: 3em; |
| 11 | + } |
| 12 | + |
| 13 | + .active { |
| 14 | + border-style: inset; |
| 15 | + } |
| 16 | + |
| 17 | + .rte, .rte-toolbar { |
| 18 | + display: block; |
| 19 | + } |
| 20 | + |
| 21 | + p { |
| 22 | + margin-top: 0; |
| 23 | + } |
| 24 | + |
| 25 | + .rte { |
| 26 | + border: 1px solid gray; |
| 27 | + height: 300px; |
| 28 | + overflow: auto; |
| 29 | + } |
| 30 | + .rte-output { |
| 31 | + width: 100%; |
| 32 | + height: 10em; |
| 33 | + } |
| 34 | +</style> |
| 35 | +<script src="../bower_components/requirejs/require.js"></script> |
| 36 | +<script> |
| 37 | +require({ |
| 38 | + paths: { |
| 39 | + 'scribe-common': '../bower_components/scribe-common', |
| 40 | + 'lodash-amd': '../bower_components/lodash-amd', |
| 41 | + 'html-janitor': '../bower_components/html-janitor/html-janitor', |
| 42 | + 'immutable': '../bower_components/immutable/dist/immutable' |
| 43 | + } |
| 44 | +}, [ |
| 45 | + '../src/scribe', |
| 46 | + '../bower_components/scribe-plugin-toolbar/src/scribe-plugin-toolbar', |
| 47 | + '../bower_components/scribe-plugin-formatter-plain-text-convert-new-lines-to-html/src/scribe-plugin-formatter-plain-text-convert-new-lines-to-html', |
| 48 | + '../bower_components/scribe-plugin-sanitizer/src/scribe-plugin-sanitizer', |
| 49 | + '../bower_components/scribe-plugin-inline-styles-to-elements/src/scribe-plugin-inline-styles-to-elements', |
| 50 | + '../bower_components/scribe-plugin-heading-command/src/scribe-plugin-heading-command', |
| 51 | + '../bower_components/scribe-plugin-link-prompt-command/src/scribe-plugin-link-prompt-command', |
| 52 | + '../bower_components/scribe-plugin-blockquote-command/src/scribe-plugin-blockquote-command' |
| 53 | + |
| 54 | +], function ( |
| 55 | + Scribe, |
| 56 | + scribePluginToolbar, |
| 57 | + scribePluginFormatterPlainTextConvertNewLinesToHtml, |
| 58 | + scribePluginSanitizer, |
| 59 | + scribePluginInlineStyles, |
| 60 | + scribePluginHeadingCommand, |
| 61 | + scribePluginLinkPromptCommand, |
| 62 | + scribePluginBlockquoteCommand |
| 63 | +) { |
| 64 | + var scribe = new Scribe(document.querySelector('.rte'), |
| 65 | + {allowBlockElements: false}); |
| 66 | + window.scribe = scribe; |
| 67 | + |
| 68 | + scribe.setContent('<p>Hello, World!<\/p>'); |
| 69 | + |
| 70 | + scribe.use(scribePluginToolbar(document.querySelector('.rte-toolbar'))); |
| 71 | + scribe.use(scribePluginFormatterPlainTextConvertNewLinesToHtml()); |
| 72 | + scribe.use(scribePluginInlineStyles()); |
| 73 | + scribe.use(scribePluginHeadingCommand(2)); |
| 74 | + scribe.use(scribePluginBlockquoteCommand()); |
| 75 | + scribe.use(scribePluginSanitizer({ tags: { |
| 76 | + p: {}, |
| 77 | + b: {}, |
| 78 | + i: {}, |
| 79 | + br: {}, |
| 80 | + h2: {}, |
| 81 | + a: {}, |
| 82 | + blockquote: {} |
| 83 | + }})); |
| 84 | + scribe.use(scribePluginLinkPromptCommand()); |
| 85 | + |
| 86 | + scribe.on('content-changed', updateHtml); |
| 87 | + |
| 88 | + function updateHtml() { |
| 89 | + document.querySelector('.rte-output').value = scribe.getHTML(); |
| 90 | + } |
| 91 | + |
| 92 | + updateHtml(); |
| 93 | +}); |
| 94 | +</script> |
| 95 | +<div class="rte-toolbar"> |
| 96 | + <button data-command-name="bold">Bold</button> |
| 97 | + <button data-command-name="italic">Italic</button> |
| 98 | + <button data-command-name="linkPrompt">Link</button> |
| 99 | + <button data-command-name="h2">H2</button> |
| 100 | + <button data-command-name="blockquote">Blockquote</button> |
| 101 | +</div> |
| 102 | +<div class="rte"></div> |
| 103 | +<section> |
| 104 | + <h1>Output</h1> |
| 105 | + <textarea class="rte-output" readonly></textarea> |
| 106 | +</section> |
0 commit comments