2014-07-05 08:50:04 -06:00
|
|
|
$(function() {
|
|
|
|
var $qa = $('#qa');
|
|
|
|
$qa.find('form.question').each(function() {
|
|
|
|
var $form = $(this);
|
2014-07-07 11:30:52 -06:00
|
|
|
var $tmInput = $form.find('input.tm-input');
|
|
|
|
$tmInput.each(function() {
|
|
|
|
var tagApi = $tmInput.tagsManager({
|
|
|
|
prefilled: $tmInput.data('prefill'),
|
2014-07-05 08:50:04 -06:00
|
|
|
backspace: [],
|
|
|
|
delimiters: [13, 44],
|
2014-07-07 11:30:52 -06:00
|
|
|
tagsContainer: $form.find('.tags_list'),
|
2014-07-09 16:38:08 -06:00
|
|
|
maxTags: 10
|
2014-07-05 08:50:04 -06:00
|
|
|
});
|
|
|
|
var tagSource = new Bloodhound({
|
|
|
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
2014-07-07 11:30:52 -06:00
|
|
|
local: $.map($tmInput.data('tags').split(','), function(t) {
|
2014-07-05 08:50:04 -06:00
|
|
|
return {
|
|
|
|
value: t
|
|
|
|
};
|
|
|
|
})
|
|
|
|
});
|
|
|
|
tagSource.initialize();
|
2014-07-07 11:30:52 -06:00
|
|
|
$tmInput.typeahead({
|
2014-07-05 08:50:04 -06:00
|
|
|
minLength: 1,
|
|
|
|
highlight: true
|
|
|
|
}, {
|
|
|
|
source: tagSource.ttAdapter(),
|
|
|
|
name: 'tags',
|
|
|
|
displayKey: 'value',
|
|
|
|
limit: 15
|
|
|
|
}).on('typeahead:selected', function(e, d) {
|
|
|
|
tagApi.tagsManager("pushTag", d.value);
|
2014-07-07 11:30:52 -06:00
|
|
|
$tmInput.val('');
|
2014-07-05 08:50:04 -06:00
|
|
|
});
|
2014-07-07 11:30:52 -06:00
|
|
|
$form.submit(function() {
|
|
|
|
var tag = $tmInput.val();
|
|
|
|
if (tag) {
|
|
|
|
tagApi.tagsManager("pushTag", tag);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$qa.on('click', '.upvote.enabled a', function() {
|
|
|
|
var $a = $(this);
|
|
|
|
$.ajax({
|
|
|
|
method: 'post',
|
|
|
|
url: $a.parent().data('post-url'),
|
|
|
|
data: {
|
|
|
|
vote: $a.data('vote')
|
|
|
|
},
|
|
|
|
success: function(html) {
|
|
|
|
$a.parent().replaceWith(html);
|
|
|
|
}
|
2014-07-05 08:50:04 -06:00
|
|
|
});
|
|
|
|
});
|
2014-07-07 11:30:52 -06:00
|
|
|
|
2014-07-05 08:50:04 -06:00
|
|
|
$qa.on('click', '.your-comment .toggle', function() {
|
|
|
|
var $form = $(this).siblings('form');
|
|
|
|
$form.toggle(200, function() {
|
|
|
|
if ($form.is(':visible')) $form.find('textarea').focus();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$qa.find('.your-comment form').submit(function() {
|
|
|
|
if ($(this).find('textarea').val().length < 20) {
|
|
|
|
alert("Comment must be longer than 20 characters");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2014-07-07 11:30:52 -06:00
|
|
|
$qa.find('.answer').each(function() {
|
|
|
|
var $answer = $(this);
|
|
|
|
$answer.on('click', '.toggle-edit-answer', function() {
|
|
|
|
$answer.toggleClass('edit');
|
|
|
|
if (!$answer.hasClass('edit-loaded')) {
|
|
|
|
$answer.addClass('edit-loaded');
|
|
|
|
$answer.find('form.edit-answer').submit(function() {
|
|
|
|
if ($(this).find('textarea').val().length < 30) {
|
|
|
|
alert("Answer must be longer than 30 characters");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-07-05 08:50:04 -06:00
|
|
|
});
|