| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <title>Editor StyleSheet Test</title> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 6 | |
| 7 | <script type="text/javascript" src="../boilerplate.js"></script> |
| 8 | |
| 9 | <script type="text/javascript"> |
| 10 | require([ |
| 11 | "doh/runner", |
| 12 | "dojo/parser", |
| 13 | "dojo/query", |
| 14 | "dijit/registry", |
| 15 | "dijit/Editor", |
| 16 | "dojo/NodeList-dom", // style() |
| 17 | "dojo/domReady!" |
| 18 | ], function(doh, parser, query, registry){ |
| 19 | |
| 20 | var editor; |
| 21 | |
| 22 | doh.register("setup", [ |
| 23 | function parse(){ |
| 24 | parser.parse(); |
| 25 | editor = registry.byId("editor"); |
| 26 | }, |
| 27 | { |
| 28 | name: "wait for load", |
| 29 | timeout: 5000, |
| 30 | runTest: function(){ |
| 31 | // Editor.onLoadDeferred doesn't seem good enough, editor.window is still unset |
| 32 | // after it fires |
| 33 | var d = new doh.Deferred(); |
| 34 | console.log("initially, editor.window is", editor.window); |
| 35 | editor.onLoadDeferred.then(function(){ |
| 36 | var handle = setInterval(function(){ |
| 37 | if(editor.window){ |
| 38 | clearInterval(handle); |
| 39 | d.callback(true); |
| 40 | } |
| 41 | }, 50); |
| 42 | }); |
| 43 | return d; |
| 44 | } |
| 45 | } |
| 46 | ]); |
| 47 | |
| 48 | doh.register("stylesheets", [ |
| 49 | { |
| 50 | name: "add sheet", |
| 51 | runTest: function(){ |
| 52 | editor.addStyleSheet('test_editor.css'); |
| 53 | |
| 54 | // Wait for stylesheet to take effect and then check if <h1> has border. |
| 55 | // Not checking background color because it could be "red" or #FF0000 or rgb(... |
| 56 | var d = new doh.Deferred(); |
| 57 | setTimeout(d.getTestCallback(function(){ |
| 58 | var h1styles = query("h1", editor.window.document).style("borderTopStyle"); |
| 59 | doh.is(1, h1styles.length, "found h1"); |
| 60 | doh.is("solid", h1styles[0], "h1 border"); |
| 61 | }), 250); |
| 62 | return d; |
| 63 | } |
| 64 | }, |
| 65 | { |
| 66 | name: "remove sheet", |
| 67 | runTest: function(){ |
| 68 | editor.removeStyleSheet('test_editor.css'); |
| 69 | |
| 70 | var h1styles = query("h1", editor.window.document).style("borderTopWidth"); |
| 71 | |
| 72 | // Wait for stylesheet removal to take effect and then check if <h1> has border. |
| 73 | // Not checking background color because it could be "red" or #FF0000 or rgb(... |
| 74 | // Not checking border-width because on IE it's 4px, but border-style is none |
| 75 | // (which means that there's really no border). |
| 76 | var d = new doh.Deferred(); |
| 77 | setTimeout(d.getTestCallback(function(){ |
| 78 | var h1styles = query("h1", editor.window.document).style("borderTopStyle"); |
| 79 | doh.is(1, h1styles.length, "found h1"); |
| 80 | doh.is("none", h1styles[0], "h1 border style"); |
| 81 | }), 250); |
| 82 | return d; |
| 83 | } |
| 84 | } |
| 85 | ]); |
| 86 | |
| 87 | doh.run(); |
| 88 | }); |
| 89 | </script> |
| 90 | </head> |
| 91 | <body class="claro" role="main"> |
| 92 | <script type="dojo/require"> |
| 93 | registry: "dijit/registry" |
| 94 | </script> |
| 95 | <p>Turning on the stylesheet should make header red</p> |
| 96 | <div id="editor" data-dojo-type="dijit/Editor" aria-label="editor" data-dojo-props='name:"field"'> |
| 97 | <h1>Adding stylesheet should make my background red</h1> |
| 98 | <h2>I shouldn't change</h2> |
| 99 | </div> |
| 100 | <button id="addStyleSheet" onclick="registry.byId('editor').addStyleSheet('test_editor.css');">add stylesheet</button> |
| 101 | <button id="removeStyleSheet" onclick="registry.byId('editor').removeStyleSheet('test_editor.css');">remove stylesheet</button> |
| 102 | |
| 103 | </body> |
| 104 | </html> |