From ec6eb34e22db0d7102b2ad23cecf59d799dabe81 Mon Sep 17 00:00:00 2001 From: isqua Date: Sat, 7 Feb 2015 19:03:24 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9D=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B9,=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=81=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D1=88=D0=BB=D0=BE=20{"error":"SomeError"}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/modules/ajax-comments.js | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/chrome_point_plus/modules/ajax-comments.js b/chrome_point_plus/modules/ajax-comments.js index 5397d2a..b53cbb2 100644 --- a/chrome_point_plus/modules/ajax-comments.js +++ b/chrome_point_plus/modules/ajax-comments.js @@ -139,21 +139,25 @@ AjaxCommentProcessor.prototype.onSuccess = function(data, textStatus) { var $textarea = this._$textarea; if (textStatus === 'success') { - this.hideForm(); - - // Creating the comment HTML - create_comment_elements({ - id: data.comment_id, - toId: this._commentId || null, - postId: this._postId, - author: $('#name h1').text(), - text: this._text, - fadeOut: true - }, this.insertComment.bind(this)); + if (data.error) { + this.onError(null, null, data.error); + } else { + // Creating the comment HTML + create_comment_elements({ + id: data.comment_id, + toId: this._commentId || null, + postId: this._postId, + author: $('#name h1').text(), + text: this._text, + fadeOut: true + }, this.insertComment.bind(this)); - // Cleaning textarea - $textarea.val(''); - this.setProgress(false); + this.hideForm(); + + // Cleaning textarea + $textarea.val(''); + this.setProgress(false); + } } }; From 5faabf04bd498085fc7c7499dee45dced76b10a8 Mon Sep 17 00:00:00 2001 From: isqua Date: Sat, 7 Feb 2015 19:33:18 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9E=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B0=D1=8F=D0=BA=D1=81=D0=BE=D0=BC,=20=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D0=BD=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/modules/ajax-comments.js | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/chrome_point_plus/modules/ajax-comments.js b/chrome_point_plus/modules/ajax-comments.js index b53cbb2..640cf60 100644 --- a/chrome_point_plus/modules/ajax-comments.js +++ b/chrome_point_plus/modules/ajax-comments.js @@ -38,12 +38,25 @@ AjaxComments.prototype.listenFirstComments = function() { */ AjaxComments.prototype.onSubmit = function(event) { var $form = $(event.target); - var proc; event.preventDefault(); event.stopPropagation(); if ($form.hasClass('reply-form')) { + this.submit($form); + } +}; + +/** + * Проверяет, выбран ли файл. Если да — отправляет форму с перезагрузкой, иначе — аяксом  + * @param {jQuery} $form Элемент формы + */ +AjaxComments.prototype.submit = function($form) { + var proc; + + if (this.isFileSelected($form)) { + $form.submit(); + } else { proc = new AjaxCommentProcessor($form); } }; @@ -63,7 +76,7 @@ AjaxComments.prototype.onKeypress = function(event) { $form = $(event.target).closest('.reply-form'); if ($form.length) { - proc = new AjaxCommentProcessor($form); + this.submit($form); } } }; @@ -77,6 +90,16 @@ AjaxComments.prototype.isProperKeys = function(event) { return (event.keyCode === 10 || event.keyCode === 13) && (event.ctrlKey || event.metaKey); }; +/** + * @param {jQuery} $form + * @return {Boolean} Выбран ли файл + */ +AjaxComments.prototype.isFileSelected = function($form) { + var files = $form.get(0).elements.attach.files; + + return Boolean(files && files.length); +}; + /** * Создаётся при каждой отправке комментария * @param {jQuery} $form Элемент формы, на которой это произошло