// Attach typeahead to the input
$('#searchContainer .search-query').typeahead({
hint: true,
highlight: true,
minLength: 3
}, {
name: 'search',
source: search,
templates: {
header: '
Popular Searches
',suggestion: function(datum) {
if (datum) {
return '
datum.query + ' ·
}
}
},
display: function(suggestion) {
// set the datum "identifier" that is selected or load data based on it.
return suggestion.query;
}
}, {
name: 'search-friends',
source: friends,
templates: {
header: '
Friends
',suggestion: function(datum) {
console.log('Freinds suggestion');
console.log(datum);
var img = '';
if (datum.image) {
img += '';
}
return '
'
}
},
display: function(suggestion) {
// set the datum "identifier" that is selected or load data based on it.
return suggestion.name;
}
}, {
name: 'search-groups',
source: groups,
templates: {
header: '
Groups
',suggestion: function(datum) {
var img = '';
if (datum.image) {
img += '';
}
return '
'
}
},
display: function(suggestion) {
// set the datum "identifier" that is selected or load data based on it.
return suggestion.name;
}
}, {
name: 'search-pages',
source: pages,
templates: {
header: '
Pages
',suggestion: function(datum) {
var img = '';
if (datum.image) {
img += '';
}
return '
'
}
},
display: function(suggestion) {
// set the datum "identifier" that is selected or load data based on it.
return suggestion.name;
}
}).bind('typeahead:select', function(event, suggestion) {
document.getElementById('responseDataContainer').innerHTML = JSON.stringify(suggestion);
});
/**
* Number format function.
*
* https://github.com/kvz/phpjs/blob/master/functions/strings/number_format.js
*/