Permalink
Browse files

initial import

  • Loading branch information...
1 parent 34bbdb4 commit bb294106970013fb7db11c09419efb640c02ff77 @matsimitsu matsimitsu committed May 14, 2011
Showing with 129 additions and 0 deletions.
  1. 0 README
  2. +37 −0 README.textile
  3. +24 −0 example.html
  4. +18 −0 jquery-1.6.1.min.js
  5. +50 −0 jquery-tapirgo.js
View
0 README
No changes.
View
@@ -0,0 +1,37 @@
+h1. TapirGo JQuery plugin
+
+An plugin that makes searching with TapirGo a breeze!
+
+Live example at "http://tapirgo.com/jquery-plugin/index.html":http://tapirgo.com/jquery-plugin/index.html
+
+h2. Using the plugin.
+
+1. Make sure you have JQuery in your site.
+2. Add the jquery-tapirgo.js to your site.
+3. Add the tapirgo call to your source. (see example)
+
+example:
+
+<pre><code>
+ <!DOCTYPE html>
+
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <title>Tapirgo jQuery plugin example</title>
+ </head>
+
+ <body>
+
+ <div id="search_results"></div>
+
+ <script src="jquery-1.6.1.min.js"></script>
+ <script src="jquery-tapirgo.js"></script>
+ <script>
+ $('#search_results').tapirgo({'token': '4dbfc79e3f61b05b53000011'});
+ </script>
+
+ </body>
+ </html>
+</code></pre>
+
View
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Tapirgo jQuery plugin example</title>
+ </head>
+
+ <body>
+ <h1>Tapirgo jQuery plugin example</h1>
+ <p>Call this page with the following params: ?query=example or <a href="?query=example">click this link</a>.</p>
+ <p>Results will be placed in the "search_results" div.</p>
+ <h2>Search results:</h2>
+ <div id="search_results">
+ </div>
+
+ <script src="jquery-1.6.1.min.js"></script>
+ <script src="jquery-tapirgo.js"></script>
+ <script>
+ $('#search_results').tapirgo({'token': '4dce6da43f61b05bff000052'});
+ </script>
+
+ </body>
+</html>
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,50 @@
+(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;
+ }
+ };
+
+ // Extract the param value from the URL.
+ function paramValue(query_param) {
+ var results = new RegExp('[\\?&]' + query_param + '=([^&#]*)').exec(window.location.href);
+ return results ? results[1] : false;
+ }
+
+ $.fn.tapirgo = 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.tapirgo');
+ }
+ };
+
+})( jQuery );

0 comments on commit bb29410

Please sign in to comment.