autosave.js 임시저장 문의드립니다. (스마트에디터 여러개 사용시 임시저장방법 있나요?)

autosave.js 임시저장 문의드립니다. (스마트에디터 여러개 사용시 임시저장방법 있나요?)

QA

autosave.js 임시저장 문의드립니다. (스마트에디터 여러개 사용시 임시저장방법 있나요?)

본문

스마트에디터 여러개 사용시 임시저장방법 있나요?

 

현재 글쓰기페이지에서는, 

 

<?php echo editor_html('wr_1', $write['wr_1'], $is_dhtml_editor); ?>

 

이렇게 사용하는데 임시저장 autosave.js 에서는 인식을 하지 않습니다.

 

autosave.js

 


// 임시 저장하는 시간을 초단위로 설정한다.
var AUTOSAVE_INTERVAL = 30; // 초
// 글의 제목과 내용을 바뀐 부분이 있는지 비교하기 위하여 저장해 놓는 변수
var save_wr_subject = null;
var save_wr_content = null;
var save_wr_1 = null;
var save_wr_2 = null;
var save_wr_3 = null;
var save_wr_4 = null;
function autosave() {
    $("form#fwrite").each(function() {
        if(g5_editor != "") {
            if (g5_editor.indexOf("ckeditor4") != -1 && typeof(CKEDITOR.instances.wr_content)!="undefined") {
                this.wr_content.value = CKEDITOR.instances.wr_content.getData();
            } else if (g5_editor.indexOf("cheditor5") != -1 && typeof(ed_wr_content)!="undefined") {
                this.wr_content.value = ed_wr_content.outputBodyHTML();
            } else {
                if(typeof get_editor_wr_content == "function") {
                    this.wr_content.value = get_editor_wr_content();
                }
            }
        }
        // 변수에 저장해 놓은 값과 다를 경우에만 임시 저장함
        if (save_wr_subject != this.wr_subject.value || save_wr_content || save_wr_1 || save_wr_2 || save_wr_3 || save_wr_4 != this.wr_content.value) {
            $.ajax({
                url: g5_bbs_url+"/ajax.autosave.php",
                data: {
                    "uid" : this.uid.value,
                    "subject": this.wr_subject.value,
                    "content": this.wr_content.value,
                    "wr_1": this.wr_1.value,
                    "wr_2": this.wr_2.value,
                    "wr_3": this.wr_3.value,
                    "wr_4": this.wr_4.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;
            save_wr_1 = this.wr_1.value;
            save_wr_2 = this.wr_2.value;
            save_wr_3 = this.wr_3.value;
            save_wr_4 = this.wr_4.value;
        }
    });
}
$(function(){
    if (g5_is_member) {
        setInterval(autosave, AUTOSAVE_INTERVAL * 1000);
    }
    // 임시저장된 글목록을 가져옴
    $("#btn_autosave").click(function(){
        if ($("#autosave_pop").is(":hidden")) {
            $.get(g5_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('<li><a href="#none" class="autosave_load">'+subject+'</a><span>'+datetime+' <button type="button" class="autosave_del">삭제</button></span></li>')
                            .find("li:eq("+i+")")
                            .data({ as_id: id, uid: uid });
                    });
                }
            }, "xml");
            $("#autosave_pop").show();
        } else {
            $("#autosave_pop").hide();
        }
    });
    // 임시저장된 글 제목과 내용을 가져와서 제목과 내용 입력박스에 노출해 줌
    $(document).on( "click", ".autosave_load", function(){
        var $li = $(this).parents("li");
        var as_id = $li.data("as_id");
        var as_uid = $li.data("uid");   
        $("#fwrite input[name='uid']").val(as_uid); 
        $.get(g5_bbs_url+"/ajax.autosaveload.php", {"as_id":as_id}, function(data){
            var subject = $(data).find("item").find("subject").text();
            var content = $(data).find("item").find("content").text();
            var wr_1 = $(data).find("item").find("wr_1").text();
            var wr_2 = $(data).find("item").find("wr_2").text();
            var wr_3 = $(data).find("item").find("wr_3").text();
            var wr_4 = $(data).find("item").find("wr_4").text();
             $("#wr_1").val(wr_1); 
             $("#wr_2").val(wr_2); 
             $("#wr_3").val(wr_4); 
             $("#wr_4").val(wr_4); 
             $("#wr_subject").val(subject); 
            if(g5_editor != "") {
                if (g5_editor.indexOf("ckeditor4") != -1 && typeof(CKEDITOR.instances.wr_content)!="undefined") {
                    CKEDITOR.instances.wr_content.setData(content);
                } else if (g5_editor.indexOf("cheditor5") != -1 && typeof(ed_wr_content)!="undefined") {
                    ed_wr_content.putContents(content);
                } else {
                    if(typeof put_editor_wr_content == "function") {
                        put_editor_wr_content(content);
                    }
                }
            } else {
                $("#fwrite #wr_content").val(content); 
            }
 
        }, "xml");
        $("#autosave_pop").hide();
    });
    $(document).on( "click", ".autosave_del", function(){
        var $li = $(this).parents("li");
        var as_id = $li.data("as_id");
        $.get(g5_bbs_url+"/ajax.autosavedel.php", {"as_id":as_id}, function(data){
            if (data == -1) {
                alert("임시 저장된글을 삭제중에 오류가 발생하였습니다.");
            } else {
                $("#autosave_count").html(data);
                $li.remove();
            }
        });
    });
    $(".autosave_close").click(function(){ $("#autosave_pop").hide(); });
});

 

 

이 질문에 댓글 쓰기 :

답변 1

에디터 안에 있는 autosave.editor.js에서 해당되는 내용을 넘겨주어야 됩니다.

ckeditor만 조금 다르게 동작하나 보네요

 

this.wr_content.value = get_editor_wr_content();
put_editor_wr_content(content);

 

답변을 작성하시기 전에 로그인 해주세요.
전체 76
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT