save_draft.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. autoSave: 'autoSave',
  23. addEdit: addEdit,
  24. oldfile: $("#oldfile").val(),
  25. parent_page: parent_page
  26. };
  27. $.ajax({
  28. url: base_path + 'admin/autosave',
  29. type: "POST",
  30. data: data,
  31. success: function(response) {
  32. $("#response").html(response.message);
  33. $("#oldfile").val(response.file);
  34. hideError();
  35. $("#response").fadeIn(600, function() {
  36. $("#response").css("display", "block");
  37. });
  38. setTimeout(function() {
  39. $("#response").fadeOut(600, function() {
  40. $("#response").css("display", "none");
  41. });
  42. }, 6000);
  43. },
  44. error: function(response) {
  45. var httpError = "";
  46. if (response.status !== 0) {
  47. httpError += ": " + response.status;
  48. if (response.responseText) {
  49. httpError += " " + response.responseText;
  50. }
  51. }
  52. $("#response-error").html("Error in Autosaving: " + response.statusText + httpError);
  53. $("#response-error").fadeIn(600, function() {
  54. $("#response-error").css("display", "block");
  55. });
  56. setTimeout(hideError, saveInterval/2);
  57. }
  58. });
  59. }
  60. $(document).ready(function() {
  61. setInterval(updateData, saveInterval);
  62. });