From 4e6d09a774d48e5bf678e4104307b96972ba7081 Mon Sep 17 00:00:00 2001 From: isqua Date: Sun, 8 Feb 2015 21:01:27 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=BE=D0=BC=D0=B5=D0=BD=D1=8F=D1=82?= =?UTF-8?q?=D1=8C=20url=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D1=8F;=20Fixes?= =?UTF-8?q?=20#87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/modules/ajax-comments.js | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/chrome_point_plus/modules/ajax-comments.js b/chrome_point_plus/modules/ajax-comments.js index c4c940c..d0bddbd 100644 --- a/chrome_point_plus/modules/ajax-comments.js +++ b/chrome_point_plus/modules/ajax-comments.js @@ -48,7 +48,7 @@ AjaxComments.prototype.onSubmit = function(event) { }; /** - * Проверяет, выбран ли файл. Если да — отправляет форму с перезагрузкой, иначе — аяксом  + * Проверяет, выбран ли файл. Если да — отправляет форму с перезагрузкой, иначе — аяксом * @param {jQuery} $form Элемент формы */ AjaxComments.prototype.submit = function($form) { @@ -67,8 +67,7 @@ AjaxComments.prototype.submit = function($form) { */ AjaxComments.prototype.onKeypress = function(event) { var $form; - var proc; - + if (this.isProperKeys(event)) { event.preventDefault(); event.stopPropagation(); @@ -116,12 +115,19 @@ function AjaxCommentProcessor($form) { this._text = this._$textarea.val(); this._CSRF = $form.get(0).elements.csrf_token.value; + this._actionUrl = this._$form.attr('action'); this._postId = this._$post.data('id'); this._commentId = this._$post.data('comment-id'); this.sendComment(); } +/** + * Регулярка для урла, проверяюшая, не рекомендация ли это + * @type {RegExp} + */ +AjaxCommentProcessor.recommendationReg = /^\/[^/]*\/r$/; + /** * Отправляет комментарий */ @@ -130,7 +136,7 @@ AjaxCommentProcessor.prototype.sendComment = function() { $.ajax({ type: 'POST', - url: '/api/post' + this._$form.attr('action'), + url: this.getUrl(), data: { text: this._text, comment_id: this._commentId @@ -141,6 +147,25 @@ AjaxCommentProcessor.prototype.sendComment = function() { }); }; +/** + * @return {Boolean} true — это коммент-рекомендация, fasle — обычный коммент + */ +AjaxCommentProcessor.prototype.isRecommendation = function() { + return this._isRec || (this._isRec = this.constructor.recommendationReg.test(this._actionUrl)); +}; + +/** + * @return {String} Адрес, на который слать запрос + */ +AjaxCommentProcessor.prototype.getUrl = function() { + // Если это рекомендация комментария + if (this.isRecommendation() && this._commentId) { + return '/api/post/' + this._postId + '/' + this._commentId + '/r'; + } else { + return '/api/post' + this._actionUrl; + } +}; + /** * Подкладывает CSRF-токен в заголовки запроса * @param {XMLHttpRequest} xhr Объект запроса @@ -181,6 +206,7 @@ AjaxCommentProcessor.prototype.onSuccess = function(data, textStatus) { }; AjaxCommentProcessor.prototype.createComment = function(data) { + /* global create_comment_elements */ create_comment_elements({ id: data.comment_id, toId: this._commentId || null, @@ -236,6 +262,7 @@ AjaxCommentProcessor.prototype.showComment = function($comment) { * @param {String} error */ AjaxCommentProcessor.prototype.onError = function(req, status, error) { + /* global alert */ alert(chrome.i18n.getMessage('msg_comment_send_failed') + '\n' + error); this.setProgress(false); @@ -243,7 +270,7 @@ AjaxCommentProcessor.prototype.onError = function(req, status, error) { /** * Устанавливает прогресс - * @param {Boolean} isProgress true — включить прогресс, false — отключить + * @param {Boolean} isProgress true — включить прогресс, false — отключить */ AjaxCommentProcessor.prototype.setProgress = function(isProgress) { this._$textarea.prop('disabled', isProgress); From d45df7d6294c08128ca41d7d73a2b571d3a9d720 Mon Sep 17 00:00:00 2001 From: isqua Date: Sun, 8 Feb 2015 21:15:29 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=92=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D1=81=D0=BE=D0=B1=D1=81=D1=82=D0=B2=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B9-=D1=80=D0=B5=D0=BA=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B4=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BA=D0=B0=D0=BA=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B9-=D1=80=D0=B5=D0=BA=D0=BE=D0=BC=D0=B5=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E;=20Fixes=20#85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/modules/ajax-comments.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chrome_point_plus/modules/ajax-comments.js b/chrome_point_plus/modules/ajax-comments.js index d0bddbd..d37d86d 100644 --- a/chrome_point_plus/modules/ajax-comments.js +++ b/chrome_point_plus/modules/ajax-comments.js @@ -213,7 +213,8 @@ AjaxCommentProcessor.prototype.createComment = function(data) { postId: this._postId, author: $('#name h1').text(), text: this._text, - fadeOut: true + fadeOut: true, + isRec: this.isRecommendation() }, this.insertComment.bind(this)); }; From af70f93ec02cf0c2efbea99602f71f6a348315e0 Mon Sep 17 00:00:00 2001 From: isqua Date: Sun, 8 Feb 2015 22:03:39 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B8=20=D1=83=D1=81?= =?UTF-8?q?=D0=BF=D0=B5=D1=88=D0=BD=D0=BE=D0=B9=20=D1=80=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B1=D0=B5?= =?UTF-8?q?=D0=B7=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D1=8F;=20Fixes=20#86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/_locales/en/messages.json | 3 ++ chrome_point_plus/_locales/ru/messages.json | 3 ++ chrome_point_plus/js/point-plus.js | 3 ++ chrome_point_plus/modules/ajax-comments.css | 27 ++++++++++++++++ chrome_point_plus/modules/ajax-comments.js | 36 +++++++++++++++++++-- 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 chrome_point_plus/modules/ajax-comments.css diff --git a/chrome_point_plus/_locales/en/messages.json b/chrome_point_plus/_locales/en/messages.json index 33fefce..7f0e1e0 100644 --- a/chrome_point_plus/_locales/en/messages.json +++ b/chrome_point_plus/_locales/en/messages.json @@ -188,5 +188,8 @@ }, "msg_saving_post_draft":{ "message": "Saving the post..." + }, + "msg_success_recommendation": { + "message": "is recommended" } } diff --git a/chrome_point_plus/_locales/ru/messages.json b/chrome_point_plus/_locales/ru/messages.json index bebbf51..3a9226b 100644 --- a/chrome_point_plus/_locales/ru/messages.json +++ b/chrome_point_plus/_locales/ru/messages.json @@ -189,5 +189,8 @@ }, "msg_saving_post_draft":{ "message": "Сохранение поста..." + }, + "msg_success_recommendation": { + "message": "рекомендовано" } } diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index 17e1c9e..e818290 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -503,6 +503,9 @@ function PointPlus(ppVersion) { if (options.is('option_ajax')) { // Comments if (options.is('option_ajax_comments')) { + messenger.css({ + file: 'modules/ajax-comments.css' + }); messenger.js({ file: 'modules/ajax-comments.js' }, function() { diff --git a/chrome_point_plus/modules/ajax-comments.css b/chrome_point_plus/modules/ajax-comments.css new file mode 100644 index 0000000..b6d045d --- /dev/null +++ b/chrome_point_plus/modules/ajax-comments.css @@ -0,0 +1,27 @@ +.pp-notification { + display: block; + position: fixed; + top: 40px; + right: 40px; + padding: 20px; + border-radius: 2px; + font-size: 15px; + line-height: 20px; + transition: all 10s ease-in; + color: #fff; +} + +.pp-notification a, +.pp-notification a:visited, { + color: #fff; + text-decoration: none; + font-weight: bold; +} + +.pp-notification-success { + background: #4CAF50; +} + +.pp-notification.pp-fade { + opacity: 0; +} diff --git a/chrome_point_plus/modules/ajax-comments.js b/chrome_point_plus/modules/ajax-comments.js index d37d86d..9982994 100644 --- a/chrome_point_plus/modules/ajax-comments.js +++ b/chrome_point_plus/modules/ajax-comments.js @@ -194,8 +194,11 @@ AjaxCommentProcessor.prototype.onSuccess = function(data, textStatus) { if (data.error) { this.onError(null, null, data.error); } else { - this.createComment(data); - + if (this.isRecommendation() && this._text.trim().length === 0) { + this.showSuccessRecommendation(); + } else { + this.createComment(data); + } this.hideForm(); // Cleaning textarea @@ -277,3 +280,32 @@ AjaxCommentProcessor.prototype.setProgress = function(isProgress) { this._$textarea.prop('disabled', isProgress); this._$form.toggleClass('pp-progress', isProgress); }; + +AjaxCommentProcessor.prototype.getRecommendationLink = function() { + var url = '//point.im/' + this._postId; + var text = '#' + this._postId; + + if (this._commentId) { + url += '#' + this._commentId; + text += '/' + this._commentId; + } + + return '' + text + ''; +}; + +AjaxCommentProcessor.prototype.showSuccessRecommendation = function() { + var $notification = $('
') + .addClass('pp-notification pp-notification-success'); + + $notification.html(this.getRecommendationLink() + ' ' + chrome.i18n.getMessage('msg_success_recommendation')); + + $notification.on('transitionend', function() { + $notification.remove(); + }); + + $('body').append($notification); + + window.requestAnimationFrame(function() { + $notification.addClass('pp-fade'); + }); +};