/*----------------------------------------------------------------------------\r
- * NexWave javascript for NSI search\r
+ * JavaScript for webhelp search\r
*----------------------------------------------------------------------------\r
- This file is part of the htmlsearch plugin for the DITA-OT\r
- adapted for NSI documentation.\r
+ This file is part of the webhelpsearch plugin for DocBook WebHelp\r
Copyright (c) 2007-2008 NexWave Solutions All Rights Reserved.\r
www.nexwave.biz Nadege Quaine\r
+ http://kasunbg.blogspot.com/ Kasun Gajasinghe\r
*/\r
\r
//string initialization\r
}\r
\r
\r
- expressionInput = document.ditaSearch_Form.textToSearch.value\r
+ var expressionInput = document.ditaSearch_Form.textToSearch.value;\r
//Set a cookie to store the searched keywords\r
$.cookie('textToSearch', expressionInput);\r
\r
\r
if (expressionInput.length < 1) {\r
\r
- // expression invalide (vide)\r
+ // expression is invalid\r
alert(txt_enter_at_least_1_char);\r
// reactive la fenetre de search (utile car cadres)\r
document.ditaSearch_Form.textToSearch.focus();\r
//DisplayWaitingMessage();\r
\r
/*data initialisation*/\r
- searchFor = ""; // expression en lowercase et sans les caracte res speciaux\r
+ var searchFor = ""; // expression en lowercase et sans les caracte res speciaux\r
//w = new Object(); // hashtable, key=word, value = list of the index of the html files\r
- scriptLetterTab = new scriptfirstchar(); // Array containing the first letter of each word to look for\r
- var scriptsarray = new Array(); // Array with the name of the scripts to load\r
+ scriptLetterTab = new Scriptfirstchar(); // Array containing the first letter of each word to look for\r
var wordsList = new Array(); // Array with the words to look for\r
var finalWordsList = new Array(); // Array with the words to look for after removing spaces\r
- var listNumerosDesFicStr = "";\r
- var ou_recherche = true;\r
var linkTab = new Array();\r
- var et_recherche = false;\r
var fileAndWordList = new Array();\r
var txt_wordsnotfound = "";\r
\r
\r
/*nqu: expressionInput, la recherche est lower cased, plus remplacement des char speciaux*/\r
- searchFor = expressionInput.toLowerCase().replace(/<\//g, "_st_").replace(/\$_/g, "_di_").replace(/\.|%2C|%3B|%21|%3A|@|\/|\*/g, " ").replace(/(%20)+/g, " ").replace(/_st_/g, "</").replace(/_di_/g, "%24_")\r
+ searchFor = expressionInput.toLowerCase().replace(/<\//g, "_st_").replace(/\$_/g, "_di_").replace(/\.|%2C|%3B|%21|%3A|@|\/|\*/g, " ").replace(/(%20)+/g, " ").replace(/_st_/g, "</").replace(/_di_/g, "%24_");\r
\r
searchFor = searchFor.replace(/ +/g, " ");\r
searchFor = searchFor.replace(/ $/, "").replace(/^ /, "");\r
* Compare with the indexed words (in the w[] array), and push words that are in it to tempTab.\r
*/\r
var tempTab = new Array();\r
- for (t in finalWordsList) {\r
+ for (var t in finalWordsList) {\r
if (w[finalWordsList[t].toString()] == undefined) {\r
txt_wordsnotfound += finalWordsList[t] + " ";\r
} else {\r
//search 'and' and 'or' one time\r
fileAndWordList = SortResults(finalWordsList);\r
\r
- cpt = fileAndWordList.length;\r
+ var cpt = fileAndWordList.length;\r
for (var i = cpt - 1; i >= 0; i--) {\r
if (fileAndWordList[i] != undefined) {\r
linkTab.push("<p>" + txt_results_for + " " + "<span class=\"searchExpression\">" + fileAndWordList[i][0].motslisteDisplay + "</span>" + "</p>");\r
for (t in fileAndWordList[i]) {\r
//DEBUG: alert(": "+ fileAndWordList[i][t].filenb+" " +fileAndWordList[i][t].motsliste);\r
//linkTab.push("<li><a href=\"../"+fl[fileAndWordList[i][t].filenb]+"\">"+fl[fileAndWordList[i][t].filenb]+"</a></li>");\r
- tempInfo = fil[fileAndWordList[i][t].filenb];\r
- pos1 = tempInfo.indexOf("@@@");\r
- pos2 = tempInfo.lastIndexOf("@@@");\r
- tempPath = tempInfo.substring(0, pos1);\r
- tempTitle = tempInfo.substring(pos1 + 3, pos2);\r
- tempShortdesc = tempInfo.substring(pos2 + 3, tempInfo.length);\r
+ var tempInfo = fil[fileAndWordList[i][t].filenb];\r
+ var pos1 = tempInfo.indexOf("@@@");\r
+ var pos2 = tempInfo.lastIndexOf("@@@");\r
+ var tempPath = tempInfo.substring(0, pos1);\r
+ var tempTitle = tempInfo.substring(pos1 + 3, pos2);\r
+ var tempShortdesc = tempInfo.substring(pos2 + 3, tempInfo.length);\r
\r
//file:///home/kasun/docbook/WEBHELP/webhelp-draft-output-format-idea/src/main/resources/web/webhelp/installation.html\r
var linkString = "<li><a href=" + tempPath + ">" + tempTitle + "</a>";\r
}\r
} \r
//stemmedWordsList is the stemmed list of words separated by spaces.\r
- for (t in wordsList) {\r
- wordsList[t] = wordsList[t].replace(/(%22)|^-/g, "")\r
+ for (var t in wordsList) {\r
+ wordsList[t] = wordsList[t].replace(/(%22)|^-/g, "");\r
if (wordsList[t] != "%20") {\r
scriptLetterTab.add(wordsList[t].charAt(0));\r
cleanwordsList.push(wordsList[t]);\r
return stemmedWordsList;\r
}\r
\r
+//Invoker of CJKTokenizer class methods.\r
function cjkTokenize(wordsList){\r
var allTokens= new Array();\r
var notCJKTokens= new Array();\r
function getAvgAsciiValue(word){\r
var tmp = 0;\r
var num = word.length < 5 ? word.length:5;\r
- for(i=0;i<num;i++){\r
+ for(var i=0;i<num;i++){\r
if(i==5) break;\r
tmp += word.charCodeAt(i);\r
}\r
var tmp = this.tokenize();\r
this.tokens.push(tmp);\r
}\r
- var sortedTokens = this.unique(this.tokens);\r
-\r
- return sortedTokens; \r
+ return this.unique(this.tokens);\r
// document.getElementById("content").innerHTML += tokens+" ";\r
// document.getElementById("content").innerHTML += "<br>dada"+sortedTokens+" ";\r
// console.log(tokens.length+"dsdsds");\r
}\r
\r
\r
-/* scriptfirstchar: to gather the first letter of index js files to upload */\r
-function scriptfirstchar() {\r
+/* Scriptfirstchar: to gather the first letter of index js files to upload */\r
+function Scriptfirstchar() {\r
this.strLetters = "";\r
this.add = addLettre;\r
}\r
function loadTheIndexScripts(tab) {\r
\r
//alert (tab.strLetters);\r
- scriptsarray = new Array();\r
+ var scriptsarray = new Array();\r
\r
- for (i = 0; i < tab.strLetters.length; i++) {\r
+ for (var i = 0; i < tab.strLetters.length; i++) {\r
\r
scriptsarray[i] = "..\/search" + "\/" + tab.strLetters.charAt(i) + ".js";\r
}\r
scriptsarray[i] = "..\/search" + "\/" + htmlfileList;\r
\r
//debug\r
- for (t in scriptsarray) {\r
+ for (var t in scriptsarray) {\r
//alert (scriptsarray[t]);\r
}\r
\r
- tab = new scriptLoader();\r
+ tab = new ScriptLoader();\r
for (t in scriptsarray) {\r
tab.add(scriptsarray[t]);\r
}\r
return (scriptsarray);\r
}\r
\r
-/* scriptloader: to load the scripts and wait that it's finished */\r
-function scriptLoader(aScriptList) {\r
+/* ScriptLoader: to load the scripts and wait that it's finished */\r
+function ScriptLoader() {\r
this.cpt = 0;\r
this.scriptTab = new Array();\r
this.add = addAScriptInTheList;\r
\r
//script = document.createElement('script');\r
\r
- for (el in this.scriptTab) {\r
+ for (var el in this.scriptTab) {\r
//alert (el+this.scriptTab[el]);\r
script = document.createElement('script');\r
script.src = this.scriptTab[el];\r
} */\r
\r
/* End of scriptloader functions */\r
-\r
-/* Array functions */\r
-/*function unique (tab){\r
- for(var y=0;y<tab.length;++y){\r
- for(var z=(y+1);z<=tab.length;++z){\r
- if(tab[y]==tab[z]){\r
- tab.splice(z,1)\r
- }\r
- }\r
- }\r
- return tab;\r
- } */\r
+ \r
// Array.unique( strict ) - Remove duplicate values\r
function unique(tab) {\r
var a = new Array();\r
}\r
return a;\r
}\r
-;\r
-\r
-\r
function indexof(tab, element, begin) {\r
- for (i = begin; i < tab.length; i++) {\r
+ for (var i = begin; i < tab.length; i++) {\r
if (tab[i] == element) {\r
return i;\r
}\r
function SortResults(mots) {\r
\r
var fileAndWordList = new Object();\r
- var fileAndWordList2 = new Object();\r
-\r
if (mots.length == 0) {\r
return null;\r
}\r
\r
- for (t in mots) {\r
+ for (var t in mots) {\r
// get the list of the indices of the files.\r
- listNumerosDesFicStr = w[mots[t].toString()];\r
+ var listNumerosDesFicStr = w[mots[t].toString()];\r
//alert ("listNumerosDesFicStr "+listNumerosDesFicStr);\r
- tab = listNumerosDesFicStr.split(",");\r
+ var tab = listNumerosDesFicStr.split(",");\r
\r
//for each file (file's index):\r
- for (t2 in tab) {\r
- temp = tab[t2].toString();\r
+ for (var t2 in tab) {\r
+ var temp = tab[t2].toString();\r
if (fileAndWordList[temp] == undefined) {\r
\r
fileAndWordList[temp] = "" + mots[t];\r
}\r
}\r
\r
- fileAndWordListValuesOnly = new Array();\r
+ var fileAndWordListValuesOnly = new Array();\r
\r
// sort results according to values\r
var temptab = new Array();\r
\r
var listToOutput = new Array();\r
\r
- for (j in fileAndWordListValuesOnly) {\r
+ for (var j in fileAndWordListValuesOnly) {\r
for (t in temptab) {\r
if (temptab[t].motsliste == fileAndWordListValuesOnly[j]) {\r
if (listToOutput[j] == undefined) {\r
} else {\r
listToOutput[j].push(temptab[t]);\r
}\r
-\r
}\r
}\r
}\r
-\r
return listToOutput;\r
}\r
\r
return -1;\r
}\r
//return t1.length - t2.length);\r
-}\r
-/* User interfaces functions */\r
-function DisplayWaitingMessage() {\r
-\r
- with (parent.frames['searchresults'].document) {\r
- writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html><head>");\r
- writeln("<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />");\r
- //writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/commonltr.css\">") ;\r
- //writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/search.css\">");\r
- writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"common/tabs.css\">");\r
- writeln("<title>" + txt_please_wait + "</title></head>");\r
- writeln("<body onload = \"self.focus()\">");\r
- writeln("<h2>" + txt_please_wait + "</h2></body></html>");\r
- close();\r
- }\r
-\r
-}\r
+}
\ No newline at end of file