_testCommon.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * _testCommon.js - a simple module to be included in dijit test pages to allow
  3. * for easy switching between the many many points of the test-matrix.
  4. *
  5. * in your test browser, provides a way to switch between available themes, and
  6. * optionally enable RTL (right to left) mode, and/or dijit_a11y (high-
  7. * constrast/image off emulation) ... probably not a genuine test for a11y.
  8. *
  9. * usage: on any dijit test_* page, press ctrl-f9 to popup links.
  10. *
  11. * there are currently (2 themes * 4 tests) * (10 variations of supported
  12. * browsers) not including testing individual locale-strings
  13. *
  14. * you should not be using this in a production enviroment. include your css and
  15. * set your classes manually. for test purposes only ...
  16. */
  17. (function() {
  18. var theme = false;
  19. var testMode;
  20. if (window.location.href.indexOf("?") > -1) {
  21. var str = window.location.href.substr(window.location.href.indexOf("?")
  22. + 1);
  23. var ary = str.split(/&/);
  24. for (var i = 0; i < ary.length; i++) {
  25. var split = ary[i].split(/=/), key = split[0], value = split[1];
  26. switch (key) {
  27. case "locale" :
  28. // locale string | null
  29. djConfig.locale = locale = value;
  30. break;
  31. case "dir" :
  32. // rtl | null
  33. document.getElementsByTagName("html")[0].dir = value;
  34. break;
  35. case "theme" :
  36. // tundra | soria | noir | squid | null
  37. theme = value;
  38. break;
  39. case "a11y" :
  40. if (value) {
  41. testMode = "dijit_a11y";
  42. }
  43. }
  44. }
  45. }
  46. // always include the default theme files:
  47. if (!theme) {
  48. theme = djConfig.defaultTestTheme || 'tundra';
  49. }
  50. var themeCss = dojo.moduleUrl("dijit.themes", theme + "/" + theme + ".css");
  51. var themeCssRtl = dojo.moduleUrl("dijit.themes", theme + "/" + theme
  52. + "_rtl.css");
  53. document.write('<link rel="stylesheet" type="text/css" href="' + themeCss
  54. + '"/>');
  55. document.write('<link rel="stylesheet" type="text/css" href="'
  56. + themeCssRtl + '"/>');
  57. if (djConfig.parseOnLoad) {
  58. djConfig.parseOnLoad = false;
  59. djConfig._deferParsing = true;
  60. }
  61. dojo.addOnLoad(function() {
  62. // set the classes
  63. if (!dojo.hasClass(dojo.body(), theme)) {
  64. dojo.addClass(dojo.body(), theme);
  65. }
  66. if (testMode) {
  67. dojo.addClass(dojo.body(), testMode);
  68. }
  69. // test-link matrix code:
  70. var node = document.createElement('div');
  71. node.id = "testNodeDialog";
  72. dojo.addClass(node, "dijitTestNodeDialog");
  73. dojo.body().appendChild(node);
  74. _populateTestDialog(node);
  75. dojo.connect(document, "onkeypress", "_testNodeShow");
  76. if (djConfig._deferParsing) {
  77. dojo.parser.parse(dojo.body());
  78. }
  79. });
  80. _testNodeShow = function(/* Event */evt) {
  81. var key = (evt.charCode == dojo.keys.SPACE
  82. ? dojo.keys.SPACE
  83. : evt.keyCode);
  84. if (evt.ctrlKey && (key == dojo.keys.F9)) { // F9 is generic enough?
  85. dojo.style(dojo.byId('testNodeDialog'), "top",
  86. (dijit.getViewport().t + 4) + "px");
  87. dojo.toggleClass(dojo.byId('testNodeDialog'),
  88. "dijitTestNodeShowing");
  89. }
  90. }
  91. _populateTestDialog = function(/* DomNode */node) {
  92. // pseudo-function to populate our test-martix-link pop-up
  93. var base = window.location.pathname;
  94. var str = "";
  95. var themes = ["tundra",/* "noir", */"soria" /* ,"squid" */];
  96. str += "<b>Tests:</b><br><table>";
  97. dojo.forEach(themes, function(t) {
  98. str += '<tr><td><a hr' + 'ef="' + base + '?theme=' + t
  99. + '">' + t + '</' + 'a></td>' + '<td><a hr'
  100. + 'ef="' + base + '?theme=' + t + '&dir=rtl">rtl</'
  101. + 'a></td>' + '<td><a hr' + 'ef="' + base
  102. + '?theme=' + t + '&a11y=true">a11y</' + 'a></td>'
  103. + '<td><a hr' + 'ef="' + base + '?theme=' + t
  104. + '&a11y=true&dir=rtl">a11y+rtl</' + 'a></td>' +
  105. // too many potential locales to list, use
  106. // &locale=[lang] to set
  107. '</tr>';
  108. });
  109. str += '<tr><td colspan="4">jump to: <a hr' + 'ef="'
  110. + (dojo.moduleUrl("dijit.themes", "themeTester.html"))
  111. + '">themeTester</' + 'a></td></tr>';
  112. str += '<tr><td colspan="4">or: <a hr' + 'ef="'
  113. + (dojo.moduleUrl("dijit.tests")) + '">tests folder</'
  114. + 'a></td></tr>';
  115. node.innerHTML = str + "</table>";
  116. }
  117. })();