Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 11 additions and 7 deletions.
  1. +3 −2 README.textile
  2. +7 −0 jquery-tapir.js
  3. +1 −5 jquery-tapir.min.js
View
5 README.textile
@@ -39,9 +39,10 @@ h2. Options
h3. Complete
-If you pass a function as a @complete@-option, your function will be executed when the search is complete and the results have been returned, right before they're appended to the page:
+If you pass a function as a @complete@-option, your function will be executed when the search is complete and the results have been returned, right before they're appended to the page. Additionally, you can pass a function as a @process@-option that will allow you to make modifications per result (the following example truncates each result to 50 words):
bc. $('#search_results').tapir({
'token': '4dbfc79e3f61b05b53000021',
- 'complete' : function() { alert("I'm done searching!"); }
+ 'complete' : function() { alert("I'm done searching!"); },
+ 'process' : function(result) { result.summary = result.summary.split(' ', 50).join(' ') + '...'; return result; }
});
View
7 jquery-tapir.js
@@ -22,7 +22,14 @@
$.getJSON(
'http://tapirgo.com/api/1/search.json?token=' + settings.token + '&query=' + paramValue(settings.query_param) + '&callback=?', function(data){
if(settings['complete']) { settings.complete() }
+
+ // Clear div if we have results
+ if(data.length > 0)
+ el.empty();
+
$.each(data, function(key, val) {
+ if(settings['process'])
+ val = settings.process(val);
el.append('<div class="result"><h3><a href="' + val.link + '">' + val.title + '</a></h3><p>' + val.summary + '</p></div>');
});
}
View
6 jquery-tapir.min.js
@@ -1,5 +1 @@
-(function($){var el;var settings={};var methods={init:function(options){el=this;settings={token:false,query_param:'query'};if(options){$.extend(settings,options);}
-if(!settings.token||settings.query_param==''){return this;}
-$.getJSON('http://tapirgo.com/api/1/search.json?token='+settings.token+'&query='+paramValue(settings.query_param)+'&callback=?',function(data){if(settings['complete']){settings.complete()}
-$.each(data,function(key,val){el.append('<div class="result"><h3><a href="'+val.link+'">'+val.title+'</a></h3><p>'+val.summary+'</p></div>');});});return this;}};function paramValue(query_param){var results=new RegExp('[\\?&]'+query_param+'=([^&#]*)').exec(window.location.href);return results?results[1]:false;}
-$.fn.tapir=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}else{$.error('Method '+method+' does not exist on jQuery.tapir');}};})(jQuery);
+(function(d){var c;var b={};var a={init:function(f){c=this;b={token:false,query_param:"query"};if(f){d.extend(b,f)}if(!b.token||b.query_param==""){return this}d.getJSON("http://tapirgo.com/api/1/search.json?token="+b.token+"&query="+e(b.query_param)+"&callback=?",function(g){if(b.complete){b.complete()}if(g.length>0){c.empty()}d.each(g,function(h,i){if(b.process){i=b.process(i)}c.append('<div class="result"><h3><a href="'+i.link+'">'+i.title+"</a></h3><p>"+i.summary+"</p></div>")})});return this}};function e(f){var g=new RegExp("[\\?&]"+f+"=([^&#]*)").exec(window.location.href);return g?g[1]:false}d.fn.tapir=function(f){if(a[f]){return a[f].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof f==="object"||!f){return a.init.apply(this,arguments)}else{d.error("Method "+f+" does not exist on jQuery.tapir")}}}})(jQuery);

No commit comments for this range

Something went wrong with that request. Please try again.