1 |
/** |
2 |
* Miscellaneous js functions for WebHelp |
3 |
* Kasun Gajasinghe, http://kasunbg.blogspot.com |
4 |
* David Cramer, http://www.thingbag.net |
5 |
* |
6 |
*/ |
7 |
|
8 |
$(document).ready(function() { |
9 |
// $("#showHideHighlight").button(); //add jquery button styling to 'Go' button |
10 |
//Generate tabs in nav-pane with JQuery |
11 |
$(function() { |
12 |
$("#tabs").tabs({ |
13 |
cookie: { |
14 |
// store cookie for 2 days. |
15 |
expires: 2 |
16 |
} |
17 |
}); |
18 |
}); |
19 |
|
20 |
//Generate the tree |
21 |
$("#ulTreeDiv").attr("style",""); |
22 |
$("#tree").treeview({ |
23 |
collapsed: true, |
24 |
animated: "medium", |
25 |
control: "#sidetreecontrol", |
26 |
persist: "cookie" |
27 |
}); |
28 |
|
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;"); |
32 |
|
33 |
//.searchButton is the css class applied to 'Go' button |
34 |
$(function() { |
35 |
$("button", ".searchButton").button(); |
36 |
|
37 |
$("button", ".searchButton").click(function() {return false;}); |
38 |
}); |
39 |
|
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"); |
47 |
} |
48 |
} |
49 |
|
50 |
syncToc(); //Synchronize the toc tree with the content pane, when loading the page. |
51 |
//$("#doSearch").button(); //add jquery button styling to 'Go' button |
52 |
}); |
53 |
|
54 |
/** |
55 |
* Synchronize with the tableOfContents |
56 |
*/ |
57 |
function syncToc(){ |
58 |
var a = document.getElementById("webhelp-currentid"); |
59 |
if (a != undefined) { |
60 |
var b = a.getElementsByTagName("span")[0]; |
61 |
|
62 |
|
63 |
if (b != undefined) { |
64 |
//Setting the background for selected node. |
65 |
//b.setAttribute("style", "color: white; background-color: #a7a9ac;"); |
66 |
b.style.color = "#FFFFFF"; |
67 |
b.style.backgroundColor = "#a7a9ac"; |
68 |
} |
69 |
|
70 |
//shows the node related to current content. |
71 |
//goes a recursive call from current node to ancestor nodes, displaying all of them. |
72 |
while (a.parentNode && a.parentNode.nodeName) { |
73 |
var parentNode = a.parentNode; |
74 |
var nodeName = parentNode.nodeName; |
75 |
|
76 |
if (nodeName.toLowerCase() == "ul") { |
77 |
parentNode.style.display = "block"; |
78 |
|
79 |
// Expand the current entry |
80 |
var u = a.getElementsByTagName("ul")[0]; |
81 |
if (u) { |
82 |
u.style.display = "block"; |
83 |
} |
84 |
} else if (nodeName.toLocaleLowerCase() == "li") { |
85 |
parentNode.setAttribute("class", "collapsable"); |
86 |
parentNode.firstChild.setAttribute("class", "hitarea collapsable-hitarea "); |
87 |
} |
88 |
a = parentNode; |
89 |
} |
90 |
|
91 |
if (b != undefined) { |
92 |
b.scrollIntoView(); |
93 |
} |
94 |
} |
95 |
} |
96 |
|
97 |
/** |
98 |
* Code for Show/Hide TOC |
99 |
* |
100 |
*/ |
101 |
function showHideToc() { |
102 |
var showHideButton = $("#showHideButton"); |
103 |
var leftNavigation = $("#leftnavigation"); |
104 |
var content = $("#content"); |
105 |
|
106 |
if (showHideButton != undefined && showHideButton.hasClass("pointLeft")) { |
107 |
//Hide TOC |
108 |
showHideButton.removeClass('pointLeft').addClass('pointRight'); |
109 |
content.css("margin", "0 0 0 0"); |
110 |
leftNavigation.css("display","none"); |
111 |
showHideButton.attr("title", "Show table of contents"); |
112 |
} else { |
113 |
//Show the TOC |
114 |
showHideButton.removeClass('pointRight').addClass('pointLeft'); |
115 |
content.css("margin", "0 0 0 315px"); |
116 |
leftNavigation.css("display","block"); |
117 |
showHideButton.attr("title", "Hide table of contents"); |
118 |
} |
119 |
} |
120 |
|
121 |
/** |
122 |
* Code for searh highlighting |
123 |
*/ |
124 |
var highlightOn = true; |
125 |
function searchHighlight(searchText) { |
126 |
highlightOn = true; |
127 |
if (searchText != undefined) { |
128 |
var wList; |
129 |
var sList = new Array(); //stem list |
130 |
//Highlight the search terms |
131 |
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_") |
132 |
searchText = searchText.replace(/ +/g, " "); |
133 |
searchText = searchText.replace(/ $/, "").replace(/^ /, ""); |
134 |
|
135 |
wList = searchText.split(" "); |
136 |
$("#content").highlight(wList); //Highlight the search input |
137 |
|
138 |
if(typeof stemmer != "undefined" ){ |
139 |
//Highlight the stems |
140 |
for (var i = 0; i < wList.length; i++) { |
141 |
var stemW = stemmer(wList[i]); |
142 |
sList.push(stemW); |
143 |
} |
144 |
} else { |
145 |
sList = wList; |
146 |
} |
147 |
$("#content").highlight(sList); //Highlight the search input's all stems |
148 |
|
149 |
var _content = document.getElementById("content"); |
150 |
var spans = _content.getElementsByTagName("span"); |
151 |
var hasOne = false; |
152 |
for (i = 0; i < spans.length; i++) { |
153 |
var span = spans[i]; |
154 |
if (span.className == "highlight") { |
155 |
span.setAttribute("id", "firstHighlight"); |
156 |
hasOne = true; |
157 |
break; |
158 |
} |
159 |
} |
160 |
if (hasOne) { |
161 |
document.getElementById("firstHighlight").scrollIntoView(); |
162 |
} |
163 |
} |
164 |
} |
165 |
|
166 |
function searchUnhighlight(){ |
167 |
highlightOn = false; |
168 |
//unhighlight the search input's all stems |
169 |
$("#content").unhighlight(); |
170 |
$("#content").unhighlight(); |
171 |
} |
172 |
|
173 |
function toggleHighlight(){ |
174 |
if(highlightOn) { |
175 |
searchUnhighlight(); |
176 |
} else { |
177 |
searchHighlight($.cookie('textToSearch')); |
178 |
} |
179 |
} |