Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1648 CKEditor에도 자동 저장 기능 추가 #1651

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/editor/skins/ckeditor/css/default.css
@@ -0,0 +1 @@
p.editor_autosaved_message.autosave_message {display:none;background: #f6ffdb;padding:6px 10px;margin:0;line-height:1;}
13 changes: 13 additions & 0 deletions modules/editor/skins/ckeditor/editor.html
Expand Up @@ -8,6 +8,10 @@
<load target="../../tpl/js/editor.app.js" />
<load target="js/xe_interface.js" />

<script>
var auto_saved_msg = "{$lang->msg_auto_saved}";
</script>

{@ $css_content = null }
<!--@if($content_font || $content_font_size)-->
<!--@if($content_style === 'ckeditor_light')-->{@ $css_content = '.xe_content.editable p { margin: 0;'. chr(125); }<!--@endif-->
Expand All @@ -23,8 +27,17 @@
{@ $css_content .= chr(125);}
<!--@endif-->

<!--@if($enable_autosave)-->
<input type="hidden" name="_saved_doc_title" value="{htmlspecialchars($saved_doc->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)}" />
<input type="hidden" name="_saved_doc_content" value="{htmlspecialchars($saved_doc->content, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)}" />
<input type="hidden" name="_saved_doc_document_srl" value="{$saved_doc->document_srl}" />
<input type="hidden" name="_saved_doc_message" value="{$lang->msg_load_saved_doc}" />
<!--@end-->

<div id="ckeditor_instance_{$editor_sequence}" data-editor-sequence="{$editor_sequence}" data-editor-primary-key-name="{$editor_primary_key_name}" data-editor-content-key-name="{$editor_content_key_name}" style="min-height:{$editor_height}px;"></div>

<p cond="$enable_autosave" class="editor_autosaved_message autosave_message" id="editor_autosaved_message_{$editor_sequence}">&nbsp;</p>

<block cond="$allow_fileupload">
<include target="file_upload.html" />
</block>
Expand Down
14 changes: 11 additions & 3 deletions modules/editor/skins/ckeditor/file_upload.html
Expand Up @@ -45,20 +45,28 @@
</div>

<script>
function reloadUploader(editor_sequence){
<!--@if($allow_fileupload)-->
$container = jQuery('#xefu-container-' + editor_sequence);
$container.data('instance').loadFilelist($container);
<!--@endif-->
}
<!--@if($allow_fileupload)-->
jQuery(function($){
// uploader
<!--@if($allow_fileupload)-->
var setting = {
maxFileSize: {$file_config->allowed_filesize},
limitMultiFileUploadSize: {$file_config->allowed_filesize}
};
var uploader = $('#xefu-container-{$editor_sequence}').xeUploader(setting);

$container = $('#xefu-container-{$editor_sequence}');
$container.data('instance',$container.xeUploader(setting));
window.xe.msg_exceeds_limit_size = '{$lang->msg_exceeds_limit_size}';
window.xe.msg_checked_file_is_deleted = '{$lang->msg_checked_file_is_deleted}';
window.xe.msg_file_cart_is_null = '{$lang->msg_file_cart_is_null}';
window.xe.msg_checked_file_is_deleted = '{$lang->msg_checked_file_is_deleted}';
window.xe.msg_not_allowed_filetype = '{$lang->msg_not_allowed_filetype}';
window.xe.msg_file_upload_error = '{$lang->msg_file_upload_error}';
<!--@endif-->
});
<!--@endif-->
</script>
48 changes: 48 additions & 0 deletions modules/editor/tpl/js/editor.app.js
@@ -1,3 +1,23 @@
function getCkFormInstance(editor_sequence)
{
var fo_obj = document.getElementById('ckeditor_instance_' + editor_sequence).parentNode;
while(fo_obj.nodeName != 'FORM') { fo_obj = fo_obj.parentNode; }
if(fo_obj.nodeName == 'FORM') return fo_obj;
return;
}

function getAutoSavedSrl(ret_obj, response_tags, c) {
var editor_sequence = ret_obj.editor_sequence;
var primary_key = ret_obj.key;
var fo_obj = getCkFormInstance(editor_sequence);

if(ret_obj.document_srl !== 0)
{
fo_obj[primary_key].value = ret_obj.document_srl;
reloadUploader(editor_sequence);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reloadUploader 가 정의되어 있지 않을 수도 있는 것 같아요.

}

(function($){
"use strict";
var default_ckeconfig = {
Expand Down Expand Up @@ -60,13 +80,38 @@
var $contentField = $form.find(opts.content_field);
var data = $containerEl.data();
var editor_sequence = $containerEl.data().editorSequence;
var primary_key = $containerEl.data().editorPrimaryKeyName;
var fo_obj = getCkFormInstance(editor_sequence);

this.ckeconfig = $.extend({}, default_ckeconfig, opts.ckeconfig || {});

this.editor_sequence = data.editorSequence;
$form.attr('editor_sequence', data.editorSequence);

if(CKEDITOR.env.mobile) CKEDITOR.env.isCompatible = true;

// saved document(자동저장 문서)에 대한 확인
if(typeof(fo_obj._saved_doc_title)!= "undefined") { ///<< _saved_doc_title field가 없으면 자동저장 하지 않음
var saved_title = fo_obj._saved_doc_title.value;
var saved_content = fo_obj._saved_doc_content.value;

if(saved_title || saved_content) {
// 자동저장된 문서 활용여부를 물은 후 사용하지 않는다면 자동저장된 문서 삭제
if(confirm(fo_obj._saved_doc_message.value)) {
if(typeof(fo_obj.title)!='undefined') fo_obj.title.value = saved_title;
$contentField.val(saved_content);

var param = [];
param.editor_sequence = editor_sequence;
param.primary_key = primary_key;
param.mid = current_mid;
var response_tags = new Array("error","message","editor_sequence","key","title","content","document_srl");
exec_xml('editor',"procEditorLoadSavedDocument", param, getAutoSavedSrl, response_tags);
} else {
editorRemoveSavedDoc();
}
}
}

var instance = CKEDITOR.appendTo($containerEl[0], {}, $contentField.val());

Expand Down Expand Up @@ -109,6 +154,9 @@
window.editorRelKeys[data.editorSequence].pasteHTML = function(text){
instance.insertHtml(text, 'html');
};

// 자동저장 필드가 있다면 자동 저장 기능 활성화
if(typeof(fo_obj._saved_doc_title)!="undefined" ) editorEnableAutoSave(fo_obj, editor_sequence);
},
getContent : function(seq) {
var self = this;
Expand Down