ondijitclick.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Test Dijit Internal Event: "ondijitclick"</title>
  6. <script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
  7. <script type="text/javascript">
  8. dojo.require("doh.runner");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dojo.parser");
  11. dojo.declare("dijit.WidgetWithOndijitclick",
  12. dijit._Widget,
  13. {
  14. clickCount: 0,
  15. _onClick: function() {
  16. this.clickCount++;
  17. },
  18. postCreate: function() {
  19. this.connect(this.domNode, "ondijitclick", "_onClick");
  20. }
  21. }
  22. );
  23. dojo.addOnLoad(function(){
  24. doh.register("ondijitclick",
  25. [
  26. {
  27. name: "ondijitclick fires once on a space-key-up",
  28. runTest: function(t){
  29. var w = dijit.byId("widget1");
  30. if (dojo.isSafari){ // safari has error
  31. this.name += " * SKIPPED *";
  32. return;
  33. }
  34. // simulate space up
  35. if (document.createEvent){
  36. var e = document.createEvent("KeyboardEvent");
  37. e.initKeyEvent("keyup",true,true,null,false,false,false,false,32,0);
  38. w.domNode.focus();
  39. w.clickCount = 0;
  40. w.domNode.dispatchEvent(e);
  41. t.is(1, w.clickCount);
  42. }
  43. }
  44. },
  45. {
  46. name: "ondijitclick fires once on an enter-key-down",
  47. runTest: function(t){
  48. var w = dijit.byId("widget1");
  49. if (dojo.isSafari){ // safari has error
  50. this.name += " * SKIPPED *";
  51. return;
  52. }
  53. // simulate enter down
  54. if (document.createEvent && !dojo.isSafari){
  55. var e = document.createEvent("KeyboardEvent");
  56. e.initKeyEvent("keydown",true,true,null,false,false,false,false,13,0);
  57. w.domNode.focus();
  58. w.clickCount = 0;
  59. w.domNode.dispatchEvent(e);
  60. t.is(1, w.clickCount);
  61. }
  62. }
  63. },
  64. {
  65. name: "ondijitclick fires once on a mouse click",
  66. runTest: function(t){
  67. var w = dijit.byId("widget1");
  68. // simulate enter up
  69. if (document.createEvent){
  70. var e = document.createEvent("MouseEvents");
  71. e.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 3, 3, false, false, false, false, 0, w.domNode);
  72. w.clickCount = 0;
  73. w.domNode.dispatchEvent(e);
  74. t.is(1, w.clickCount);
  75. }
  76. }
  77. }
  78. ]
  79. );
  80. doh.run();
  81. });
  82. </script>
  83. </head>
  84. <body class="tundra">
  85. <div id="widget1" dojoType="dijit.WidgetWithOndijitclick"></div>
  86. </body>
  87. </html>