No activity today, make something!
afya
SearchOptionsPlugin
Markdown Help
Search globally
Save Tiddler
Revert Changes
Cancel Edit
/*** |Name|SearchOptionsPlugin| |Source|http://www.TiddlyTools.com/#SearchOptionsPlugin| |Documentation|http://www.TiddlyTools.com/#SearchOptionsPluginInfo| |Version|3.0.10| |Author|Eric Shulman| |License|http://www.TiddlyTools.com/#LegalStatements| |~CoreVersion|2.1| |Type|plugin| |Description|extend core search function with additional user-configurable options| Adds extra options to core search function including selecting which data items to search, enabling/disabling incremental key-by-key searches, and generating a ''list of matching tiddlers'' instead of immediately displaying all matches. This plugin also adds syntax for rendering 'search links' within tiddler content to embed one-click searches using pre-defined 'hard-coded' search terms. !!!!!Documentation >see [[SearchOptionsPluginInfo]] !!!!!Configuration <<< <
> <
> Include {{{options...}}} slider in "search again" form <<< !!!!!Revisions <<< 2011.04.08 3.0.10 fixed typo in CSS in formatSearchResults_buttons(). Restore missing options in Configuration section. |please see [[SearchOptionsPluginInfo]] for additional revision details| 2005.10.18 1.0.0 Initial Release <<< !!!!!Code ***/ //{{{ version.extensions.SearchOptionsPlugin= {major: 3, minor: 0, revision: 10, date: new Date(2011,3,18)}; //}}} //{{{ var defaults={ chkSearchTitles: true, chkSearchText: true, chkSearchTags: true, chkSearchFields: true, chkSearchTitlesFirst: true, chkSearchList: true, chkSearchHighlight: true, chkSearchListTiddler: false, chkSearchByDate: false, chkIncrementalSearch: true, chkSearchShadows: true, chkSearchOpenTiddlers: false, chkSearchResultsOptions:true, chkSearchExcludeTags: true, txtSearchExcludeTags: 'excludeSearch', txtIncrementalSearchDelay: 500, txtIncrementalSearchMin: 3 }; for (var id in defaults) if (config.options[id]===undefined) config.options[id]=defaults[id]; if (config.macros.search.reportTitle==undefined) config.macros.search.reportTitle="SearchResults"; // note: not a cookie! config.macros.search.label+="\xa0"; // a little bit of space just because it looks better //}}} // // searchLink: {{{[search[text to find]] OR [search[text to display|text to find]]}}} //{{{ config.formatters.push( { name: "searchLink", match: "\\[search\\[", lookaheadRegExp: /\[search\[(.*?)(?:\|(.*?))?\]\]/mg, prompt: "search for: '%0'", handler: function(w) { this.lookaheadRegExp.lastIndex = w.matchStart; var lookaheadMatch = this.lookaheadRegExp.exec(w.source); if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { var label=lookaheadMatch[1]; var text=lookaheadMatch[2]||label; var prompt=this.prompt.format([text]); var btn=createTiddlyButton(w.output,label,prompt, function(){story.search(this.getAttribute("searchText"))},"searchLink"); btn.setAttribute("searchText",text); w.nextMatch = this.lookaheadRegExp.lastIndex; } } }); //}}} // // incremental search uses option settings instead of hard-coded delay and minimum input values //{{{ var fn=config.macros.search.onKeyPress; fn=fn.toString().replace(/500/g, "config.options.txtIncrementalSearchDelay||500"); fn=fn.toString().replace(/> 2/g, ">=(config.options.txtIncrementalSearchMin||3)"); eval("config.macros.search.onKeyPress="+fn); //}}} // // REPLACE story.search() for option to "show search results in a list" //{{{ Story.prototype.search = function(text,useCaseSensitive,useRegExp) { var co=config.options; // abbrev var re=new RegExp(useRegExp ? text : text.escapeRegExp(),useCaseSensitive ? "mg" : "img"); if (config.options.chkSearchHighlight) highlightHack=re; var matches = store.search(re,co.chkSearchByDate?"modified":"title",""); if (co.chkSearchByDate) matches=matches.reverse(); // most recent first var q = useRegExp ? "/" : "'"; clearMessage(); if (!matches.length) { if (co.chkSearchListTiddler) discardSearchResults(); displayMessage(config.macros.search.failureMsg.format([q+text+q])); } else { if (co.chkSearchList||co.chkSearchListTiddler) reportSearchResults(text,matches); else { var titles = []; for(var t=0; t
=0; t--) if (!tids[t].tags.containsAny(ex)) temp.push(tids[t]); tids=temp; } // scan for matching titles first... var results = []; if (co.chkSearchTitles) { for(var t=0; t
>}}} macro to add "report" and "simple inline" output //{{{ config.macros.search.SOP_handler=config.macros.search.handler; config.macros.search.handler = function(place,macroName,params) { // if "report", use SearchOptionsPlugin report generator for inline output if (params[1]&¶ms[1].substr(0,6)=="report") { var keyword=params[0]; var options=params[1].split("=")[1]; // split "report=option+option+..." var heading=params[2]?params[2].unescapeLineBreaks():""; var matches=store.search(new RegExp(keyword.escapeRegExp(),"img"),"title","excludeSearch"); if (matches.length) wikify(heading+window.formatSearchResults(keyword,matches,options),place); } else if (params[1]) { var keyword=params[0]; var heading=params[1]?params[1].unescapeLineBreaks():""; var seperator=params[2]?params[2].unescapeLineBreaks():", "; var matches=store.search(new RegExp(keyword.escapeRegExp(),"img"),"title","excludeSearch"); if (matches.length) { var out=[]; for (var m=0; m
> /%\n'; body+='%/
'; if (!config.options.chkSearchResultsOptions) // omit "options..." body+=''; else { body+='
options...
'; body+='