Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the complete option

  • Loading branch information...
commit 8e5477f909f7320499b9ad1c729c86d59643f795 1 parent 1b5a862
Jeff Kreeftmeijer jeffkreeftmeijer authored
Showing with 21 additions and 8 deletions.
  1. +14 −3 README.textile
  2. +5 −4 jquery-tapir.js
  3. +2 −1  jquery-tapir.min.js
17 README.textile
View
@@ -7,8 +7,8 @@ Check out the "live example":http://tapirgo.com/examples/jquery-plugin/index.htm
h2. Using the plugin
1. Make sure you have jQuery in your site (any version above 1.2 should work).
-2. Add the jquery-tapir.min.js to your site.
-3. Call tapir() on the element you want the results to appear in.
+2. Add the @jquery-tapir.min.js@ file to your site.
+3. Call @tapir()@ on the element you want the results to appear in (don't forget to pass your token!).
example:
@@ -28,9 +28,20 @@ example:
<script src="jquery-1.6.1.min.js"></script>
<script src="jquery-tapir.min.js"></script>
<script>
- $('#search_results').tapir({'token': '4dbfc79e3f61b05b53000011'});
+ $('#search_results').tapir({'token': '4dbfc79e3f61b05b53000021'});
</script>
</body>
</html>
</code></pre>
+
+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:
+
+bc. $('#search_results').tapir({
+ 'token': '4dbfc79e3f61b05b53000021',
+ 'complete' : function() { alert("I'm done searching!"); }
+});
9 jquery-tapir.js
View
@@ -6,10 +6,10 @@
init: function(options) {
el = this;
- settings = {
- token: false,
- query_param: 'query'
- };
+ settings = {
+ token: false,
+ query_param: 'query'
+ };
if (options) {
$.extend(settings, options);
@@ -21,6 +21,7 @@
$.getJSON(
'http://tapirgo.com/api/1/search.json?token=' + settings.token + '&query=' + paramValue(settings.query_param) + '&callback=?', function(data){
+ if(settings['complete']) { settings.complete() }
Jeff Kreeftmeijer Owner

I might need some feedback on this. @roytomeij, @matsimitsu? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
$.each(data, function(key, val) {
el.append('<div class="result"><h3><a href="' + val.link + '">' + val.title + '</a></h3><p>' + val.summary + '</p></div>');
});
3  jquery-tapir.min.js
View
@@ -1,4 +1,5 @@
(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){$.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;}
+$.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);
Jeff Kreeftmeijer

I might need some feedback on this. @roytomeij, @matsimitsu? :)

Please sign in to comment.
Something went wrong with that request. Please try again.