diff --git a/package.json b/package.json
index a4e0d70..604ef09 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "bay-components",
- "version": "0.3.3",
+ "version": "0.3.4",
"description": "common functions for shanbay frontend projects",
"main": "lib/index.js",
"scripts": {
diff --git a/src/js/PullToLoadList.js b/src/js/PullToLoadList.js
index 0b9cf3a..76b9c4f 100644
--- a/src/js/PullToLoadList.js
+++ b/src/js/PullToLoadList.js
@@ -1,3 +1,4 @@
+/* global bayUtils */
const { ajax } = bayUtils;
export class PullToLoadList {
@@ -59,13 +60,21 @@ export class PullToLoadList {
if (container === window) {
const docRoot = document.documentElement;
- if (docRoot.scrollHeight - Math.ceil(window.scrollY || window.pageYOffset) - this.threshold <= docRoot.clientHeight) {
+ if (
+ docRoot.scrollHeight -
+ Math.ceil(window.scrollY || window.pageYOffset) -
+ this.threshold <=
+ docRoot.clientHeight
+ ) {
this.loadMoreData();
}
} else {
// reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
// Note: container 固定高 且 scroll
- if (container.scrollHeight - Math.ceil(container.scrollTop) - this.threshold <= container.clientHeight) {
+ if (
+ container.scrollHeight - Math.ceil(container.scrollTop) - this.threshold <=
+ container.clientHeight
+ ) {
this.loadMoreData();
}
}
@@ -118,7 +127,7 @@ export class PullToLoadList {
ajax({
url,
type: 'GET',
- success: (data) => {
+ success: data => {
const parsedData = this.parseData(data);
this.$loadHint.hide();
this.items = parsedData.items;
diff --git a/src/js/comment.js b/src/js/comment.js
index 29127cf..58dc699 100644
--- a/src/js/comment.js
+++ b/src/js/comment.js
@@ -1,3 +1,4 @@
+/* global bayUtils */
const { merge, ajax, formatDate } = bayUtils;
class Comment {
@@ -55,13 +56,15 @@ class Comment {
updateLikeStatus(status) {
const { comment, buildLikeApiData } = this.options;
- ajax(merge(buildLikeApiData({ vote: status, commentId: comment.id }), {
- type: 'PUT',
- data: { vote: status },
- success: () => {
- this.changeLikeStatus(status);
- },
- }));
+ ajax(
+ merge(buildLikeApiData({ vote: status, commentId: comment.id }), {
+ type: 'PUT',
+ data: { vote: status },
+ success: () => {
+ this.changeLikeStatus(status);
+ },
+ }),
+ );
}
// 改变喜欢/不喜欢状态
@@ -89,7 +92,7 @@ class Comment {
this.$toggleDislikeBtn.addClass('disable');
this.$toggleDislikeBtn.html('已不喜欢');
if (isVotedUp) {
- $voteNum.html((voteNum - 1) || '');
+ $voteNum.html(voteNum - 1 || '');
}
}
@@ -98,7 +101,7 @@ class Comment {
this.$toggleDislikeBtn.removeClass('disable');
this.$toggleDislikeBtn.html('不喜欢');
if (isVotedUp) {
- $voteNum.html((voteNum - 1) || '');
+ $voteNum.html(voteNum - 1 || '');
}
}
}
@@ -126,8 +129,14 @@ class Comment {
// 渲染
render() {
const {
- $el, comment, currentUser, isInteractiveDisabled,
- hasLikeBtn, hasDislikeBtn, hasNestReplyBtn, hasReportBtn,
+ $el,
+ comment,
+ currentUser,
+ isInteractiveDisabled,
+ hasLikeBtn,
+ hasDislikeBtn,
+ hasNestReplyBtn,
+ hasReportBtn,
} = this.options;
const data = comment;
const user = data.user || {};
@@ -143,47 +152,60 @@ class Comment {
- ${currentUser.user_id_str === user.id && !isInteractiveDisabled ?
- `
` :
- ''
+ />`
+ : ''
}
- ${hasLikeBtn ?
- `
+ ${
+ hasLikeBtn
+ ? `
${data.vote_score || ''}
-
` :
- ''
+
`
+ : ''
}
- ${(hasDislikeBtn || hasNestReplyBtn || hasReportBtn) && !isInteractiveDisabled ?
- `
+ ${
+ (hasDislikeBtn || hasNestReplyBtn || hasReportBtn) &&
+ !isInteractiveDisabled
+ ? `
…
- ${hasDislikeBtn ?
- `
+ ${
+ hasDislikeBtn
+ ? `
${data.is_voted_down ? '已不喜欢' : '不喜欢'}
- ` :
- ''
+ `
+ : ''
}
- ${hasNestReplyBtn ?
- `
回复` :
- ''
+ >回复`
+ : ''
}
- ${hasReportBtn ?
- `
举报 ` :
- ''
+ href="/web/report?report_url=${encodeURIComponent(
+ data.report_url,
+ )}&next=${encodeURIComponent(window.location.href)}"
+ > 举报 `
+ : ''
}
-
` :
- ''
+
`
+ : ''
}
diff --git a/src/js/comments.js b/src/js/comments.js
index 461347e..3fe8ea3 100644
--- a/src/js/comments.js
+++ b/src/js/comments.js
@@ -1,6 +1,8 @@
-const { merge, ajax } = bayUtils;
+/* global bayUtils bayComponents */
import comment from './comment';
+const { merge, ajax } = bayUtils;
+
class Comments {
constructor(options) {
this.options = merge(options, {
@@ -104,37 +106,49 @@ class Comments {
// 更新评论
if (this.editingComment.id) {
- ajax(merge(buildCommentApiData({
- commentId: this.editingComment.id,
- content,
- }), {
- type: 'PUT',
- success: this.render,
- }));
+ ajax(
+ merge(
+ buildCommentApiData({
+ commentId: this.editingComment.id,
+ content,
+ }),
+ {
+ type: 'PUT',
+ success: this.render,
+ },
+ ),
+ );
return;
}
// 回复评论
if (this.toUserId) {
- ajax(merge(buildCommentApiData({
- to_user_id: this.toUserId,
- content,
- }), {
- url: apiUrl,
- type: 'POST',
- success: this.render,
- }));
+ ajax(
+ merge(
+ buildCommentApiData({
+ to_user_id: this.toUserId,
+ content,
+ }),
+ {
+ url: apiUrl,
+ type: 'POST',
+ success: this.render,
+ },
+ ),
+ );
return;
}
// 添加评论
- ajax(merge(buildCommentApiData({ content }), {
- url: apiUrl,
- type: 'POST',
- success: this.render,
- }));
+ ajax(
+ merge(buildCommentApiData({ content }), {
+ url: apiUrl,
+ type: 'POST',
+ success: this.render,
+ }),
+ );
}
// 显示输入页面
@@ -149,7 +163,10 @@ class Comments {
}
this.$commentInputBox.show();
- this.$commentInputBox.find('input').val(this.editingComment.content || '').focus();
+ this.$commentInputBox
+ .find('input')
+ .val(this.editingComment.content || '')
+ .focus();
return false;
}
@@ -164,9 +181,14 @@ class Comments {
// 渲染单个评论
renderComment(data) {
- comment(merge({
- comment: this.options.parseItemData(data),
- }, this.options));
+ comment(
+ merge(
+ {
+ comment: this.options.parseItemData(data),
+ },
+ this.options,
+ ),
+ );
}
renderEmptyBlock() {
@@ -205,6 +227,7 @@ class Comments {
$el.html('');
this.isCreating = false;
+ // eslint-disable-next-line no-new
new bayComponents.PullToLoadList({
ipp: this.options.ipp,
pageNum: this.options.pageNum,
@@ -214,7 +237,7 @@ class Comments {
renderItem: this.renderComment,
parseData: this.options.parseData,
- onLoadedFirstPage: (data) => {
+ onLoadedFirstPage: data => {
const commentsData = parseData(data);
let commentData = {
user: {},
diff --git a/src/js/tabs.js b/src/js/tabs.js
index a8e8179..3ca9cf8 100644
--- a/src/js/tabs.js
+++ b/src/js/tabs.js
@@ -1,3 +1,4 @@
+/* global bayUtils */
const { merge } = bayUtils;
/*