From 5faabf04bd498085fc7c7499dee45dced76b10a8 Mon Sep 17 00:00:00 2001 From: isqua Date: Sat, 7 Feb 2015 19:33:18 +0300 Subject: [PATCH] =?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 Элемент формы, на которой это произошло