]> granicus.if.org Git - docbook-dsssl/commitdiff
Clean up of the search js code and some small modifications.
authorKasun Gajasinghe <kasunbg@gmail.com>
Sat, 14 Aug 2010 11:10:15 +0000 (11:10 +0000)
committerKasun Gajasinghe <kasunbg@gmail.com>
Sat, 14 Aug 2010 11:10:15 +0000 (11:10 +0000)
xsl/webhelp/template/common/main.js
xsl/webhelp/template/content/search/nwSearchFnt.js

index c38951d4cb2b0ecdb5ded30dd6ba7c75197e9fc8..246ecde30131e3fee8ed378f7b7b4f8e878682db 100755 (executable)
@@ -1,7 +1,7 @@
 /**
- * main.js
- *
- * Developed by: Kasun Gajasinghe, David Cramer
+ * Miscellaneous js functions for WebHelp
+ * Kasun Gajasinghe, http://kasunbg.blogspot.com
+ * David Cramer, http://www.thingbag.net
  *
  */
 
index f34ffcf3d4737a4ff8ad342c780f9f485143ffd7..0111559cc50d6b0168ab34a3cdbc7aa959a87c91 100755 (executable)
@@ -1,10 +1,10 @@
 /*----------------------------------------------------------------------------\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
@@ -23,14 +23,14 @@ function Verifie(ditaSearch_Form) {
     }\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
@@ -54,22 +54,18 @@ function Effectuer_recherche(expressionInput) {
     //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
@@ -100,7 +96,7 @@ function Effectuer_recherche(expressionInput) {
      * 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
@@ -114,7 +110,7 @@ function Effectuer_recherche(expressionInput) {
         //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
@@ -123,12 +119,12 @@ function Effectuer_recherche(expressionInput) {
                 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
@@ -172,8 +168,8 @@ function tokenize(wordsList){
         }\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
@@ -192,6 +188,7 @@ function tokenize(wordsList){
     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
@@ -214,7 +211,7 @@ function cjkTokenize(wordsList){
 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
@@ -252,9 +249,7 @@ function CJKTokenizer(input){
                        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
@@ -283,8 +278,8 @@ function CJKTokenizer(input){
 }\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
@@ -306,9 +301,9 @@ function addLettre(caract) {
 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
@@ -317,11 +312,11 @@ function loadTheIndexScripts(tab) {
     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
@@ -330,8 +325,8 @@ function loadTheIndexScripts(tab) {
     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
@@ -351,7 +346,7 @@ function loadTheScripts() {
 \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
@@ -385,18 +380,7 @@ function onLoadComplete() {
 } */\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
@@ -417,11 +401,8 @@ function unique(tab) {
     }\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
@@ -443,21 +424,19 @@ function indexof(tab, element, begin) {
 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
@@ -468,7 +447,7 @@ function SortResults(mots) {
         }\r
     }\r
 \r
-    fileAndWordListValuesOnly = new Array();\r
+    var fileAndWordListValuesOnly = new Array();\r
 \r
     // sort results according to values\r
     var temptab = new Array();\r
@@ -498,7 +477,7 @@ function SortResults(mots) {
 \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
@@ -506,11 +485,9 @@ function SortResults(mots) {
                 } else {\r
                     listToOutput[j].push(temptab[t]);\r
                 }\r
-\r
             }\r
         }\r
     }\r
-\r
     return listToOutput;\r
 }\r
 \r
@@ -533,20 +510,4 @@ function compare_nbMots(s1, s2) {
         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