2 * Miscellaneous js functions for WebHelp
3 * Kasun Gajasinghe, http://kasunbg.blogspot.com
4 * David Cramer, http://www.thingbag.net
8 $(document).ready(function() {
9 // $("#showHideHighlight").button(); //add jquery button styling to 'Go' button
10 //Generate tabs in nav-pane with JQuery
14 // store cookie for 2 days.
21 $("#ulTreeDiv").attr("style","");
25 control: "#sidetreecontrol",
29 //after toc fully styled, display it. Until loading, a 'loading' image will be displayed
30 $("#tocLoading").attr("style","display:none;");
31 // $("#ulTreeDiv").attr("style","display:block;");
33 //.searchButton is the css class applied to 'Go' button
35 $("button", ".searchButton").button();
37 $("button", ".searchButton").click(function() { return false; });
40 //'ui-tabs-1' is the cookie name which is used for the persistence of the tabs.(Content/Search tab)
41 if ($.cookie('ui-tabs-1') === '1') { //search tab is visible
42 if ($.cookie('textToSearch') != undefined && $.cookie('textToSearch').length > 0) {
43 document.getElementById('textToSearch').value = $.cookie('textToSearch');
44 Verifie('diaSearch_Form');
45 searchHighlight($.cookie('textToSearch'));
46 $("#showHideHighlight").css("display","block");
50 syncToc(); //Synchronize the toc tree with the content pane, when loading the page.
51 //$("#doSearch").button(); //add jquery button styling to 'Go' button
55 * Synchronize with the tableOfContents
58 var a = document.getElementById("webhelp-currentid");
60 var b = a.getElementsByTagName("a")[0];
63 //Setting the background for selected node.
64 var style = a.getAttribute("style");
65 if (style != null && !style.match(/background-color: Background;/)) {
66 a.setAttribute("style", "background-color: #6495ed; " + style);
67 b.setAttribute("style", "color: white;");
68 } else if (style != null) {
69 a.setAttribute("style", "background-color: #6495ed; " + style);
70 b.setAttribute("style", "color: white;");
72 a.setAttribute("style", "background-color: #6495ed; ");
73 b.setAttribute("style", "color: white;");
77 //shows the node related to current content.
78 //goes a recursive call from current node to ancestor nodes, displaying all of them.
79 while (a.parentNode && a.parentNode.nodeName) {
80 var parentNode = a.parentNode;
81 var nodeName = parentNode.nodeName;
83 if (nodeName.toLowerCase() == "ul") {
84 parentNode.setAttribute("style", "display: block;");
85 } else if (nodeName.toLocaleLowerCase() == "li") {
86 parentNode.setAttribute("class", "collapsable");
87 parentNode.firstChild.setAttribute("class", "hitarea collapsable-hitarea ");
95 * Code for Show/Hide TOC
98 function showHideToc() {
99 var showHideButton = $("#showHideButton");
100 var leftNavigation = $("#leftnavigation");
101 var content = $("#content");
103 if (showHideButton != undefined && showHideButton.hasClass("pointLeft")) {
105 showHideButton.removeClass('pointLeft').addClass('pointRight');
106 content.css("margin", "0 0 0 0");
107 leftNavigation.css("display","none");
108 showHideButton.attr("title", "Show the TOC tree");
111 showHideButton.removeClass('pointRight').addClass('pointLeft');
112 content.css("margin", "0 0 0 280px");
113 leftNavigation.css("display","block");
114 showHideButton.attr("title", "Hide the TOC Tree");
119 * Code for searh highlighting
121 var highlightOn = true;
122 function searchHighlight(searchText) {
124 if (searchText != undefined) {
126 var sList = new Array(); //stem list
127 //Highlight the search terms
128 searchText = searchText.toLowerCase().replace(/<\//g, "_st_").replace(/\$_/g, "_di_").replace(/\.|%2C|%3B|%21|%3A|@|\/|\*/g, " ").replace(/(%20)+/g, " ").replace(/_st_/g, "</").replace(/_di_/g, "%24_")
129 searchText = searchText.replace(/ +/g, " ");
130 searchText = searchText.replace(/ $/, "").replace(/^ /, "");
132 wList = searchText.split(" ");
133 $("#content").highlight(wList); //Highlight the search input
135 if(typeof stemmer != "undefined" ){
136 //Highlight the stems
137 for (var i = 0; i < wList.length; i++) {
138 var stemW = stemmer(wList[i]);
144 $("#content").highlight(sList); //Highlight the search input's all stems
148 function searchUnhighlight(){
150 //unhighlight the search input's all stems
151 $("#content").unhighlight();
152 $("#content").unhighlight();
155 function toggleHighlight(){
159 searchHighlight($.cookie('textToSearch'));