diff --git a/js/autosave.js b/js/autosave.js new file mode 100644 index 000000000..f9684db1a --- /dev/null +++ b/js/autosave.js @@ -0,0 +1,98 @@ +// 임시 저장하는 시간을 초단위로 설정한다. +var AUTOSAVE_INTERVAL = 60; // 초 + +// 글의 제목과 내용을 바뀐 부분이 있는지 비교하기 위하여 저장해 놓는 변수 +var save_wr_subject = null; +var save_wr_content = null; + +function autosave() { + $("form#fwrite").each(function() { + if (typeof(CKEDITOR.instances.wr_content)!="undefined") + this.wr_content.value = CKEDITOR.instances.wr_content.getData(); + // 변수에 저장해 놓은 값과 다를 경우에만 임시 저장함 + if (save_wr_subject != this.wr_subject.value || save_wr_content != this.wr_content.value) { + $.ajax({ + url: g4_bbs_url+"/ajax.autosave.php", + data: { + "uid" : this.uid.value, + "subject": this.wr_subject.value, + "content": this.wr_content.value + }, + type: "POST", + success: function(data){ + if (data) { + $("#autosave_count").html(data); + } + } + }); + save_wr_subject = this.wr_subject.value; + save_wr_content = this.wr_content.value; + } + }); +} + +$(function(){ + + if (g4_is_member) { + setInterval(autosave, AUTOSAVE_INTERVAL * 1000); + } + + // 임시저장된 글목록을 가져옴 + $("#btn_autosave").click(function(){ + if ($("#autosave_pop").is(":hidden")) { + $.get(g4_bbs_url+"/ajax.autosavelist.php", function(data){ + //alert(data); + //console.log( "Data: " + data); + $("#autosave_pop ul").empty(); + if ($(data).find("list").find("item").length > 0) { + $(data).find("list").find("item").each(function(i) { + var id = $(this).find("id").text(); + var uid = $(this).find("uid").text(); + var subject = $(this).find("subject").text(); + var datetime = $(this).find("datetime").text(); + $("#autosave_pop ul").append('