Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const typeahead = (element, options) => {
const source = new Bloodhound({
// Boilerplate
datumTokenizer(d) {
return Bloodhound.tokenizers.whitespace(d.num);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: options.url,
wildcard: '%QUERY',
},
});
element.typeahead({
valueKey: 'id',
}, {
name: options.name || 'typeahead',
source,
templates: {
suggestion: options.template,
},
display: options.display || 'name',
}).on('typeahead:selected typeahead:autocompleted', options.select);
};
export const typeahead = (element, options) => {
const source = new Bloodhound({
// Boilerplate
datumTokenizer(d) {
return Bloodhound.tokenizers.whitespace(d.num);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: options.url,
wildcard: '%QUERY',
},
});
element.typeahead({
valueKey: 'id',
}, {
name: options.name || 'typeahead',
source,
templates: {
function init() {
autocomplete = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete.json?term=%QUERY",
wildcard: "%QUERY",
rateLimitBy: "throttle",
rateLimitWait: 300
},
sufficient: 12
});
}
function init() {
autocomplete = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete.json?term=%QUERY",
wildcard: "%QUERY",
rateLimitBy: "throttle",
rateLimitWait: 300
},
sufficient: 12
});
}
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value) },
queryTokenizer: Bloodhound.tokenizers.whitespace,
datumTokenizer(d) {
return Bloodhound.tokenizers.whitespace(d.num);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
})
groups.initialize()
$('input.group_typeahead, .entry_add_form input[name="groupname"], .content_add_form input[name="groupname"]').typeahead(null, {
name: 'groups',
source: groups.ttAdapter(),
display: 'value',
templates: {
suggestion: _.template('<div><img class="avatar" src="<%= avatar %>"><p><%= value %><span class="count">[<%= contents %>]</span></p></div>')
}
})
var users = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value) },
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: '/users.json',
filter: function (d) {
if (window.blocked_users)
return _.filter(d, function (u) { return !_.includes(window.blocked_users, u.value) })
else
return d
}
}
})
users.initialize()
$('input.user_typeahead').typeahead([
{
name: 'users',
if (!('permission' in Notification))
Notification.permission = permission
if (permission === 'granted')
$('input[name="browser_notifications"]').prop('checked', true)
})
}
return false
})
if (window.Notification && Notification.permission === 'granted')
$('input[name="browser_notifications"]').prop('checked', true)
if (window.username) {
var groups = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value) },
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: '/groups.json',
filter: function (d) {
if (window.settings && window.settings.homepage_subscribed)
return _.filter(d, function (g) { return _.includes(window.subscribed_groups, g.value) })
else
return _.filter(d, function (g) { return !_.includes(window.blocked_groups, g.value) })
}
},
sorter: function (a, b) {
return b.contents - a.contents
}
})
return b.contents - a.contents
}
})
groups.initialize()
$('input.group_typeahead, .entry_add_form input[name="groupname"], .content_add_form input[name="groupname"]').typeahead(null, {
name: 'groups',
source: groups.ttAdapter(),
display: 'value',
templates: {
suggestion: _.template('<div><img class="avatar" src="<%= avatar %>"><p><%= value %><span class="count">[<%= contents %>]</span></p></div>')
}
})
var users = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value) },
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: '/users.json',
filter: function (d) {
if (window.blocked_users)
return _.filter(d, function (u) { return !_.includes(window.blocked_users, u.value) })
else
return d
}
}
})
users.initialize()
$('input.user_typeahead').typeahead([