Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'process' config option and now clear original div before appending #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
});
7 changes: 7 additions & 0 deletions jquery-tapir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
});
}
Expand Down
6 changes: 1 addition & 5 deletions jquery-tapir.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.