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.

javascript.php 5.8KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. define('JAVASCRIPT', true);
  3. require_once "common.php";
  4. ?>
  5. <!-- --><script>
  6. $(function(){
  7. // Scan AJAX responses for errors.
  8. $(document).ajaxComplete(function(event, request){
  9. var response = request ? request.responseText : null
  10. if (isError(response))
  11. alert(response.replace(/(HEY_JAVASCRIPT_THIS_IS_AN_ERROR_JUST_SO_YOU_KNOW|<([^>]+)>\n?)/gm, ""))
  12. })<?php echo "\n\n\n\n"; # Balance out the line numbers in this script and in the output to help debugging. ?>
  13. $(".toggle_admin").click(function(){
  14. if (!$("#admin_bar:visible, #controls:visible").size())
  15. Cookie.destroy("hide_admin")
  16. else
  17. Cookie.set("hide_admin", "true", 30)
  18. $("#admin_bar, #controls").slideToggle()
  19. return false
  20. })
  21. <?php if (!isset($config->enable_ajax) or $config->enable_ajax): ?> Post.prepare_links()<?php endif; ?>
  22. })
  23. var Route = {
  24. action: "<?php echo $_GET['action']; ?>"
  25. }
  26. var site_url = "<?php echo $config->chyrp_url; ?>"
  27. var Post = {
  28. delete_animations: { height: "hide", opacity: "hide" },
  29. delete_wrap: "<div></div>",
  30. id: 0,
  31. edit: function(id) {
  32. Post.id = id
  33. $("#post_"+id).loader()
  34. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "edit_post", id: id }, function(data) {
  35. $("#post_"+id).loader(true).fadeOut("fast", function(){
  36. $(this).replaceWith(data)
  37. $("#post_edit_form_"+id).css("opacity", 0).animate({ opacity: 1 }, function(){
  38. <?php $trigger->call("ajax_post_edit_form_javascript"); ?>
  39. $("#more_options_link_"+id).click(function(){
  40. if ($("#more_options_"+id).css("display") == "none") {
  41. $(this).empty().append("<?php echo __("&uarr; Fewer Options"); ?>")
  42. $("#more_options_"+id).slideDown("slow");
  43. } else {
  44. $(this).empty().append("<?php echo __("More Options &darr;"); ?>")
  45. $("#more_options_"+id).slideUp("slow");
  46. }
  47. return false;
  48. })
  49. $("#post_edit_form_"+id).ajaxForm({ beforeSubmit: function(){
  50. $("#post_edit_form_"+id).loader()
  51. }, success: Post.updated })
  52. $("#post_cancel_edit_"+id).click(function(){
  53. $("#post_edit_form_"+id).loader()
  54. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
  55. action: "view_post",
  56. context: "all",
  57. id: id,
  58. reason: "cancelled"
  59. }, function(data) {
  60. $("#post_edit_form_"+id).loader(true).fadeOut("fast", function(){
  61. $(this).replaceWith(data)
  62. $(this).hide().fadeIn("fast")
  63. })
  64. })
  65. return false
  66. })
  67. })
  68. })
  69. })
  70. },
  71. updated: function(response){
  72. id = Post.id
  73. if (isError(response))
  74. return $("#post_edit_form_"+id).loader(true)
  75. if (Route.action != "drafts" && Route.action != "view" && $("#post_edit_form_"+id+" select#status").val() == "draft") {
  76. $("#post_edit_form_"+id).loader(true).fadeOut("fast", function(){
  77. alert("<?php echo __("Post has been saved as a draft."); ?>")
  78. })
  79. } else if (Route.action == "drafts" && $("#post_edit_form_"+id+" select#status").val() != "draft") {
  80. $("#post_edit_form_"+id).loader(true).fadeOut("fast", function(){
  81. alert("<?php echo __("Post has been published."); ?>")
  82. })
  83. } else {
  84. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
  85. action: "view_post",
  86. context: "all",
  87. id: id,
  88. reason: "edited"
  89. }, function(data) {
  90. $("#post_edit_form_"+id).loader(true).fadeOut("fast", function(){
  91. $(this).replaceWith(data)
  92. $("#post_"+id).hide().fadeIn("fast")
  93. })
  94. })
  95. }
  96. },
  97. destroy: function(id) {
  98. $("#post_"+id).loader()
  99. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "delete_post", id: id }, function(response) {
  100. $("#post_"+id).loader(true)
  101. if (isError(response)) return
  102. if (Post.delete_wrap != "")
  103. $("#post_"+id).wrap(Post.delete_wrap).parent().animate(Post.delete_animations, function(){
  104. $(this).remove()
  105. if (Route.action == "view")
  106. window.location = "<?php echo $config->url; ?>"
  107. })
  108. else
  109. $("#post_"+id).animate(Post.delete_animations, function(){
  110. $(this).remove()
  111. if (Route.action == "view")
  112. window.location = "<?php echo $config->url; ?>"
  113. })
  114. })
  115. },
  116. prepare_links: function(id) {
  117. $(".post_edit_link:not(.no_ajax)").live("click", function(){
  118. var id = $(this).attr("id").replace(/post_edit_/, "")
  119. Post.edit(id)
  120. return false
  121. })
  122. $(".post_delete_link").live("click", function(){
  123. if (!confirm("<?php echo __("Are you sure you want to delete this post?\\n\\nIt cannot be restored if you do this. If you wish to hide it, save it as a draft."); ?>")) return false
  124. var id = $(this).attr("id").replace(/post_delete_/, "")
  125. Post.destroy(id)
  126. return false
  127. })
  128. }
  129. }
  130. <?php echo "\n"; $trigger->call("javascript"); ?>
  131. <!-- --></script>