forked from TapirGo/jquery-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-tapir.min.js
4 lines (3 loc) · 1.18 KB
/
jquery-tapir.min.js
1
2
3
4
(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;}var query=paramValue(settings.query_param);if(settings.query){query=settings.query;}$.getJSON(createUrl(settings.token,query),function(data){displayResult(el,data,settings.complete)});return this;}};function displayResult(el,data,complete){if(complete){complete();}el.empty();$.each(data,function(key,val){el.append('<div class="result"><h3><a href="'+val.link+'">'+val.title+'</a></h3><p>'+val.summary+'</p></div>');});};function createUrl(token,query){return'http://tapirgo.com/api/1/search.json?token='+token
+'&query='+query
+'&callback=?';};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);