| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>Editor Test</title> |
| 6 | |
| 7 | <script type="text/javascript" src="../boilerplate.js"></script> |
| 8 | |
| 9 | |
| 10 | <script type="text/javascript"> |
| 11 | require([ |
| 12 | "dojo/_base/declare", |
| 13 | "dojo/parser", // scan page for widgets and instantiate them |
| 14 | "dijit/Editor", |
| 15 | "dijit/_editor/_Plugin", |
| 16 | "dijit/_editor/plugins/AlwaysShowToolbar", |
| 17 | "dijit/_editor/plugins/FontChoice", // 'fontName','fontSize','formatBlock' |
| 18 | "dijit/_editor/plugins/TextColor", |
| 19 | "dijit/_editor/plugins/LinkDialog", |
| 20 | "dojo/NodeList-dom", // orphan() |
| 21 | "dojo/domReady!" |
| 22 | ], function(declare, parser, Editor, _Plugin){ |
| 23 | |
| 24 | // Dummy simple plugin for testing that filters registered this way work |
| 25 | // properly with content setting on load. |
| 26 | declare("TestFilter", _Plugin, { |
| 27 | setEditor: function(editor){ |
| 28 | this.editor = editor; |
| 29 | this.editor.contentPreFilters.push(function(val){ |
| 30 | if(val){ |
| 31 | val = val.replace("notdojo", "DOJO"); |
| 32 | } |
| 33 | return val; |
| 34 | }); |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | parser.parse(); |
| 39 | |
| 40 | var progEditor = new Editor({ |
| 41 | value: "Custom Initial Content.", |
| 42 | "aria-label": "progEditor" |
| 43 | }, "programmatic3"); |
| 44 | progEditor.startup(); |
| 45 | |
| 46 | var progEditor2 = new Editor({ |
| 47 | contentPreFilters: [function(txt){ return txt; }], |
| 48 | "aria-label": "progEditor2" |
| 49 | }, "programmatic4"); |
| 50 | progEditor2.startup(); |
| 51 | }); |
| 52 | |
| 53 | </script> |
| 54 | </head> |
| 55 | |
| 56 | <body class="claro" role="main"> |
| 57 | <script type="dojo/require"> |
| 58 | dom: "dojo/dom", |
| 59 | lang: "dojo/_base/lang", |
| 60 | query: "dojo/query", |
| 61 | registry: "dijit/registry", |
| 62 | Editor: "dijit/Editor" |
| 63 | </script> |
| 64 | <div data-dojo-type="dijit/Editor" data-dojo-props="plugins:[], focusOnLoad:true, height:'1.5em', style:'border:0px;','aria-label':'automated'" id="automated" |
| 65 | >Automated Test - all check boxes should be checked<script type='dojo/method' data-dojo-event='onFocus'> |
| 66 | if(!document.getElementById('onFocusFired').checked){ |
| 67 | document.getElementById('onFocusFired').checked=true; |
| 68 | document.getElementById('initialValueOK').checked = (registry.byId('automated').getValue() == 'Automated Test - all check boxes should be checked'); |
| 69 | registry.byId('automated').document.execCommand('selectall', false, false); |
| 70 | document.getElementById('onChangeOKnow').checked=true; |
| 71 | registry.byId('automated').document.execCommand('underline', false, false); |
| 72 | setTimeout(lang.hitch(registry.byId('editor0'),"focus",0)); |
| 73 | } |
| 74 | </script |
| 75 | ><script type='dojo/method' data-dojo-event='onBlur'> |
| 76 | if(!document.getElementById('onBlurFired').checked){ |
| 77 | document.getElementById('onBlurFired').checked=true; |
| 78 | registry.byId('automated').set('disabled', true); |
| 79 | setTimeout(function(){ try { |
| 80 | registry.byId('automated').document.execCommand('bold', false, false); |
| 81 | document.getElementById('disabledOK').checked = (registry.byId('automated').document.queryCommandState('bold') == false); |
| 82 | }catch(e){ document.getElementById('disabledOK').checked = true; }}, 0); |
| 83 | } |
| 84 | </script |
| 85 | ><script type='dojo/method' data-dojo-event='onChange'> |
| 86 | if(document.getElementById('onChangeOKnow').checked && !document.getElementById('onChangeFired').checked){ |
| 87 | document.getElementById('onChangeFired').checked=true; |
| 88 | } |
| 89 | </script |
| 90 | ></div> |
| 91 | <label for="onFocusFired">Focus:</label><input type="checkbox" id="onFocusFired" disabled /> |
| 92 | <label for="initialValueOK">Value:</label><input type="checkbox" id="initialValueOK" disabled /> |
| 93 | <input type="checkbox" id="onChangeOKnow" disabled style="display:none;"/> |
| 94 | <label for="onChangeFired">Change:</label><input type="checkbox" id="onChangeFired" disabled /> |
| 95 | <label for="onBlurFired">Blur:</label><input type="checkbox" id="onBlurFired" disabled /> |
| 96 | <label for="disabledOK">Disabled:</label><input type="checkbox" id="disabledOK" disabled /> |
| 97 | <br> |
| 98 | <br> |
| 99 | |
| 100 | <h1 class="testTitle">Editor + Plugins Test</h1> |
| 101 | |
| 102 | <h2>No plugins, initially empty</h2> |
| 103 | <div data-dojo-type="dijit/Editor" data-dojo-props="plugins:[], height:'100', 'aria-label':'applied with aria'" id="editor0"></div> |
| 104 | |
| 105 | <h2><label id="label_editor1">Created from div</label></h2> |
| 106 | <label for="focusBefore">lbl:</label><input id="focusBefore" value="input before editor1"/> |
| 107 | <div data-dojo-type="dijit/Editor" aria-labelledby="label_editor1" data-dojo-props="onChange:function(v){console.log('editor1 onChange handler: ' + v)}, disableSpellCheck:true" id="editor1" |
| 108 | ><p>This instance is created from a div directly with default toolbar and plugins</p> |
| 109 | The following HTML should appear as source: <INPUT TYPE="IMAGE" SRC="javascript:alert('no scripting attacks')"> |
| 110 | </div> |
| 111 | <label for="focusAfter">lbl:</label><input id="focusAfter" value="input after editor1"/> |
| 112 | <button onClick="registry.byId('editor1').destroy()">destroy</button> |
| 113 | <button onClick="registry.byId('editor1').set('disableSpellCheck', !registry.byId('editor1').get('disableSpellCheck'))">toggle spell check</button> |
| 114 | <button onclick="console.log(registry.byId('editor1').get('value'))">getValue</button> |
| 115 | <hr/> |
| 116 | |
| 117 | <h2>Created from div, auto-expanding</h2> |
| 118 | <h3><label id="label_thud">label for editor:</label></h3> |
| 119 | <div data-dojo-type="dijit/Editor" |
| 120 | data-dojo-props="onChange:function(v){console.log('thud onChange handler: ' + v)}, extraPlugins:['dijit/_editor/plugins/AlwaysShowToolbar'], styleSheets:'../../themes/claro/document.css', minHeight:'75px', height:''" |
| 121 | id="thud" aria-labelledby="label_thud"> |
| 122 | Extra text |
| 123 | <p> |
| 124 | This editor is created from a div with AlwaysShowToolbar plugin (do not forget to set height=""). |
| 125 | </p> |
| 126 | <p> |
| 127 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean |
| 128 | semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin |
| 129 | porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. |
| 130 | Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. |
| 131 | Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae |
| 132 | risus. |
| 133 | </p> |
| 134 | The following HTML should appear as source: <INPUT TYPE="IMAGE" SRC="javascript:alert('no scripting attacks')"> |
| 135 | </div> |
| 136 | <h3>..after</h3> |
| 137 | <hr/> |
| 138 | |
| 139 | <h2>Optional toolbar buttons</h2> |
| 140 | <h3><label id="label_blah">blah entry</label></h3> |
| 141 | <div data-dojo-type="dijit/Editor" |
| 142 | data-dojo-props="plugins:['bold','italic','|','createLink','foreColor','hiliteColor',{name:'dijit/_editor/plugins/FontChoice', command:'fontName', generic:true},'fontSize','formatBlock','insertImage','insertHorizontalRule'], styleSheets:'../../themes/claro/document.css'" |
| 143 | id="blah" aria-labelledby="label_blah"> |
| 144 | This instance includes optional toolbar buttons which pull in additional ui (dijit) code. |
| 145 | Note the require() arguments to pull in the associated editor plugins to make |
| 146 | this work. |
| 147 | <br> |
| 148 | <span style="font-family: serif">This is serif.</span> |
| 149 | <br> |
| 150 | <span style="font-family: sans-serif">This is sans-serif.</span> |
| 151 | <br> |
| 152 | <span style="font-family: monospace">This is monospace.</span> |
| 153 | <br> |
| 154 | <span style="font-family: cursive">This is cursive.</span> |
| 155 | <br> |
| 156 | <span style="font-family: fantasy">This is fantasy.</span> |
| 157 | <br> |
| 158 | </div> |
| 159 | <h3>..after</h3> |
| 160 | <button onclick="alert(registry.byId('blah').get('value'));">getValue</button> |
| 161 | <hr/> |
| 162 | |
| 163 | <h2>Plugins specified</h2> |
| 164 | <h3><label id="label_blah2">Another blah entry</label></h3> |
| 165 | <div data-dojo-type="dijit/Editor" aria-labelledby="label_blah2" |
| 166 | data-dojo-props="plugins:['bold','italic','|',{name:'dijit/_editor/plugins/FontChoice', command:'fontName', custom:['Verdana','Myriad','Garamond','Apple Chancery','Hiragino Mincho Pro']}, {name:'dijit/_editor/plugins/FontChoice', command:'fontSize', custom:[3,4,5]}, {name:'dijit/_editor/plugins/EnterKeyHandling', blockNodeForEnter:'DIV'}], styleSheets:'../../themes/claro/document.css'" |
| 167 | id="blah2"> |
| 168 | This instance demos how to: |
| 169 | <ol> |
| 170 | <li>specify which plugins to load (see the plugins property): this instance loads FontChoice plugin, among others;</li> |
| 171 | <li>specify options for a plugin (see the last item in the plugins array)</li> |
| 172 | </ol> |
| 173 | </div> |
| 174 | <h3>..after</h3> |
| 175 | <hr/> |
| 176 | |
| 177 | <h2>Font sizing via style</h2> |
| 178 | <div data-dojo-type="dijit/Editor" data-dojo-props="style:'text-align:left; font-size:30pt'" aria-label="fontSizedEditor" id="fontSizedEditor"> |
| 179 | Hello World! |
| 180 | </div> |
| 181 | |
| 182 | <h2>Checking pre-filter application</h2> |
| 183 | <div data-dojo-type="dijit/Editor" data-dojo-props="extraPlugins:[{name: 'TestFilter'}]" aria-label="filteredEditor" id="filteredEditor"> |
| 184 | notdojo |
| 185 | </div> |
| 186 | |
| 187 | <h2>Checking editor starting with br</h2> |
| 188 | <div data-dojo-type="dijit/Editor" id="brEditor" aria-label="brEditor"> |
| 189 | <br> |
| 190 | some stuff |
| 191 | <br> |
| 192 | some other stuff. |
| 193 | </div> |
| 194 | |
| 195 | <h2>Programmatic creation</h2> |
| 196 | <div id="programmatic">This div will become an editor.</div> |
| 197 | <button |
| 198 | id="create" |
| 199 | onclick="new Editor({}, dom.byId('programmatic')); query('#create').orphan();"> |
| 200 | create static editor |
| 201 | </button> |
| 202 | <div id="programmatic2">This div will become an auto-expanding editor.</div> |
| 203 | <button |
| 204 | id="create2" |
| 205 | onclick="new Editor({height: '', extraPlugins: ['dijit/_editor/plugins/AlwaysShowToolbar']}, dom.byId('programmatic2')); query('#create2').orphan();"> |
| 206 | create expanding editor |
| 207 | </button> |
| 208 | |
| 209 | <br><br> |
| 210 | <div id="programmatic3">This div will become a programmatic editor in addOnLoad with creation-defined default content.</div> |
| 211 | <br><br> |
| 212 | <div id="programmatic4">This div will become a programmatic editor in addOnLoad with creation-defined and custom filters.</div> |
| 213 | |
| 214 | </body> |
| 215 | </html> |