-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvh.js
52 lines (44 loc) · 2.04 KB
/
cvh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var CVH = {
questionArrowClick : function(event) {
var href = $(this).attr('href');
var $parent = $(this).parent();
$.get(href, function(data) {
$('section.questions article.card').hide('drop', { direction: 'down' }, 'slow', function() {
$parent.replaceWith(data);
});
var qId = $(data).find('article.question').attr('id');
var answerRegex = new RegExp('Q\\d+', '');
$('section.answers article.card a.answerlink').each(function() {
var oldAnswerCardHref = $(this).attr('href');
var newAnswerCardHref = oldAnswerCardHref.replace(answerRegex, qId);
$(this).attr('href', newAnswerCardHref);
});
var $answerArrow = $('section.answers a.arrow');
var oldAnswerArrowHref = $answerArrow.attr('href');
var newAnswerArrowHref = oldAnswerArrowHref.replace(answerRegex, qId);
$answerArrow.attr('href', newAnswerArrowHref);
});
event.preventDefault();
},
answerArrowClick : function(event) {
var href = $(this).attr('href');
var $parent = $(this).parent();
$parent.load(href);
event.preventDefault();
},
voteClick : function(event) {
$(this).siblings('form').submit();
event.preventDefault();
},
dropReplace : function(data) {
var dataClass = $('section', data).attr('class');
console.log($('section', data));
alert(dataClass);
$(this).siblings('article.card').hide('drop', { direction: 'down' }, 'slow', function() {
$(this).parent().replaceWith(data);
});
}
}
$(document).on('click', 'section.questions a.arrow', CVH.questionArrowClick);
$(document).on('click', 'section.answers a.arrow', CVH.answerArrowClick);
$(document).on('click', 'section.answers article.vote', CVH.voteClick);