topic.js 2.4 KB

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