topic.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. $(document).ready(function(){
  2. $('.like-reply').click(function() {
  3. var _$this = $(this);
  4. var replyId = _$this.attr('data-id');
  5. var like_url = "/user/like/" + replyId;
  6. var data = JSON.stringify({
  7. });
  8. if(_$this.hasClass('like-active')){
  9. $.ajax ({
  10. type : "DELETE",
  11. url : like_url,
  12. data:data,
  13. contentType: 'application/json;charset=UTF-8',
  14. success: function(result) {
  15. if (result.judge === true)
  16. {
  17. _$this.attr("title","赞");
  18. _$this.removeClass("like-active");
  19. _$this.addClass("like-no-active");
  20. } else
  21. {
  22. window.location.href = result.url;
  23. }
  24. }});
  25. }else {
  26. $.ajax ({
  27. type : "POST",
  28. url : like_url,
  29. data:data,
  30. contentType: 'application/json;charset=UTF-8',
  31. success: function(result) {
  32. if (result.judge === true)
  33. {
  34. _$this.attr("title","取消赞");
  35. _$this.removeClass("like-no-active");
  36. _$this.addClass("like-active");
  37. } else
  38. {
  39. window.location.href = result.url;
  40. }
  41. }});
  42. }});
  43. $('.reply-author').click(function() {
  44. var _$this = $(this);
  45. var author = _$this.attr('data-id');
  46. $('#content').focus();
  47. $('#content').val('@' + author + ' ');
  48. });
  49. });
  50. function DoVote(voteData) {
  51. $(document).ready(function(){
  52. $('#topic-up-vote').click(function() {
  53. var data = JSON.stringify({
  54. });
  55. $.ajax ({
  56. type : "POST",
  57. url : voteData.vote_up,
  58. data:data,
  59. contentType: 'application/json;charset=UTF-8',
  60. success: function(result) {
  61. if (result.judge)
  62. {
  63. $('.votes').html(result.html);
  64. } else
  65. {
  66. window.location.href = result.url;
  67. }
  68. }});
  69. });
  70. $('#topic-down-vote').click(function() {
  71. var data = JSON.stringify({
  72. });
  73. $.ajax ({
  74. type : "POST",
  75. url : voteData.vote_down,
  76. data:data,
  77. contentType: 'application/json;charset=UTF-8',
  78. success: function(result) {
  79. if (result.judge)
  80. {
  81. $('.votes').html(result.html);
  82. } else
  83. {
  84. window.location.href = result.url;
  85. }
  86. }});
  87. });
  88. });
  89. }