DjConfig.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /****************************************************************
  2. ** IBM Confidential
  3. **
  4. ** OCO Source Materials
  5. **
  6. ** BI and PM: tm1web
  7. **
  8. ** (C) Copyright IBM Corp. 2010
  9. **
  10. ** The source code for this program is not published or otherwise
  11. ** divested of its trade secrets, irrespective of what has been
  12. ** deposited with the U.S. Copyright Office.
  13. *****************************************************************/
  14. // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  15. // This file is code that is meant to run BEFORE dojo is loaded and therefore
  16. // cannot depend on any dojo library objects, or use dojo to load other code.
  17. // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  18. var common = {DjConfig : {}};
  19. ;(function() {
  20. var DjConfig = common.DjConfig;
  21. DjConfig.setupPage = function() {
  22. // see if there's a debug=true arg in the URL
  23. var isDebug = isDebugUrl(document.location.href);
  24. // setup Dojo config object prior to loading dojo
  25. djConfig = {
  26. parseOnLoad:false,
  27. isDebug:isDebug,
  28. popup:isDebug,
  29. breakOnAssert:true,
  30. defaultDuration:100
  31. };
  32. };
  33. DjConfig.setDebugClickElement = function(dcElement) {
  34. dojo.connect(dcElement, "onclick", DjConfig, DjConfig.reloadPageInDebugMode);
  35. };
  36. DjConfig.reloadPageInDebugMode = function(event) {
  37. if (!(event.shiftKey && event.ctrlKey)) {
  38. return;
  39. }
  40. var curHref = document.location.href;
  41. var newHref = curHref;
  42. newHref = newHref.replace(/debug=(\w)*/,"");
  43. newHref = (newHref.indexOf("?") != -1) ? newHref : newHref + "?";
  44. newHref = newHref.replace(/\&\&/,"");
  45. document.location.href = newHref + "&debug=true";
  46. };
  47. DjConfig.setupPage();
  48. function isDebugUrl(urlText) {
  49. var debugValue = getQueryArgValue(document.location.href, "debug", false);
  50. var isDebug = debugValue != null && debugValue != "false" && debugValue != "0" && debugValue != false;
  51. return isDebug;
  52. }
  53. function getQueryArgValue(urlText, argName, defaultValue) {
  54. var urlParts = urlText.split("?");
  55. if (urlParts.length < 2) {
  56. return null;
  57. }
  58. var argArray = urlParts[1].split("&");
  59. var value = defaultValue;
  60. for (var i = 0; i < argArray.length; i++) {
  61. var arg = argArray[i];
  62. var argParts = arg.split("=");
  63. var name = argParts[0];
  64. if (name == argName) {
  65. if (argParts.length > 1) {
  66. value = argParts[1];
  67. } else {
  68. value = true;
  69. }
  70. break;
  71. }
  72. }
  73. return value;
  74. }
  75. }());