start export and import

This commit is contained in:
Mark Dermanov 2015-12-29 21:44:32 +03:00
parent ed4fda4651
commit 908508584f
2 changed files with 69 additions and 4 deletions

View file

@ -35,6 +35,7 @@ var ce = function(settings) {
/** Bind all events */
this.bindEvents();
};
// All posible tools
@ -80,11 +81,40 @@ ce.prototype.makeInterface = function () {
/** Insert Editor after initial textarea. Hide textarea */
this.resultTextarea.parentNode.insertBefore(wrapper, this.resultTextarea.nextSibling);
this.resultTextarea.hidden = true;
//this.resultTextarea.hidden = true;
this.focusNode(firstNode);
};
/*
* Экспорт разметки в итоговый текстареа
* пока по кнопке "экспорт", потом можно сделать на каждое изменение в редакторе (надо ли это?)
* */
ce.prototype.exportHtml = function () {
console.log("export");
this.resultTextarea.innerHTML = this.editableWrapper.innerHTML;
return false;
};
/*
* Импорт разметки из итоговой текстареа
* пока по кнопке "импорт", потом можно сделать на каждое изменение в редакторе (надо ли это?)
* */
ce.prototype.importHtml = function () {
console.log("importHtml");
//this.resultTextarea.innerHTML = this.editableWrapper.innerHTML;
return false;
};
/**
* All events binds in one place
*/
@ -93,6 +123,24 @@ ce.prototype.bindEvents = function () {
var _this = this,
selectedNodeClass = "selected";
/*
* Экспорт разметки в итоговый текстареа
* пока по кнопке "экспорт", потом можно сделать на каждое изменение в редакторе (надо ли это?)
* */
document.getElementById("export_html").addEventListener('click', function () {
_this.exportHtml.apply(_this)
});
/*
* Импорт разметки из итоговой текстареа
* пока по кнопке "импорт", потом можно сделать на каждое изменение в редакторе (надо ли это?)
* */
document.getElementById("import_html").addEventListener('click', function () {
_this.importHtml.apply(_this)
});
/** All keydowns on Window */
document.addEventListener('keydown', function (event) {
_this.globalKeydownCallback(event);
@ -106,7 +154,7 @@ ce.prototype.bindEvents = function () {
//event.target.classList.add(selectedNodeClass)
var sender = event.target
var sender = event.target;
if (sender.classList.contains("node") && !_this.toolbar.isOpened) {
console.log("hover", sender);
@ -197,6 +245,17 @@ ce.prototype.focusNode = function (node) {
}
};
/*
*
* */
ce.prototype.isTextSelected = function(){
//var sel = window.getSelection();
//debugger
return !!window.getSelection().toString()
}
/**
* All window keydowns handles here
*/
@ -213,6 +272,8 @@ ce.prototype.globalKeydownCallback = function (event) {
event.preventDefault();
//return
} else if (event.which == this.key.ENTER) {
// TODO process seleceted toolBtn
//insert new node or change type of current?
//and close toolbar
@ -402,7 +463,7 @@ ce.prototype.enterKeyPressed = function(event) {
var curNode = this.getFocusedNode();
if (curNode.dataset["type"] == "header") {
if (curNode.dataset["type"] == "header" && !this.isTextSelected()) {
var newNode = this.make.textNode();
/** Add node */

View file

@ -10,9 +10,13 @@
<h1>CodeX Editor</h1>
<button id="export_html">Экспорт</button>
<button id="import_html">Импорт</button>
<br>
<br>
<form action="">
<textarea name="" id="codex_editor" cols="30" rows="10"></textarea>
<textarea name="" id="codex_editor" cols="30" rows="10" style="width: 100%;height: 300px;"></textarea>
</form>