init.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. © Copyright IBM Corp. 1999, 2013.
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. function encodeJS(str) {
  8. var out = '';
  9. for(var i=0; i<str.length; i++) {
  10. var ch = str.charAt(i);
  11. if(ch === '<') {
  12. out += '\\x3c';
  13. } else if(ch === '>') {
  14. out += '\\x3e';
  15. } else if(ch === "'") {
  16. out += '\\x27';
  17. } else if(ch === '"') {
  18. out += '\\x22';
  19. } else if(ch === '\\') {
  20. out += '\\x5c';
  21. } else {
  22. out += ch;
  23. }
  24. }
  25. return out;
  26. }
  27. function init(newVersion)
  28. {
  29. var query = parseHash(window.location.href); // read URL for topic/section info
  30. var sCurrentTopic = "";
  31. var sDirTopics = "";
  32. var sHelpIDtopic = "";
  33. // determine current helpID topic reference, and use over any other info
  34. if( query['helpid'] && (query['helpid'] != "") ) {
  35. // determine which file the helpid/topicalias is in
  36. sHelpIDtopic = checkHelpID(query['helpid']);
  37. sCurrentTopic = (sHelpIDtopic && (sHelpIDtopic!= "")) ? (sHelpIDtopic) : welcomeTopic; // welcomeTopic globally defined variable
  38. sCurrentTopic += (query['helpid'] && (query['helpid'] != "")) ? ("#" + query['helpid']) : "";
  39. }
  40. else {
  41. // determine current topic and section html info
  42. sCurrentTopic = (query['topic'] && (query['topic'] != "")) ? (query['topic'] + ".html") : welcomeTopic; // welcomeTopic globally defined variable
  43. sCurrentTopic += (query['section'] && (query['section'] != "")) ? ("#" + query['section']) : "";
  44. }
  45. // determine full path to html
  46. var sDirString = window.location.href.substring(0, window.location.href.indexOf('?') );
  47. var nPos = sDirString.lastIndexOf('/');
  48. sDirTopics = (nPos != -1) ? window.location.href.substring(0, nPos + 1) : "";
  49. sCurrentTopic = sDirTopics + sCurrentTopic;
  50. sCurrentTopic = encodeJS(sCurrentTopic);
  51. sTabs = sDirTopics + sTabs; // sTabs globally defined variable
  52. //commenting out the two lines below because of a change needed to allow our files to work properly in a secure environment
  53. if (!newVersion) {
  54. window.tab.location.href = sTabs;
  55. window.content.location.href = sCurrentTopic;
  56. }
  57. else {
  58. //return the result of the topic that was found so that the frame src attribute can be populated in the <bookname>.html and <bookname>_a.html files
  59. //sTabs has already been determined by the server and the variable in the template file replaced with the appropriate value for that book.
  60. return sCurrentTopic;
  61. }
  62. }
  63. function parseHash(s)
  64. {
  65. var query = new Array();
  66. var nPos = s.indexOf("?");
  67. if (nPos != -1)
  68. {
  69. s = s.substring(nPos + 1, s.length);
  70. var sPair = "";
  71. while (s != "")
  72. {
  73. nPos = s.indexOf("&");
  74. if (nPos == -1) { sPair = s; s = ""; }
  75. else { sPair = s.substring(0, nPos); s = s.substring(nPos + 1, s.length); }
  76. nPos = sPair.indexOf("=");
  77. if (nPos != -1) query[sPair.substring(0, nPos)] = unescape(sPair.substring(nPos + 1, sPair.length));
  78. }
  79. }
  80. return query;
  81. }