KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
6.4KB

  1. <?php
  2. define('JAVASCRIPT', true);
  3. require_once "../../includes/common.php";
  4. error_reporting(0);
  5. header("Content-Type: application/x-javascript");
  6. ?>
  7. <!-- --><script>
  8. $(function(){
  9. if ($(".comments:not(:header)").size()) {
  10. <?php if ($config->auto_reload_comments and $config->enable_reload_comments): ?>
  11. var updater = setInterval("Comment.reload()", <?php echo $config->auto_reload_comments * 1000; ?>);
  12. <?php endif; ?>
  13. $("#add_comment").append($(document.createElement("input")).attr({ type: "hidden", name: "ajax", value: "true", id: "ajax" }))
  14. $("#add_comment").ajaxForm({ dataType: "json", resetForm: true, beforeSubmit: function(){
  15. $("#add_comment").loader();
  16. }, success: function(json){
  17. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "show_comment", comment_id: json.comment_id, reason: "added" }, function(data) {
  18. if ($(".comment_count").size() && $(".comment_plural").size()) {
  19. var count = parseInt($(".comment_count:first").text())
  20. count++
  21. $(".comment_count").text(count)
  22. var plural = (count == 1) ? "" : "s"
  23. $(".comment_plural").text(plural)
  24. }
  25. $("#last_comment").val(json.comment_timestamp)
  26. $(data).appendTo(".comments:not(:header)").hide().fadeIn("slow")
  27. })
  28. }, complete: function(){
  29. $("#add_comment").loader(true)
  30. } })
  31. }
  32. <?php echo "\n"; if (!isset($config->enable_ajax) or $config->enable_ajax): ?>
  33. $(".comment_edit_link").live("click", function(){
  34. var id = $(this).attr("id").replace(/comment_edit_/, "")
  35. Comment.edit(id)
  36. return false
  37. })
  38. $(".comment_delete_link").live("click", function(){
  39. var id = $(this).attr("id").replace(/comment_delete_/, "")
  40. notice++
  41. if (!confirm("<?php echo __("Are you sure you want to delete this comment?\\n\\nIt cannot be restored if you do this.", "comments"); ?>")) {
  42. notice--
  43. return false
  44. }
  45. notice--
  46. Comment.destroy(id)
  47. return false
  48. })
  49. <?php endif; ?>
  50. })
  51. var editing = 0
  52. var notice = 0
  53. var Comment = {
  54. delete_animations: { height: "hide", opacity: "hide" },
  55. delete_wrap: "",
  56. reload: function() {
  57. if ($(".comments:not(:header)").attr("id") == undefined) return;
  58. var id = $(".comments:not(:header)").attr("id").replace(/comments_/, "")
  59. if (editing == 0 && notice == 0 && $(".comments:not(:header)").children().size() < <?php echo $config->comments_per_page; ?>) {
  60. $.ajax({ type: "post", dataType: "json", url: "<?php echo $config->chyrp_url; ?>/includes/ajax.php", data: "action=reload_comments&post_id="+id+"&last_comment="+$("#last_comment").val(), success: function(json) {
  61. $("#last_comment").val(json.last_comment)
  62. $.each(json.comment_ids, function(i, id) {
  63. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "show_comment", comment_id: id }, function(data){
  64. $(data).appendTo(".comments:not(:header)").hide().fadeIn("slow")
  65. })
  66. })
  67. } })
  68. }
  69. },
  70. edit: function(id) {
  71. editing++
  72. $("#comment_"+id).loader()
  73. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "edit_comment", comment_id: id }, function(data) {
  74. if (isError(data)) return $("#comment_"+id).loader(true)
  75. $("#comment_"+id).loader(true).fadeOut("fast", function(){ $(this).empty().append(data).fadeIn("fast", function(){
  76. $("#more_options_link_"+id).click(function(){
  77. if ($("#more_options_"+id).css("display") == "none") {
  78. $(this).empty().append("<?php echo __("&uarr; Fewer Options"); ?>")
  79. $("#more_options_"+id).slideDown("slow");
  80. } else {
  81. $(this).empty().append("<?php echo __("More Options &darr;"); ?>")
  82. $("#more_options_"+id).slideUp("slow");
  83. }
  84. return false;
  85. })
  86. $("#comment_cancel_edit_"+id).click(function(){
  87. $("#comment_"+id).loader()
  88. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "show_comment", comment_id: id }, function(data){
  89. $("#comment_"+id).loader(true).replaceWith(data)
  90. })
  91. })
  92. $("#comment_edit_"+id).ajaxForm({ beforeSubmit: function(){
  93. $("#comment_"+id).loader()
  94. }, success: function(response){
  95. editing--
  96. if (isError(response)) return $("#comment_"+id).loader(true)
  97. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "show_comment", comment_id: id, reason: "edited" }, function(data) {
  98. if (isError(data)) return $("#comment_"+id).loader(true)
  99. $("#comment_"+id).loader(true)
  100. $("#comment_"+id).fadeOut("fast", function(){
  101. $(this).replaceWith(data).fadeIn("fast")
  102. })
  103. })
  104. } })
  105. }) })
  106. })
  107. },
  108. destroy: function(id) {
  109. notice--
  110. $("#comment_"+id).loader()
  111. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "delete_comment", id: id }, function(response){
  112. $("#comment_"+id).loader(true)
  113. if (isError(response)) return
  114. if (Comment.delete_wrap != "")
  115. $("#comment_"+id).wrap(Comment.delete_wrap).parent().animate(Comment.delete_animations, function(){
  116. $(this).remove()
  117. })
  118. else
  119. $("#comment_"+id).animate(Comment.delete_animations, function(){
  120. $(this).remove()
  121. })
  122. if ($(".comment_count").size() && $(".comment_plural").size()) {
  123. var count = parseInt($(".comment_count:first").text())
  124. count--
  125. $(".comment_count").text(count)
  126. var plural = (count == 1) ? "" : "s"
  127. $(".comment_plural").text(plural)
  128. }
  129. })
  130. }
  131. }
  132. <?php Trigger::current()->call("comments_javascript"); ?>
  133. <!-- --></script>