Question

Very much new to web development and Jekyll, and trying to implement TapirGo into my website to allow for static search. It appears as though their Jquery plugin is active on my site (when manually adding the parameter ?query=example to my site, it seems to make mention of tapir when loading my website) but I cannot figure out for the life of me how to actually get results to appear in anything meaningful.

Ideally, I'd have a form in my website that would display a list of results and allow the visitor to click on one.

Anyways, here's my (mostly copy and pasted) code:

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/libs/modernizr-2.0.min.js"></script>
<script src="/js/libs/respond.min.js"></script>   
<script src="/js/jquery-tapir.min.js"></script>
<script>
    $('#search_results').tapir({'token': '502f16a53f61b006d6000bbc'});
</script>   
</head>
<body>
<div id="search_results"></div>
</body>

Thanks ahead of time for the help!

Was it helpful?

Solution

If you want to display result you need to create an input text and a button. You don't need to call tapir(...) method because the way they implement it is crap :) (or I don't like it, choose which one you prefer)

So first do the text box and the button, followed by the div that will display result.

<!-- HTML -->
<input type="text" name="query" />
<input type="button" name="search" value="search" />
<div id="results"></div>

 ...

and then,

// Javascript
$('input[name="search"]').click(function(e) {
    $.getJSON(
        'http://tapirgo.com/api/1/search.json?token=' 
             + 'PUT_YOUR_TOKEN_HERE' 
             + '&query=' 
             + $('input[name="query"]').val()
             + '&callback=?', 
        function(data) {
            $('#results').empty();
            $.each(data, function(key, val) {
                $('#results').append('<div class="result"><h3><a href="'
                                     + val.link + '">' 
                                     + val.title + '</a></h3><p>' 
                                     + val.summary + '</p></div>');
            });
        }
    );
});

OTHER TIPS

I think Tapir is no longer supported. I have implemented a static search mechanism myself using Jquery. You can reuse the code from here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top