topic.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. $(document).ready(function(){
  2. $('.like-reply').click(function() {
  3. var _$this = $(this);
  4. var replyId = _$this.attr('data-id');
  5. var like_url = "/replies/" + replyId + '/like';
  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(response) {
  15. if (response.status === '200')
  16. {
  17. _$this.attr("title","赞");
  18. _$this.removeClass("like-active");
  19. _$this.addClass("like-no-active");
  20. } else
  21. {
  22. window.location.href = response.data.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(response) {
  32. if (response.status === '200')
  33. {
  34. _$this.attr("title","取消赞");
  35. _$this.removeClass("like-no-active");
  36. _$this.addClass("like-active");
  37. } else
  38. {
  39. window.location.href = response.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_url,
  58. data:data,
  59. contentType: 'application/json;charset=UTF-8',
  60. success: function(response) {
  61. if (response.status === '200')
  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 : "DELETE",
  75. url : voteData.vote_url,
  76. data:data,
  77. contentType: 'application/json;charset=UTF-8',
  78. success: function(response) {
  79. if (response.status === '200')
  80. {
  81. $('.votes').html(result.html);
  82. } else
  83. {
  84. window.location.href = result.url;
  85. }
  86. }});
  87. });
  88. });
  89. }
  90. $(document).ready(function(){
  91. $('#topic-preview').click(function() {
  92. var content = $('#content').val();
  93. $.post('/topic/preview', {
  94. content: $("#content").val(),
  95. content_type: $("#content_type").val()
  96. }, function(data) {
  97. $("#show-preview").html(data);
  98. });
  99. });
  100. $('#tokenfield').tokenfield({
  101. limit:4
  102. });
  103. $('#topic-put-btn').click(function() {
  104. var _$this = $(this);
  105. var form_data = $("form#topic-put").serializeArray();
  106. var url = '/topic/' + _$this.attr("data-id");
  107. var data = {};
  108. $.each(form_data,function() {
  109. data[this.name] = this.value;
  110. });
  111. $.ajax ({
  112. type : "PUT",
  113. url : url,
  114. data:JSON.stringify(data),
  115. contentType: 'application/json;charset=UTF-8',
  116. success: function(response) {
  117. if (response.status === '200') {
  118. window.location.href= url;
  119. }
  120. }
  121. });
  122. });
  123. });