Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
initialize daumeditor using a template
Browse files Browse the repository at this point in the history
  • Loading branch information
simonz committed Apr 9, 2013
1 parent 3908a72 commit 0456911
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 40 deletions.
3 changes: 2 additions & 1 deletion build.xml
Expand Up @@ -3,6 +3,7 @@
<property file="build.properties"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${build.lib.antcontrib}" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${build.lib.antcontrib}"/>
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" classpath="${build.lib.gcuploader}" name="gcupload"/>
<!-- main tasks ====================================================== -->
<target name="buildall" description="clean and build all" depends="clean, packaging">
</target>
Expand Down Expand Up @@ -39,7 +40,6 @@
<trycatch>
<try>
<property file="${user.home}/daumeditor.credentials.properties"/>
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" classpath="${build.lib.gcuploader}" name="gcupload"/>
<gcupload username="${gc.username}" password="${gc.password}" projectname="daumopeneditor" filename="${build.dist.dir}/daumeditor.zip" targetfilename="daumeditor-${editor.version}.zip" summary="${editor.version} release zip file" verbose="true"/>
</try>
<catch>
Expand Down Expand Up @@ -81,6 +81,7 @@
<copy todir="${build.target.js.merged.dir}" overwrite="true">
<fileset dir="${src.editor.js.dir}">
<include name="editor_loader.js"/>
<include name="editor_creator.js"/>
<include name="**/async/"/>
</fileset>
</copy>
Expand Down
93 changes: 93 additions & 0 deletions daumeditor/converting.html
@@ -0,0 +1,93 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Daum Editor - Demo</title>
<link rel="stylesheet" href="css/editor.css" type="text/css" charset="utf-8"/>
</head>
<body>
<div class="body">
<form name="tx_editor_form" id="tx_editor_form" action="http://posttestserver.com/post.php" method="post"
accept-charset="utf-8">
<textarea name="content" id="content" style="width: 100%; height: 490px;"></textarea>
</form>
</div>
<div>
<button onclick="saveContent()">Submit Content</button>
</div>
<script src="js/editor_loader.js" type="text/javascript" charset="utf-8"></script>
<script src="js/editor_creator.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var config = {
initializedId: "",
wrapper: "tx_trex_container",
form: 'tx_editor_form',
txIconPath: "images/icon/editor/",
txDecoPath: "images/deco/contents/",
events: {
preventUnload: false
},
sidebar: {
attachbox: {
show: true
}
}
};

EditorCreator.convert(document.getElementById("content"), 'pages/template/simple.html', function () {
EditorJSLoader.ready(function (Editor) {
new Editor(config);
Editor.modify({
content: '<p>Hello</p>'
});
});
});

</script>

<script type="text/javascript">
function saveContent() {
Editor.save();
}

function validForm(editor) {
var validator = new Trex.Validator();
var content = editor.getContent();
if (!validator.exists(content)) {
alert('Content is empty');
return false;
}

return true;
}

function setForm(editor) {
var i, input;
var form = editor.getForm();
var content = editor.getContent();

var field = document.getElementById("content");
field.value = content;

var images = editor.getAttachments('image');
for (i = 0; i < images.length; i++) {
input = document.createElement('input');
input.type = 'hidden';
input.name = 'attach_image';
input.value = images[i].data.imageurl;
form.createField(input);
}

var files = editor.getAttachments('file');
for (i = 0; i < files.length; i++) {
input = document.createElement('input');
input.type = 'hidden';
input.name = 'attach_file';
input.value = files[i].data.attachurl;
form.createField(input);
}
return true;
}
</script>
</body>
</html>
76 changes: 37 additions & 39 deletions daumeditor/editor.html
Expand Up @@ -537,46 +537,44 @@
* @returns {Boolean} 정상적인 경우에 true
*/
function setForm(editor) {
var formGenerator = editor.getForm();
var content = editor.getContent();
formGenerator.createField(
tx.textarea({
'name': "tx_content", // 본문 내용을 필드를 생성하여 값을 할당하는 부분
'style': { 'display': "none" }
}, content)
);
/* 아래의 코드는 첨부된 데이터를 필드를 생성하여 값을 할당하는 부분으로 상황에 맞게 수정하여 사용한다.
첨부된 데이터 중에 주어진 종류(image,file..)에 해당하는 것만 배열로 넘겨준다. */
var images = editor.getAttachments('image');
for (var i = 0, len = images.length; i < len; i++) {
// existStage는 현재 본문에 존재하는지 여부
if (images[i].existStage) {
// data는 팝업에서 execAttach 등을 통해 넘긴 데이터
alert('attachment information - image[' + i + '] \r\n' + JSON.stringify(images[i].data));
formGenerator.createField(
tx.input({
'type': "hidden",
'name': 'tx_attach_image',
'value': images[i].data.imageurl // 예에서는 이미지경로만 받아서 사용
})
);
}
}
var files = editor.getAttachments('file');
for (var i = 0, len = files.length; i < len; i++) {
alert('attachment information - file[' + i + '] \r\n' + JSON.stringify(files[i].data));
formGenerator.createField(
tx.input({
'type': "hidden",
'name': 'tx_attach_file',
'value': files[i].data.attachurl
})
);
}
return true;
var i, input;
var form = editor.getForm();
var content = editor.getContent();

// 본문 내용을 필드를 생성하여 값을 할당하는 부분
var textarea = document.createElement('textarea');
textarea.name = 'content';
textarea.value = content;
form.createField(textarea);

/* 아래의 코드는 첨부된 데이터를 필드를 생성하여 값을 할당하는 부분으로 상황에 맞게 수정하여 사용한다.
첨부된 데이터 중에 주어진 종류(image,file..)에 해당하는 것만 배열로 넘겨준다. */
var images = editor.getAttachments('image');
for (i = 0; i < images.length; i++) {
// existStage는 현재 본문에 존재하는지 여부
if (images[i].existStage) {
// data는 팝업에서 execAttach 등을 통해 넘긴 데이터
alert('attachment information - image[' + i + '] \r\n' + JSON.stringify(images[i].data));
input = document.createElement('input');
input.type = 'hidden';
input.name = 'attach_image';
input.value = images[i].data.imageurl; // 예에서는 이미지경로만 받아서 사용
form.createField(input);
}
}

var files = editor.getAttachments('file');
for (i = 0; i < files.length; i++) {
input = document.createElement('input');
input.type = 'hidden';
input.name = 'attach_file';
input.value = files[i].data.attachurl;
form.createField(input);
}
return true;
}
</script>
<p><button onclick='saveContent()'>SAMPLE - submit contents</button></p>
<div><button onclick='saveContent()'>SAMPLE - submit contents</button></div>
<!-- End: Saving Contents -->

<!-- Sample: Loading Contents -->
Expand Down Expand Up @@ -626,7 +624,7 @@
});
}
</script>
<p><button onclick='loadContent()'>SAMPLE - load contents to editor</button></p>
<div><button onclick='loadContent()'>SAMPLE - load contents to editor</button></div>
<!-- End: Loading Contents -->

</body>
Expand Down
18 changes: 18 additions & 0 deletions daumeditor/js/editor_creator.js
@@ -0,0 +1,18 @@
var EditorCreator = {
convert: function (el, template, callback) {
if (!el || !template || !$tom) return;

$tom.applyStyles(el, {display: 'none'});
Trex.I.XHRequester.sendRequest('get',
template,
'',
false,
function (html) {
var root = document.createElement('div');
root.innerHTML = html;
$tom.insertNext(root, el);
callback && callback();
}
);
}
};

0 comments on commit 0456911

Please sign in to comment.