save_draft.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. function hideError() {
  2. $("#response-error").fadeOut(600, function() {
  3. $("#response-error").css("display", "none");
  4. });
  5. }
  6. function updateData() {
  7. // Prepare data to send to PHP
  8. var data = {
  9. title: $("#pTitle").val(),
  10. url: $("#pURL").val(),
  11. content: $("#wmd-input").val(),
  12. description: $("#pMeta").val(),
  13. tag: $("#pTag").val(),
  14. category: $("#pCategory").val(),
  15. posttype: $("#pType").val(),
  16. pimage: $("#pImage").val(),
  17. paudio: $("#pAudio").val(),
  18. pvideo: $("#pVideo").val(),
  19. pquote: $("#pQuote").val(),
  20. plink: $("#pLink").val(),
  21. dateTime: $("#pDate").val() + " " + $("#pTime").val(),
  22. ai: $("#pAI").is(":checked") ? "yes" : "",
  23. autoSave: 'autoSave',
  24. addEdit: addEdit,
  25. oldfile: $("#oldfile").val(),
  26. parent_page: parent_page
  27. };
  28. $.ajax({
  29. url: base_path + 'admin/autosave',
  30. type: "POST",
  31. data: data,
  32. success: function(response) {
  33. $("#response").html(response.message);
  34. $("#oldfile").val(response.file);
  35. hideError();
  36. $("#response").fadeIn(600, function() {
  37. $("#response").css("display", "block");
  38. });
  39. setTimeout(function() {
  40. $("#response").fadeOut(600, function() {
  41. $("#response").css("display", "none");
  42. });
  43. }, 6000);
  44. },
  45. error: function(response) {
  46. var httpError = "";
  47. if (response.status !== 0) {
  48. httpError += ": " + response.status;
  49. if (response.responseText) {
  50. httpError += " " + response.responseText;
  51. }
  52. }
  53. $("#response-error").html("Error in Autosaving: " + response.statusText + httpError);
  54. $("#response-error").fadeIn(600, function() {
  55. $("#response-error").css("display", "block");
  56. });
  57. setTimeout(hideError, saveInterval/2);
  58. }
  59. });
  60. }
  61. $(document).ready(function() {
  62. setInterval(updateData, saveInterval);
  63. });