[Solved] Newbie question: how to use jquery plugin in Meteor


#1

I want to incorporate a jquery plugin for searching in Bing into my Meteor app, but I can’t figure out how to do it. A few tips would be much appreciated!!

This is the plugin: https://github.com/cbenard/jquery-bingsearch

I have the plugin stored into my app library but I don’t know how to use it from within the app code.

The plugin presents a couple of examples:

HTML code: <script type="text/javascript" src="js/jquery.bingsearch-min.js"></script>

Also it presents sample Javascript code (see below). The plugin is set up such that once you have typed your search text into a search field and pushed the “Submit” button, then I assume the below code is called.
However, I rather need to construct my own query and then use the plugin to search.
How can I call the below code from within the Meteor app?

Javascript code:
$.bingSearch({
// Required: query text
query: ‘query text here’,
// Required (unless you use urlBase) by Bing Search API
appKey: ‘Put your Windows Azure Marketplace Bing Search API Primary Account Key here’
// Optional (defaults to the Bing Search API Web Results Query).
// Additional information: This feature allows you to proxy through a server-side
// script in order to hide your API key, which is exposed to the
// world if you set it client-side in appKey. An example PHP
// script is included (searchproxy.php).
urlBase: ‘searchproxy.php’,
// Optional (defaults to 1): Page Number
pageNumber: parseInt($(’#pageNumber’).val()),
// Optional (defaults to 10): Page Size
pageSize: 10,
// Optional (defaults to null): Limit to site. Shortcut to adding "site:example.org " to query
limitToSite: ‘example.org’,
// Optional (defaults to false): Print console logging information about search results
debug: false,
// Optional: Function is called after search results are retrieved, but before the interator is called
beforeSearchResults: function(data) {
// Use data.hasMore, data.resultBatchCount
},
// Optional: Function is called once per result in the current batch
searchResultIterator: function(data) {
// Use data.ID, data.Title, data.Description, data.Url, data.DisplayUrl, data.Metadata.Type (check for undefined)
},
// Optional: Function is called after search results are retrieved and after all instances of the interator are called
afterSearchResults: function(data) {
// Use data.hasMore, data.resultBatchCount
},
// Optional: Called when there is an error retrieving results
fail: function(data) {
// data contains an error message
}
});


#2

I figured it out myself so don’t bother to respond.
I tried to delete the question but didn’t seem possible.


#3

Can you share your solution?


#4

Yeah - not being an expert I may not be able to explain properly.
But essentially I figured out to place the $.bingSearch function in a separate javascript file in the client/lib directory.
I am then able to call it from any of the template helpers for instance.
In fact it isn’t necessary to place a search field - the function can be called without it, and modified to purpose.


#5

If your using this, do be mindful of putting this in client/lib…