webhelp.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. var tree = "tree";
  2. /**
  3. * Marks a link as being selected.
  4. *
  5. * @param parentID the ID of the LI containing the link.
  6. */
  7. function selectLink(parentID){
  8. // Clear all the classes from the a elements, and selects the target.
  9. var aElements = parent.tocwin.document.getElementById(tree).getElementsByTagName("a");
  10. var j = 0;
  11. for (j = 0; j < aElements.length; j++){
  12. if(aElements[j].parentNode.id == parentID){
  13. // Selected.
  14. aElements[j].className='selected';
  15. } else {
  16. // Unselected.
  17. aElements[j].className='';
  18. }
  19. }
  20. }
  21. /**
  22. * Expands and selects a specified topic.
  23. *
  24. * @param referringTopicURL The URL of the referring topic, as string.
  25. * @param href The relative location of the target.
  26. */
  27. function expandToTopic(referringTopicURL, href) {
  28. var targetAbsoluteURL = makeAbsolute(href);
  29. var targetAbsoluteURLArray = new Array();
  30. var target;
  31. targetAbsoluteURLArray = targetAbsoluteURL.split("#");
  32. target = targetAbsoluteURLArray[0].replace("../", "");
  33. var idsToExpand = findIds(target);
  34. var toc = parent.tocwin.document;
  35. $(function(){
  36. if (idsToExpand != ''){
  37. $("#tree").dynatree("getTree").getNodeByKey(idsToExpand).focus();
  38. }
  39. });
  40. }
  41. function getParent(url){
  42. var str = "" + url;
  43. // Removes the last component from the path.
  44. url = url.substring(0, url.lastIndexOf('/'));
  45. return url;
  46. }
  47. /*
  48. Finds all ids of parent elements of "a"'s having their hrefs ending in the target.
  49. */
  50. function findIds(targetAbsoluteURL) {
  51. var returnedArray = new Array();
  52. var windowLocation = getParent(parent.tocwin.location.href);
  53. var toc = parent.tocwin.document.getElementById('tree');
  54. var aElements = toc.getElementsByTagName("a");
  55. var nr = aElements.length;
  56. var k = 0;
  57. for (var i = 0; i < nr; i++) {
  58. var linkURL = makeAbsolute(windowLocation + '/' + aElements[i].getAttribute("href"));
  59. if (linkURL.match(targetAbsoluteURL)) {
  60. returnedArray[k] = aElements[i].id;
  61. k++;
  62. }
  63. }
  64. return returnedArray;
  65. }
  66. /**
  67. * Makes absolute the input URL by stripping the .. constructs.
  68. */
  69. function makeAbsolute(inputURL) {
  70. var url = inputURL;
  71. // matches a foo/../ expression
  72. var reParent = /[\-\w]+\/\.\.\//;
  73. // reduce all 'xyz/../' to just ''
  74. while (reParent.test(url)) {
  75. url = url.replace(reParent, "");
  76. }
  77. return url;
  78. }
  79. /**
  80. * Opens a page (topic) file and highlights a word from it.
  81. */
  82. function openAndHighlight(page, words, linkName){
  83. var links = document.getElementsByTagName('a');
  84. for (var i = 0 ; i < links.length ; i++){
  85. if (links[i].id == linkName ){
  86. document.getElementById(linkName).className = 'otherLink';
  87. } else if (links[i].id.startsWith('foundLink')) {
  88. document.getElementById(links[i].id).className = 'foundResult';
  89. }
  90. }
  91. parent.termsToHighlight = words;
  92. parent.frames['contentwin'].location = page;
  93. }
  94. /**
  95. * Hide and show div-s
  96. */
  97. function showMenu(displayTab){
  98. parent.termsToHighlight = Array();
  99. var contentLinkText = getLocalization("Content");
  100. var searchLinkText = getLocalization("Search");
  101. var indexLinkText = getLocalization("Index");
  102. var tabs = document.getElementById('tocMenu').getElementsByTagName("div");
  103. for (var i = 0 ; i < tabs.length; i++){
  104. var currentTabId = tabs[i].id;
  105. // generates menu tabs
  106. document.getElementById(currentTabId).innerHTML = '<span onclick="showMenu(\'' + currentTabId + '\')">' + eval(currentTabId + "LinkText") + '</span>';
  107. // show selected block
  108. selectedBlock = displayTab + "Block";
  109. if (currentTabId == displayTab){
  110. document.getElementById(selectedBlock).style.display = "block";
  111. $('#' + currentTabId).addClass('selected');
  112. } else {
  113. document.getElementById(currentTabId + 'Block').style.display = "none";
  114. $('#' + currentTabId).removeClass('selected');
  115. }
  116. }
  117. if (displayTab == 'content') {
  118. var pathPrefix = parent.location.pathname;
  119. var expandPage = getHTMLPage2Expand(parent.contentwin.location.pathname);
  120. if(expandPage){
  121. expandPage = expandPage.replace(pathPrefix, "");
  122. expandToTopic(window.location.href, expandPage);
  123. }
  124. }
  125. if (displayTab == 'search') {
  126. $('.textToSearch').focus();
  127. }
  128. if (displayTab == 'index') {
  129. $('#id_search').focus();
  130. }
  131. // $('*', window.parent.contentwin.document).unhighlight();
  132. }
  133. function hideDiv(hiddenDiv,showedDiv){
  134. parent.termsToHighlight = Array();
  135. document.getElementById(hiddenDiv).style.display = "none";
  136. document.getElementById(showedDiv).style.display = "block";
  137. var contentLinkText = getLocalization("Content");
  138. var searchLinkText = getLocalization("Search");
  139. if (hiddenDiv == 'searchDiv') {
  140. document.getElementById('divContent').innerHTML = '<font class="normalLink">' + contentLinkText + '</font>';
  141. document.getElementById('divSearch').innerHTML = '<a href="javascript:void(0);" class="activeLink" id="searchLink" onclick="hideDiv(\'displayContentDiv\',\'searchDiv\')">' + searchLinkText + '</a>';
  142. var pathPrefix = parent.location.pathname;
  143. var expandPage = getHTMLPage2Expand(parent.contentwin.location.pathname);
  144. expandPage = expandPage.replace(pathPrefix, "");
  145. expandToTopic(window.location.href, expandPage);
  146. } else {
  147. document.getElementById('divContent').innerHTML = '<a href="javascript:void(0);" class="activeLink" id="contentLink" onclick="hideDiv(\'searchDiv\',\'displayContentDiv\')">' + contentLinkText + '</a>';
  148. document.getElementById('divSearch').innerHTML = '<font class="normalLink">' + searchLinkText + '</font>';
  149. }
  150. // $('*', window.parent.contentwin.document).unhighlight();
  151. }
  152. /**
  153. * Get the localized string for the specified key.
  154. */
  155. function getLocalization(localizationKey) {
  156. if (localization[localizationKey]){
  157. return localization[localizationKey];
  158. }else{
  159. return localizationKey;
  160. }
  161. }
  162. function getHTMLPage2Expand(url){
  163. currentPage =url;
  164. if(typeof url != 'undefined'){
  165. var page = url.substr(1);
  166. //var page = url;
  167. currentPage = page;
  168. page = parent.location.search.substr(1).split("&");
  169. for (x in page) {
  170. var q;
  171. q = page[x].split("=");;
  172. if(q[0] == 'q'){
  173. currentPage = q[1];
  174. }
  175. }
  176. }
  177. return currentPage;
  178. }