diff --git a/doc-src/assets/javascripts/jquery.url.packed.js b/doc-src/assets/javascripts/jquery.url.packed.js new file mode 100644 index 00000000..14ae800f --- /dev/null +++ b/doc-src/assets/javascripts/jquery.url.packed.js @@ -0,0 +1 @@ +jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}(); \ No newline at end of file diff --git a/doc-src/content/search-data.js.erb b/doc-src/content/search-data.js.erb index 42fab9d4..f948f90d 100644 --- a/doc-src/content/search-data.js.erb +++ b/doc-src/content/search-data.js.erb @@ -1,7 +1,34 @@ -function search(term, callback) { - var ids = index.terms[term] || index.approximate[term] || []; - var items = $.map(ids, function(id){ return index.items[id]; }); - callback(items) +function unique(arrayName) + { + var newArray = new Array(); + label: for (var i = 0; i < arrayName.length; i++) + { + for (var j = 0; j < newArray.length; j++) + { + if (newArray[j] == arrayName[i]) + continue label; + } + newArray[newArray.length] = arrayName[i]; + } + return newArray; +} +function search(query, callback) { + var terms = $.trim(query).replace(/[\W\s_]+/m,' ').toLowerCase().split(/\s+/); + var matching_ids = null; + for (var i = 0; i < terms.length; i++) { + var term = terms[i]; + var exactmatch = index.terms[term] || []; + var approxmatch = index.approximate[term] || []; + var ids = unique(exactmatch.concat(approxmatch)); + if (matching_ids) { + matching_ids = $.grep(matching_ids, function(id) { + return ids.indexOf(id) != -1; + }); + } else { + matching_ids = ids; + } + } + callback($.map(matching_ids, function(id){ return index.items[id]; })) } var index = <%= search_index.to_json %>; diff --git a/doc-src/content/search.haml b/doc-src/content/search.haml index 595c03f1..fb7910a3 100644 --- a/doc-src/content/search.haml +++ b/doc-src/content/search.haml @@ -5,9 +5,14 @@ body_id: search --- - content_for(:javascripts) do %script(type="text/javascript" src="/docs/javascripts/search-data.js") + %script(type="text/javascript" src="/docs/javascripts/jquery.url.packed.js") :javascript $(function(){ - $('input').keypress(function(){ + if ($.url.param("q")) { + $('input#q').attr('value', $.url.param("q")); + search($.url.param("q"), displayResults); + } + $('input#q').keyup(function(){ search(this.value, displayResults); }); }) @@ -22,7 +27,7 @@ body_id: search $('ol#results').html("