improve scripts and styles

parent c4bc37e2
...@@ -28,6 +28,8 @@ ETYPOS.prototype = { ...@@ -28,6 +28,8 @@ ETYPOS.prototype = {
selection: '', selection: '',
needConstructPanel: true,
element: null, element: null,
/* Переменные для перетаскивания */ /* Переменные для перетаскивания */
...@@ -67,6 +69,9 @@ ETYPOS.prototype = { ...@@ -67,6 +69,9 @@ ETYPOS.prototype = {
// Создает контейнер и добавляет его в конец body // Создает контейнер и добавляет его в конец body
_createControlPanel: function () { _createControlPanel: function () {
if ( !this.needConstructPanel ) {
return;
}
/* Main div */ /* Main div */
var div = document.createElement("div"); var div = document.createElement("div");
...@@ -90,9 +95,10 @@ ETYPOS.prototype = { ...@@ -90,9 +95,10 @@ ETYPOS.prototype = {
var comment = document.createElement("input"); var comment = document.createElement("input");
comment.className = "e_typos_comment"; comment.className = "e_typos_comment";
comment.type = "text"; comment.type = "text";
comment.size = 19; comment.size = 30;
comment.maxlength = 50; comment.maxlength = 50;
comment.placeholder = "Обязательно для заполнения"; comment.placeholder = "Обязательно для заполнения";
comment.autofocus = true;
var nobr = document.createElement("nobr"); var nobr = document.createElement("nobr");
var nobrText = document.createTextNode("Исправленный вариант: "); var nobrText = document.createTextNode("Исправленный вариант: ");
...@@ -134,6 +140,8 @@ ETYPOS.prototype = { ...@@ -134,6 +140,8 @@ ETYPOS.prototype = {
document.body.appendChild(div); document.body.appendChild(div);
this.element = document.querySelector(".e_typos_div"); this.element = document.querySelector(".e_typos_div");
this.needConstructPanel = false;
}, },
// Нужны для onmousemove // Нужны для onmousemove
...@@ -162,10 +170,28 @@ ETYPOS.prototype = { ...@@ -162,10 +170,28 @@ ETYPOS.prototype = {
return; return;
} }
document.querySelector('.e_typos_text').innerHTML = self.selection.trim(); if ( self.needConstructPanel ) {
self.controlPanel(); self.controlPanel();
} }
self.openWindow();
var comment = document.querySelector('.e_typos_comment');
var text = document.querySelector('.e_typos_text');
var selection = self.selection.trim();
text.innerHTML = selection;
self.userdata['text'] = selection;
if ( !self.validateTextData() ) {
self.printMessage('error', self.error);
} else {
comment.value = selection;
}
comment.focus();
return false;
}
}; };
this.element.addEventListener("mousedown", function (e) { this.element.addEventListener("mousedown", function (e) {
...@@ -272,6 +298,20 @@ ETYPOS.prototype = { ...@@ -272,6 +298,20 @@ ETYPOS.prototype = {
this.isVisible = false; this.isVisible = false;
}, },
validateTextData: function() {
if (!this.userdata['text']) {
this.error = this.language[this.default_language]['error_text'];
return false;
}
if (this.userdata['text'].length < 5 || this.userdata['text'].length > 30) {
this.error = "Выделенный текст должен быть длиной от 5 до 30 символов (сейчас: " + this.userdata['text'].length + ")";
return false;
}
return true;
},
/*Проверка данных перед отправкой*/ /*Проверка данных перед отправкой*/
validateData: function () { validateData: function () {
if (typeof (this.userdata) !== 'object') { if (typeof (this.userdata) !== 'object') {
...@@ -288,8 +328,7 @@ ETYPOS.prototype = { ...@@ -288,8 +328,7 @@ ETYPOS.prototype = {
this.userdata['language'] = this.default_language; this.userdata['language'] = this.default_language;
} }
if (!this.userdata['text']) { if ( !this.validateTextData() ) {
this.error = this.language[this.default_language]['error_text'];
return false; return false;
} }
...@@ -301,11 +340,6 @@ ETYPOS.prototype = { ...@@ -301,11 +340,6 @@ ETYPOS.prototype = {
return false; return false;
} }
if (this.userdata['text'].length < 5 || this.userdata['text'].length > 30) {
this.error = "Выделенный текст должен быть длиной от 5 до 30 символов (сейчас: " + this.userdata['text'].length + ")";
return false;
}
if (this.userdata['comment'].length > 30) { if (this.userdata['comment'].length > 30) {
this.error = "Комментарий должен быть длиной до 30 символов (сейчас: " + this.userdata['comment'].length + ")"; this.error = "Комментарий должен быть длиной до 30 символов (сейчас: " + this.userdata['comment'].length + ")";
return false; return false;
...@@ -317,7 +351,6 @@ ETYPOS.prototype = { ...@@ -317,7 +351,6 @@ ETYPOS.prototype = {
/*Сбор данных*/ /*Сбор данных*/
postData: function () { postData: function () {
this.userdata['url'] = window.location.href; this.userdata['url'] = window.location.href;
this.userdata['text'] = this.selection.trim();
this.userdata['comment'] = (document.querySelector(".e_typos_div .e_typos_comment")) ? document.querySelector(".e_typos_div .e_typos_comment").value : ''; this.userdata['comment'] = (document.querySelector(".e_typos_div .e_typos_comment")) ? document.querySelector(".e_typos_div .e_typos_comment").value : '';
this.userdata['comment'] = this.userdata['comment'].trim(); this.userdata['comment'] = this.userdata['comment'].trim();
......
...@@ -93,3 +93,9 @@ ...@@ -93,3 +93,9 @@
color: red; color: red;
font-size: 110%; font-size: 110%;
} }
.e_typos_comment {
display: block;
margin: 0 auto;
margin-top: 10px;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment