Tuesday, 10 September 2013

Typeahead.js not working on server

Typeahead.js not working on server

I was able to get the typeahead.js plugin working on my dev machine, but
once I pushed my code to heroku it stopped working. Here's the relevant
code:
if (Meteor.isClient) {
window.onload = function() {
$("input.entry").typeahead({
name: "movies",
remote: {
url:
"http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=####################&page_limit=5&q=%QUERY",
dataType: 'jsonp',
template: ["<p><strong>{{title}}</strong></p>"],
engine: Handlebars,
filter: function(parsedResponse) {
var dataset = [];
movies = parsedResponse.movies;
for(i = 0; i < movies.length; i++) {
dataset.push({
value: movies[i].title,
details: movies[i].critics_consensus,
image: movies[i].posters.profile
});
}
return dataset;
}
}
});
$('input.entry').bind('typeahead:selected', function(obj, datum) {
Movies.insert({
name: datum.value,
consensus: datum.details,
image: datum.image,
voters: [],
creator: Meteor.user(),
time: Date.now()
});
});
}
If I paste the contents of window.onload into the javascript console after
the page loads it works fine.
Does anyone have any idea why this isn't working properly?
Thanks

No comments:

Post a Comment