diff options
Diffstat (limited to 'src/search_js.h')
-rw-r--r-- | src/search_js.h | 352 |
1 files changed, 302 insertions, 50 deletions
diff --git a/src/search_js.h b/src/search_js.h index 7a401e6..d7b2a75 100644 --- a/src/search_js.h +++ b/src/search_js.h @@ -69,7 +69,7 @@ " this.lastSearchValue = \"\";\n" " this.lastResultsPage = \"\";\n" " this.hideTimeout = 0;\n" -" this.searchTopic = \"all\";\n" +" this.searchIndex = 0;\n" " this.searchActive = false;\n" " this.insideFrame = inFrame;\n" "\n" @@ -90,8 +90,8 @@ " this.DOMPopupSearchResultsWindow = function()\n" " { return document.getElementById(\"MSearchResultsWindow\"); }\n" "\n" -" this.DOMSearchResultWindowClose = function()\n" -" { return document.getElementById(\"MSearchResultsWindowClose\"); }\n" +" this.DOMSearchClose = function()\n" +" { return document.getElementById(\"MSearchClose\"); }\n" "\n" " this.DOMSearchBox = function()\n" " { return document.getElementById(\"MSearchBox\"); }\n" @@ -150,7 +150,7 @@ " }\n" "\n" " // Called when the content of the search field is changed.\n" -" this.OnSearchFieldChange = function()\n" +" this.OnSearchFieldChange = function(evt)\n" " {\n" " if (this.keyTimeout) // kill running timer\n" " {\n" @@ -158,6 +158,40 @@ " this.keyTimeout = 0;\n" " }\n" "\n" +" var e = (evt) ? evt : window.event; // for IE\n" +" if (e.keyCode==40 || e.keyCode==13)\n" +" {\n" +" if (e.shiftKey==1)\n" +" {\n" +" this.OnSearchSelectShow();\n" +" var win=this.DOMSearchSelectWindow(); \n" +" for (i=0;i<win.childNodes.length;i++)\n" +" {\n" +" var child = win.childNodes[i]; // get span within a\n" +" if (child.className=='SelectItem')\n" +" {\n" +" child.focus();\n" +" return;\n" +" }\n" +" }\n" +" return;\n" +" }\n" +" else if (window.frames.MSearchResults.searchResults)\n" +" {\n" +" var elem = window.frames.MSearchResults.searchResults.NavNext(0);\n" +" if (elem) elem.focus();\n" +" }\n" +" }\n" +" else if (e.keyCode==27) // Escape out of the search field\n" +" {\n" +" this.DOMSearchField().blur();\n" +" this.DOMPopupSearchResultsWindow().style.display = 'none';\n" +" this.DOMSearchClose().style.display = 'none';\n" +" this.lastSearchValue = '';\n" +" this.Activate(false);\n" +" return;\n" +" }\n" +"\n" " // strip whitespaces\n" " var searchValue = this.DOMSearchField().value.replace(/ +/g, \"\");\n" "\n" @@ -172,14 +206,28 @@ " else // empty search field\n" " {\n" " this.DOMPopupSearchResultsWindow().style.display = 'none';\n" +" this.DOMSearchClose().style.display = 'none';\n" " this.lastSearchValue = '';\n" " }\n" " }\n" " }\n" "\n" -" // Called when an search filter selection is made.\n" -" // set item with index id as the active item\n" -" this.OnSelectItem = function(id,topic)\n" +" this.SelectItemCount = function(id)\n" +" {\n" +" var count=0;\n" +" var win=this.DOMSearchSelectWindow(); \n" +" for (i=0;i<win.childNodes.length;i++)\n" +" {\n" +" var child = win.childNodes[i]; // get span within a\n" +" if (child.className=='SelectItem')\n" +" {\n" +" count++;\n" +" }\n" +" }\n" +" return count;\n" +" }\n" +"\n" +" this.SelectItemSet = function(id)\n" " {\n" " var i,j=0;\n" " var win=this.DOMSearchSelectWindow(); \n" @@ -191,7 +239,6 @@ " var node = child.firstChild;\n" " if (j==id)\n" " {\n" -" // add a tickmark: see http://doogalbellend.blogspot.com/2007/05/even-more-on-tick-marks-in-html.html\n" " node.innerHTML='•';\n" " } \n" " else\n" @@ -201,31 +248,39 @@ " j++;\n" " }\n" " }\n" -" if (topic)\n" -" {\n" -" this.searchTopic = topic;\n" -" var searchValue = this.DOMSearchField().value.replace(/ +/g, \"\");\n" -" if (searchValue != \"\" && this.searchActive) // something was found -> do a search\n" -" {\n" -" this.Search();\n" -" }\n" -" }\n" -" else\n" +" }\n" +"\n" +" // Called when an search filter selection is made.\n" +" // set item with index id as the active item\n" +" this.OnSelectItem = function(id)\n" +" {\n" +" this.searchIndex = id;\n" +" this.SelectItemSet(id);\n" +" var searchValue = this.DOMSearchField().value.replace(/ +/g, \"\");\n" +" if (searchValue!=\"\" && this.searchActive) // something was found -> do a search\n" " {\n" -" this.Activate(false);\n" +" this.Search();\n" " }\n" " }\n" "\n" -" this.OnCloseHighlight = function(active)\n" +" this.OnSearchSelectKey = function(evt)\n" " {\n" -" var close = this.DOMSearchResultWindowClose();\n" -" if (active)\n" +" var e = (evt) ? evt : window.event; // for IE\n" +" if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down\n" " {\n" -" close.firstChild.src = this.resultsPath + '/close_active.png';\n" +" this.searchIndex++;\n" +" this.OnSelectItem(this.searchIndex);\n" " }\n" -" else\n" +" else if (e.keyCode==38 && this.searchIndex>0) // Up\n" +" {\n" +" this.searchIndex--;\n" +" this.OnSelectItem(this.searchIndex);\n" +" }\n" +" else if (e.keyCode==13 || e.keyCode==27)\n" " {\n" -" close.firstChild.src = this.resultsPath + '/close.png';\n" +" this.OnSelectItem(this.searchIndex);\n" +" this.CloseSelectionWindow();\n" +" this.DOMSearchField().focus();\n" " }\n" " return false;\n" " }\n" @@ -235,13 +290,14 @@ " // Closes the results window.\n" " this.CloseResultsWindow = function()\n" " {\n" -" this.DOMPopupSearchResultsWindow().style.display = \"none\";\n" +" this.DOMPopupSearchResultsWindow().style.display = 'none';\n" +" this.DOMSearchClose().style.display = 'none';\n" " this.Activate(false);\n" " }\n" "\n" " this.CloseSelectionWindow = function()\n" " {\n" -" this.DOMSearchSelectWindow().style.display = \"none\";\n" +" this.DOMSearchSelectWindow().style.display = 'none';\n" " }\n" "\n" " // Performs a search.\n" @@ -267,10 +323,9 @@ " var resultsPageWithSearch;\n" " var hasResultsPage;\n" "\n" -" // indexSectionsWithContent is defined in searchdata.js\n" -" if (indexSectionsWithContent[this.searchTopic].charAt(code-32) == '1')\n" +" if (indexSectionsWithContent[this.searchIndex].charAt(code-32) == '1')\n" " {\n" -" resultsPage = this.resultsPath + '/' + this.searchTopic + '_' + hexCode + '.html';\n" +" resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';\n" " resultsPageWithSearch = resultsPage+'?'+escape(searchValue);\n" " hasResultsPage = true;\n" " }\n" @@ -284,13 +339,13 @@ " window.frames.MSearchResults.location.href = resultsPageWithSearch; \n" " var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();\n" "\n" -" if (domPopupSearchResultsWindow.style.display!=\"block\")\n" +" if (domPopupSearchResultsWindow.style.display!='block')\n" " {\n" +" var domSearchBox = this.DOMSearchBox();\n" +" this.DOMSearchClose().style.display = 'inline';\n" " if (this.insideFrame)\n" " {\n" -" var domSearchBox = this.DOMSearchBox();\n" " var domPopupSearchResults = this.DOMPopupSearchResults();\n" -" this.DOMSearchResultWindowClose().style.textAlign = 'left';\n" " domPopupSearchResultsWindow.style.position = 'relative';\n" " domPopupSearchResultsWindow.style.display = 'block';\n" " var width = document.body.clientWidth - 8; // the -8 is for IE :-(\n" @@ -299,10 +354,9 @@ " }\n" " else\n" " {\n" -" var domSearchField = this.DOMSearchField();\n" " var domPopupSearchResults = this.DOMPopupSearchResults();\n" -" var left = getXPos(domSearchField) + domSearchField.offsetWidth;\n" -" var top = getYPos(domSearchField) + domSearchField.offsetHeight + 1;\n" +" var left = getXPos(domSearchBox) + domSearchBox.offsetWidth;\n" +" var top = getYPos(domSearchBox) + domSearchBox.offsetHeight + 1;\n" " domPopupSearchResultsWindow.style.display = 'block';\n" " left -= domPopupSearchResults.offsetWidth;\n" " domPopupSearchResultsWindow.style.top = top + 'px';\n" @@ -352,9 +406,11 @@ "{\n" " // The number of matches from the last run of <Search()>.\n" " this.lastMatchCount = 0;\n" +" this.lastKey = 0;\n" +" this.repeatOn = false;\n" "\n" " // Toggles the visibility of the passed element ID.\n" -" this.Toggle = function(id)\n" +" this.FindChildElement = function(id)\n" " {\n" " var parentElement = document.getElementById(id);\n" " var element = parentElement.firstChild;\n" @@ -363,14 +419,7 @@ " {\n" " if (element.nodeName == 'DIV' && element.className == 'SRChildren')\n" " {\n" -" if (element.style.display == 'block')\n" -" { \n" -" element.style.display = 'none'; \n" -" }\n" -" else\n" -" { \n" -" element.style.display = 'block'; \n" -" }\n" +" return element;\n" " }\n" "\n" " if (element.nodeName == 'DIV' && element.hasChildNodes())\n" @@ -397,6 +446,22 @@ " }\n" " }\n" "\n" +" this.Toggle = function(id)\n" +" {\n" +" var element = this.FindChildElement(id);\n" +" if (element)\n" +" {\n" +" if (element.style.display == 'block')\n" +" { \n" +" element.style.display = 'none'; \n" +" }\n" +" else\n" +" { \n" +" element.style.display = 'block'; \n" +" }\n" +" }\n" +" }\n" +"\n" " // Searches for the passed string. If there is no parameter, \n" " // it takes it from the URL query.\n" " //\n" @@ -431,26 +496,213 @@ " if (search.length<=rowMatchName.length && \n" " rowMatchName.substr(0, search.length)==search)\n" " {\n" -" row.style.display = \"block\";\n" +" row.style.display = 'block';\n" " matches++;\n" " }\n" " else\n" " { \n" -" row.style.display = \"none\"; \n" +" row.style.display = 'none'; \n" " }\n" " }\n" " i++;\n" " }\n" -" document.getElementById(\"Searching\").style.display=\"none\";\n" +" document.getElementById(\"Searching\").style.display='none';\n" " if (matches == 0) // no results\n" " { \n" -" document.getElementById(\"NoMatches\").style.display=\"block\"; \n" +" document.getElementById(\"NoMatches\").style.display='block'; \n" " }\n" " else // at least one result\n" " { \n" -" document.getElementById(\"NoMatches\").style.display=\"none\"; \n" +" document.getElementById(\"NoMatches\").style.display='none'; \n" " }\n" " this.lastMatchCount = matches;\n" " return true;\n" " }\n" +"\n" +" // return the first item with index index or higher that is visible\n" +" this.NavNext = function(index)\n" +" {\n" +" var focusItem;\n" +" while (1)\n" +" {\n" +" var focusName = 'Item'+index;\n" +" focusItem = document.getElementById(focusName);\n" +" if (focusItem && focusItem.parentNode.parentNode.style.display=='block')\n" +" {\n" +" break;\n" +" }\n" +" else if (!focusItem) // last element\n" +" {\n" +" break;\n" +" }\n" +" focusItem=null;\n" +" index++;\n" +" }\n" +" return focusItem;\n" +" }\n" +"\n" +" this.NavPrev = function(index)\n" +" {\n" +" var focusItem;\n" +" while (1)\n" +" {\n" +" var focusName = 'Item'+index;\n" +" focusItem = document.getElementById(focusName);\n" +" if (focusItem && focusItem.parentNode.parentNode.style.display=='block')\n" +" {\n" +" break;\n" +" }\n" +" else if (!focusItem) // last element\n" +" {\n" +" break;\n" +" }\n" +" focusItem=null;\n" +" index--;\n" +" }\n" +" return focusItem;\n" +" }\n" +"\n" +" this.ProcessKeys = function(e)\n" +" {\n" +" if (e.type == \"keydown\") \n" +" {\n" +" this.repeatOn = false;\n" +" this.lastKey = e.keyCode;\n" +" }\n" +" else if (e.type == \"keypress\")\n" +" {\n" +" if (!this.repeatOn)\n" +" {\n" +" if (this.lastKey) this.repeatOn = true;\n" +" return false; // ignore first keypress after keydown\n" +" }\n" +" }\n" +" else if (e.type == \"keyup\")\n" +" {\n" +" this.lastKey = 0;\n" +" this.repeatOn = false;\n" +" }\n" +" return this.lastKey!=0;\n" +" }\n" +"\n" +" this.Nav = function(evt,itemIndex) \n" +" {\n" +" var e = (evt) ? evt : window.event; // for IE\n" +" if (e.keyCode==13) return true;\n" +" if (!this.ProcessKeys(e)) return false;\n" +"\n" +" if (this.lastKey==38) // Up\n" +" {\n" +" var newIndex = itemIndex-1;\n" +" var focusItem = this.NavPrev(newIndex);\n" +" if (focusItem)\n" +" {\n" +" var child = this.FindChildElement(focusItem.parentNode.parentNode.id);\n" +" if (child && child.style.display == 'block') // children visible\n" +" { \n" +" var n=0;\n" +" var tmpElem;\n" +" while (1) // search for last child\n" +" {\n" +" tmpElem = document.getElementById('Item'+newIndex+'_c'+n);\n" +" if (tmpElem) \n" +" {\n" +" focusItem = tmpElem; \n" +" }\n" +" else // found it!\n" +" {\n" +" break;\n" +" }\n" +" n++;\n" +" }\n" +" }\n" +" }\n" +" if (focusItem)\n" +" {\n" +" focusItem.focus();\n" +" }\n" +" else // return focus to search field\n" +" {\n" +" parent.document.getElementById(\"MSearchField\").focus();\n" +" }\n" +" }\n" +" else if (this.lastKey==40) // Down\n" +" {\n" +" var newIndex = itemIndex+1;\n" +" var focusItem;\n" +" var item = document.getElementById('Item'+itemIndex);\n" +" var elem = this.FindChildElement(item.parentNode.parentNode.id);\n" +" if (elem && elem.style.display == 'block') // children visible\n" +" {\n" +" focusItem = document.getElementById('Item'+itemIndex+'_c0');\n" +" }\n" +" if (!focusItem) focusItem = this.NavNext(newIndex);\n" +" if (focusItem) focusItem.focus();\n" +" }\n" +" else if (this.lastKey==39) // Right\n" +" {\n" +" var item = document.getElementById('Item'+itemIndex);\n" +" var elem = this.FindChildElement(item.parentNode.parentNode.id);\n" +" if (elem) elem.style.display = 'block';\n" +" }\n" +" else if (this.lastKey==37) // Left\n" +" {\n" +" var item = document.getElementById('Item'+itemIndex);\n" +" var elem = this.FindChildElement(item.parentNode.parentNode.id);\n" +" if (elem) elem.style.display = 'none';\n" +" }\n" +" else if (this.lastKey==27) // Escape\n" +" {\n" +" parent.searchBox.CloseResultsWindow();\n" +" parent.document.getElementById(\"MSearchField\").focus();\n" +" }\n" +" else if (this.lastKey==13) // Enter\n" +" {\n" +" return true;\n" +" }\n" +" return false;\n" +" }\n" +"\n" +" this.NavChild = function(evt,itemIndex,childIndex)\n" +" {\n" +" var e = (evt) ? evt : window.event; // for IE\n" +" if (e.keyCode==13) return true;\n" +" if (!this.ProcessKeys(e)) return false;\n" +"\n" +" if (this.lastKey==38) // Up\n" +" {\n" +" if (childIndex>0)\n" +" {\n" +" var newIndex = childIndex-1;\n" +" document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();\n" +" }\n" +" else // already at first child, jump to parent\n" +" {\n" +" document.getElementById('Item'+itemIndex).focus();\n" +" }\n" +" }\n" +" else if (this.lastKey==40) // Down\n" +" {\n" +" var newIndex = childIndex+1;\n" +" var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);\n" +" if (!elem) // last child, jump to parent next parent\n" +" {\n" +" elem = this.NavNext(itemIndex+1);\n" +" }\n" +" if (elem)\n" +" {\n" +" elem.focus();\n" +" } \n" +" }\n" +" else if (this.lastKey==27) // Escape\n" +" {\n" +" parent.searchBox.CloseResultsWindow();\n" +" parent.document.getElementById(\"MSearchField\").focus();\n" +" }\n" +" else if (this.lastKey==13) // Enter\n" +" {\n" +" return true;\n" +" }\n" +" return false;\n" +" }\n" "}\n" |