| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
|---|
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
|---|
| 3 | |
|---|
| 4 | <title>dojo.html selection test</title> |
|---|
| 5 | <script type="text/javascript"> djConfig = { isDebug: true }; </script> |
|---|
| 6 | <script type="text/javascript" src="../dojo.js"></script> |
|---|
| 7 | <script type="text/javascript"> |
|---|
| 8 | |
|---|
| 9 | dojo.require("dojo.html.selection"); |
|---|
| 10 | dojo.require("dojo.event.*"); |
|---|
| 11 | function $ (id) { return dojo.lang.isString(id) ? document.getElementById(id) : id; } |
|---|
| 12 | |
|---|
| 13 | </script> |
|---|
| 14 | <style type="text/css"> h2, h3 { font-size: 1em; margin-top: 2.5em; } h3 { color: black; font-weight: normal; font-style: italic; } </style> |
|---|
| 15 | |
|---|
| 16 | <h2><code>clearSelection</code></h2> |
|---|
| 17 | |
|---|
| 18 | <p id="clearSelection" onmouseover="">The current selection should be cleared when you mouse over this paragraph.</p> |
|---|
| 19 | |
|---|
| 20 | <script type="text/javascript"> |
|---|
| 21 | dojo.addOnLoad(function(){ |
|---|
| 22 | dojo.event.connect($("clearSelection"), "onmouseover", function (e) { |
|---|
| 23 | dojo.html.clearSelection(); |
|---|
| 24 | }); |
|---|
| 25 | }); |
|---|
| 26 | </script> |
|---|
| 27 | |
|---|
| 28 | <h2><code>disableSelection</code> and <code>enableSelection</code></h2> |
|---|
| 29 | |
|---|
| 30 | <p id="enabletest">This is some test text!</p> |
|---|
| 31 | <p><input type="checkbox" id="toggleSelection"><label for="toggleSelection"> toggling this checkbox should enable and disable the ability to select the above paragraph.</label></p> |
|---|
| 32 | |
|---|
| 33 | <script type="text/javascript"> |
|---|
| 34 | dojo.addOnLoad(function(){ |
|---|
| 35 | dojo.event.connect($("toggleSelection"), "onchange", function (e) { |
|---|
| 36 | if ($("toggleSelection").checked) { |
|---|
| 37 | dojo.html.disableSelection($("enabletest")); |
|---|
| 38 | } else { |
|---|
| 39 | dojo.html.enableSelection($("enabletest")); |
|---|
| 40 | } |
|---|
| 41 | }); |
|---|
| 42 | }); |
|---|
| 43 | </script> |
|---|
| 44 | |
|---|
| 45 | <h2><code>selectElement</code></h2> |
|---|
| 46 | |
|---|
| 47 | <p id="selectElementtest">This is some test text!</p> |
|---|
| 48 | <p><input type="button" id="selectElement" value="select the above paragraph"></p> |
|---|
| 49 | |
|---|
| 50 | <script type="text/javascript"> |
|---|
| 51 | dojo.addOnLoad(function(){ |
|---|
| 52 | dojo.event.connect($("selectElement"), "onclick", function (e) { |
|---|
| 53 | dojo.html.selection.selectElementChildren($("selectElementtest")); |
|---|
| 54 | }); |
|---|
| 55 | }); |
|---|
| 56 | </script> |
|---|
| 57 | |
|---|
| 58 | <h2><code>dojo.html.selection.isCollapsed and other information</code></h2> |
|---|
| 59 | |
|---|
| 60 | <p>selection collapsed: <b id="selectionCollapsed"></b></p> |
|---|
| 61 | <p>selection parentElement: <b id="selectionParentElement"></b></p> |
|---|
| 62 | |
|---|
| 63 | <script type="text/javascript"> |
|---|
| 64 | dojo.addOnLoad(function(){ |
|---|
| 65 | setInterval(function () { |
|---|
| 66 | $("selectionCollapsed").innerHTML = dojo.html.selection.isCollapsed(); |
|---|
| 67 | var p = dojo.html.selection.getParentElement(); |
|---|
| 68 | if(p) |
|---|
| 69 | $("selectionParentElement").innerHTML = p.toString(); |
|---|
| 70 | else |
|---|
| 71 | $("selectionParentElement").innerHTML = "null"; |
|---|
| 72 | }, 100); |
|---|
| 73 | }); |
|---|
| 74 | </script> |
|---|
| 75 | |
|---|
| 76 | <h2><code>delete selection</code></h2> |
|---|
| 77 | <textarea>delete this</textarea> |
|---|
| 78 | <p><span id="deleteSelection" onmouseover="">The current selection should be deleted when you mouse over this text span.</span></p> |
|---|
| 79 | <script type="text/javascript"> |
|---|
| 80 | dojo.addOnLoad(function(){ |
|---|
| 81 | dojo.event.connect($("deleteSelection"), "onmouseover", function (e) { |
|---|
| 82 | dojo.html.selection.remove(); |
|---|
| 83 | }); |
|---|
| 84 | }); |
|---|
| 85 | </script> |
|---|