app/assets/javascripts/articles.js.coffee.erb
$ ->
# tagging
bhTags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
dupDetector: (remoteMatch, localMatch) ->
remoteMatch.id == localMatch.id
,
# prefetch: {
# url: '/tags/list.json',
# ttl: 5000
# },
remote: '<%= asset_path '/tags/list.json?q=%QUERY' %>'
})
bhTags.initialize()
$("input.js-tag-names").tokenfield({
typeahead: [
{
hint: true,
highlight: true,
minLength: 1
},
{
name: 'tagName',
displayKey: 'name',
source: bhTags.ttAdapter(),
templates: {
suggestion: Handlebars.compile('<p><strong>{{name}}</strong> ({{taggings_count}})</p>')
}
}
]
})
# ToC toggle
$(document).on 'click', '.markdown-toc h1', (e)->
e.preventDefault()
e.stopPropagation()
e.stopImmediatePropagation()
$tocArea = $(this).parent()
$ul = $(this).siblings('ul')
if $ul.is(':visible')
$ul.hide()
$tocArea.attr('data-opened', 'false')
else
$ul.show()
$tocArea.attr('data-opened', 'true')