I revently clobbered together a custom search plugin. It is a barely functional mix of SimpleSearchPlugin, SearchOptionsPlugin and tiddlywikis built in search. It is not pretty (code wise) but it does work... mostly. It functions exactly like I want it to when i run the page locally, but when i serve the page it falls apart. I was hoping that one of you could tell me where I went wrong!
I am using TiddlyWiki 2.5.2. The plugin requires two tiddlers to function. Here they are: <div title="TaoSearchOptions" modifier="CharlesNodell" created="200907241715" tags="excludeSearch" changecount="5"> <pre> <<option chkSearchText>> Text <<option chkSearchTag>> Tags <<option chkSearchTitle>> Title </pre> </div> <div title="TaoSearchPlugin" modifier="CharlesNodell" created="200907231757" modified="200907241726" tags="systemConfig excludeSearch" changecount="71"> <pre> /*** |''Name''|TaoSearchPlugin| |''Description''|Includes tags when searching.| |''Authors''|FND (Modified By Charles)| |''Version''|0.1.0| |''Status''|alpha| |''Source''|| |''CodeRepository''|| |''License''|[[Creative Commons Attribution-ShareAlike 3.0 License| http://creativecommons.org/licenses/by-sa/3.0/]]| |''Keywords''|search| !Revision History !!v0.1.0 (2009-07-23) * Initial release !To Do * Maintain compatibility with future versions of TiddlyWiki !Code ***/ //{{{ if(!version.extensions.TaoSearchPlugin) { //# ensure that the plugin is only installed once version.extensions.TaoSearchPlugin = { installed: true }; //override search macro config.macros.search.onClickSlider = function(ev) { var e = ev || window.event; var n = this.nextSibling; var cookie = n.getAttribute("cookie"); var isOpen = n.style.display != "none"; if(config.options.chkAnimate && anim && typeof Slider == "function") anim.startAnimating(new Slider(n,!isOpen,null,"none")); else n.style.display = isOpen ? "none" : "block"; config.options[cookie] = !isOpen; saveOptionCookie(cookie); return false; }; config.macros.search.createSlider = function (place,cookie,title,tooltip) { var c = cookie || ""; var btn = createTiddlyButton(place,title,tooltip,this.onClickSlider); var panel = createTiddlyElement(null,"div",null,"sliderPanel"); panel.setAttribute("cookie",c); panel.style.display = config.options[c] ? "block" : "none"; place.appendChild(panel); return panel; }; merge(config.macros.search,{ label: "search", prompt: "Search this TiddlyWiki", accessKey: "F", successMsg: "%0 tiddlers found matching %1", failureMsg: "No tiddlers found matching %0"}) config.macros.search.handler = function(place,macroName,params) { var searchTimeout = null; var btn = createTiddlyButton (place,this.label,this.prompt,this.onClick,"searchButton"); var txt = createTiddlyElement(null,"input",null,"txtOptionInput searchField"); place.appendChild(txt); txt.onkeyup = this.onKeyPress; txt.onfocus = this.onFocus; txt.setAttribute("size",this.sizeTextbox); txt.setAttribute("accessKey",params[1] || this.accessKey); txt.setAttribute("autocomplete","off"); txt.setAttribute("lastSearchText",""); var panel = this.createSlider(place,"","advanced search options ยป","Choose what elements to search"); var text = store.getTiddlerText("TaoSearchOptions"); panel.setAttribute("refresh","content"); panel.setAttribute("tiddler","TaoSearchOptions"); if(params[0]) txt.value = params[0]; if(config.browser.isSafari) { txt.setAttribute("type","search"); txt.setAttribute("results","5"); } else { txt.setAttribute("type","text"); } if(text) wikify(text,panel,null,store.getTiddler("TaoSearchOptions")); }; // override Tconfig.macros.search.onKeyPress to start incremental search with> 0 config.macros.search.onKeyPress = function(ev) { var e = ev || window.event; switch(e.keyCode) { case 13: // Ctrl-Enter case 10: // Ctrl-Enter on IE PC config.macros.search.doSearch(this); break; case 27: // Escape this.value = ""; clearMessage(); break; } if(config.options.chkIncrementalSearch) { if(this.value.length > 0) { if(this.value != this.getAttribute("lastSearchText")) { if(config.macros.search.timeout) clearTimeout(config.macros.search.timeout); var txt = this; config.macros.search.timeout = setTimeout(function() {config.macros.search.doSearch(txt);},500); } } else { if(config.macros.search.timeout) clearTimeout(config.macros.search.timeout); } } }; // override TiddlyWiki.search() to sort by relevance TiddlyWiki.prototype.search = function(searchRegExp, sortField, excludeTag, match) { var candidates = this.reverseLookup("tags", excludeTag, !!match); var primary = []; var secondary = []; var tertiary = []; if (config.options.chkSearchText==true && config.options.chkSearchTag==true && config.options.chkSearchTitle==true){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].title.search(searchRegExp) != -1) { primary.push(candidates[t]); } else if(candidates[t].tags.join(" ").search(searchRegExp) != -1) { secondary.push(candidates[t]); } else if(candidates[t].text.search(searchRegExp) != -1) { tertiary.push(candidates[t]); } } var results = primary.concat(secondary).concat(tertiary); if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==true && config.options.chkSearchTag==true && config.options.chkSearchTitle==false){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].text.search(searchRegExp) != -1) { primary.push(candidates[t]); } else if(candidates[t].tags.join(" ").search(searchRegExp) != -1) { secondary.push(candidates[t]); } } var results = primary.concat(secondary); if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==true && config.options.chkSearchTag==false && config.options.chkSearchTitle==true){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].title.search(searchRegExp) != -1) { primary.push(candidates[t]); } else if(candidates[t].text.search(searchRegExp) != -1) { secondary.push(candidates[t]); } } var results = primary.concat(secondary); if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==false && config.options.chkSearchTag==true && config.options.chkSearchTitle==true){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].title.search(searchRegExp) != -1) { primary.push(candidates[t]); } else if(candidates[t].tags.join(" ").search(searchRegExp) != -1) { secondary.push(candidates[t]); } } var results = primary.concat(secondary); if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==false && config.options.chkSearchTag==false && config.options.chkSearchTitle==true){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].title.search(searchRegExp) != -1) { primary.push(candidates[t]); } } var results = primary; if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==false && config.options.chkSearchTag==true && config.options.chkSearchTitle==false){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].tags.join(" ").search(searchRegExp) != -1) { primary.push(candidates[t]); } } var results = primary; if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else if (config.options.chkSearchText==true && config.options.chkSearchTag==false && config.options.chkSearchTitle==false){ for(var t = 0; t < candidates.length; t++) { if(candidates[t].text.search(searchRegExp) != -1) { primary.push(candidates[t]); } } var results = primary; if(sortField) { results.sort(function(a, b) { return a[sortField] < b[sortField] ? -1 : (a[sortField] == b [sortField] ? 0 : +1); }); } return results; } else { alert("At least one search option must be selected!"); } }; } //# end of "install only once" //}}} </pre> </div> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/TiddlyWiki?hl=en -~----------~----~----~----~------~----~------~--~---

