| 1 | <html> |
| 2 | <head> |
| 3 | <title>dojox.html.styles Test</title> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | |
| 6 | <style type="text/css" rel="stylesheet" title="dojoDefault"> |
| 7 | @import "../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 9 | </style> |
| 10 | |
| 11 | <style title="altStyle" type="text/css" rel="alternate stylesheet"> |
| 12 | p{ |
| 13 | font-size:9px; |
| 14 | color:#9999FF; |
| 15 | } |
| 16 | </style> |
| 17 | |
| 18 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: true, fontSizeWatch: true" ></script> |
| 19 | <script type="text/javascript"> |
| 20 | |
| 21 | dojo.require("dojox.html.styles"); |
| 22 | |
| 23 | getSelectedStyleSheet = function(){ |
| 24 | if(dojo.byId("ssDefault").checked) return false; |
| 25 | if(dojo.byId("ssExtra").checked) return "ssExtra"; |
| 26 | } |
| 27 | |
| 28 | enableStyleSheet = function(){ |
| 29 | dojox.html.enableStyleSheet(getSelectedStyleSheet()); |
| 30 | } |
| 31 | |
| 32 | disableStyleSheet = function(){ |
| 33 | dojox.html.disableStyleSheet(getSelectedStyleSheet()); |
| 34 | } |
| 35 | |
| 36 | dojo.ready(function(){ |
| 37 | |
| 38 | console.log(dojo.version.toString()); |
| 39 | var styles = [ |
| 40 | "p { font-size:24; margin:20px;}", |
| 41 | "p { font-size:12; color:#ff0000;}", |
| 42 | ".woot { color:#ff0000; }", |
| 43 | ".woot { color:#00ff00; }", |
| 44 | "p span {font-weight:bold;}", |
| 45 | "span {font-style:italic;}" |
| 46 | ] |
| 47 | |
| 48 | var col = dojo.byId("btnCol"); |
| 49 | dojo.forEach(styles, function(s){ |
| 50 | |
| 51 | var sel = s.substring(0,s.indexOf("{")-1); |
| 52 | var des = s.substring(s.indexOf("{")+1, s.indexOf("}") ); |
| 53 | |
| 54 | var div = dojo.doc.createElement("div"); |
| 55 | col.appendChild(div); |
| 56 | |
| 57 | var d = dojo.doc.createElement("span"); |
| 58 | dojo.style(d, "display", "block"); |
| 59 | d.innerHTML = s; |
| 60 | div.appendChild(d); |
| 61 | |
| 62 | var b = dojo.doc.createElement("button"); |
| 63 | div.appendChild(b); |
| 64 | b.innerHTML = "Insert"; |
| 65 | dojo.connect(b, "click", function(){ |
| 66 | console.log("Add:", s) |
| 67 | dojox.html.insertCssRule(sel, des, getSelectedStyleSheet()); |
| 68 | }); |
| 69 | var b = dojo.doc.createElement("button"); |
| 70 | div.appendChild(b); |
| 71 | b.innerHTML = "Remove"; |
| 72 | dojo.connect(b, "click", function(){ |
| 73 | console.log("Rem:", s); |
| 74 | dojox.html.removeCssRule(sel, des); |
| 75 | }); |
| 76 | |
| 77 | }); |
| 78 | |
| 79 | console.log("Style Sheets tests:"); |
| 80 | console.log("dojox.html.getStyleSheet [is false]:", dojox.html.getStyleSheet()); |
| 81 | |
| 82 | // insert a style, which creates our dynamic style sheet: |
| 83 | var sel = styles[0].substring(0,styles[0].indexOf("{")-1); |
| 84 | var des = styles[0].substring(styles[0].indexOf("{")+1, styles[0].indexOf("}") ); |
| 85 | dojox.html.insertCssRule(sel, des, getSelectedStyleSheet()); |
| 86 | console.log("dojox.html.getStyleSheet [object is default]:", dojox.html.getStyleSheet()); |
| 87 | console.log("dojox.html.activeStyleSheet:", dojox.html.activeStyleSheet().title); |
| 88 | dojo.forEach(dojox.html.getToggledStyleSheets(), function(s){ |
| 89 | console.log(" toggled style sheet:", s.title, "enabled:", !s.disabled); |
| 90 | }); |
| 91 | |
| 92 | var ss = dojox.html.getStyleSheets(); //return object |
| 93 | for(var nm in ss){ |
| 94 | //display either title or href |
| 95 | var name = (ss[nm].title)?ss[nm].title:ss[nm].href; |
| 96 | if(!name){ name = "*Persistant*"} |
| 97 | console.log(" style sheet:", name); |
| 98 | } |
| 99 | |
| 100 | console.log("dojox.html.getStyleSheet [href:dijitTests.css, object]:", dojox.html.getStyleSheet("dijitTests.css")); |
| 101 | console.log("dojox.html.getStyleSheet [title:BadStyleName]:", dojox.html.getStyleSheet("BadStyleName")); |
| 102 | |
| 103 | }); |
| 104 | </script> |
| 105 | <style> |
| 106 | #btnCol{ |
| 107 | width:220px; |
| 108 | } |
| 109 | #btnCol div{ |
| 110 | margin-bottom:10px; |
| 111 | } |
| 112 | body table td{ |
| 113 | vertical-align:top; |
| 114 | |
| 115 | } |
| 116 | button{ |
| 117 | width:70px; |
| 118 | text-align:left; |
| 119 | } |
| 120 | .label{ |
| 121 | color:#666666; |
| 122 | } |
| 123 | </style> |
| 124 | |
| 125 | </head> |
| 126 | |
| 127 | <body> |
| 128 | <h1>dojox.html.styles Test</h1> |
| 129 | <p>With the buttons on the left, insert and remove rules with a dynamically created stylesheet. Use the radio buttons |
| 130 | to create a second style sheet. Toggle them on and off. See the log for more style sheet tests.</p> |
| 131 | <table width="100%" cellspacing="0" cellpadding="0"> |
| 132 | <tr> |
| 133 | <td id="btnCol"> |
| 134 | <span class="label">Dynamic Stylesheets</span> |
| 135 | <div> |
| 136 | <span style="display:block;">Use Style Sheet:</span> |
| 137 | <label for="ssDefault">Default</label> |
| 138 | <input type="radio" name="ss" id="ssDefault" checked="true"/> |
| 139 | <label for="ssExtra">Extra</label> |
| 140 | <input type="radio" name="ss" id="ssExtra" /> |
| 141 | <br> |
| 142 | <button onClick="enableStyleSheet();">Enable</button> |
| 143 | <button onClick="disableStyleSheet();">Disable</button> |
| 144 | </div> |
| 145 | </td> |
| 146 | <td> |
| 147 | <p>paragraph text</p> |
| 148 | |
| 149 | <p class="foo">paragraph class=foo text |
| 150 | <span class="woot">span class=woot</span> |
| 151 | with a span inside it |
| 152 | </p> |
| 153 | |
| 154 | <p class="bar">paragraph class=bar text |
| 155 | <span class="zoot">span class=zoot</span> |
| 156 | with a span inside it |
| 157 | </p> |
| 158 | |
| 159 | <span class="xoot">external span class=xoot</span> |
| 160 | </td> |
| 161 | </tr> |
| 162 | </table> |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | </body> |
| 168 | </html> |