...
|
...
|
@@ -2,15 +2,6 @@ |
|
|
* 评论及登录插件
|
|
|
* author:liuyue
|
|
|
* date:2015-01-07
|
|
|
<<<<<<< HEAD
|
|
|
*/
|
|
|
var $ = require("jquery"),
|
|
|
validate = require("./validate"),
|
|
|
box = require("./box"),
|
|
|
tools = require("yoho-tools"),
|
|
|
tips = require("./tips");
|
|
|
mustache = require("mustache");
|
|
|
=======
|
|
|
*/
|
|
|
var $ = require("jquery"),
|
|
|
validate = require("./validate"),
|
...
|
...
|
@@ -18,12 +9,10 @@ var $ = require("jquery"), |
|
|
tools = require("yoho-tools"),
|
|
|
tips = require("./tips");
|
|
|
mustache = require("mustache");
|
|
|
>>>>>>> develop
|
|
|
|
|
|
require("./login");
|
|
|
|
|
|
(function(global, undefined) {
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
var Comment = function(element, options) {
|
|
|
this.options = options;
|
|
|
this.$element = $(element);
|
...
|
...
|
@@ -38,18 +27,18 @@ require("./login"); |
|
|
publishUrl: '/writer/default/publish',
|
|
|
deleteUrl: '/writer/default/delete',
|
|
|
commentNum: $(".comment-num"),
|
|
|
commentItemTpl: '<li class="clearfix">'+
|
|
|
'<div class="userimg">'+
|
|
|
'<img src="\{{userimg}}" alt="">'+
|
|
|
'<i class="\{{partnerType}}"></i>'+
|
|
|
'</div>'+
|
|
|
'<div class="userinfo">'+
|
|
|
'<h6>\{{username}}</h6> '+
|
|
|
'<p class="comment-text">\{{content}}</p>'+
|
|
|
'\{{# isSelf}}'+
|
|
|
'<a class="delete-comment" href="javascript:;" pid="{{id}}"></a>'+
|
|
|
'\{{/ isSelf}} '+
|
|
|
'</div>'+
|
|
|
commentItemTpl: '<li class="clearfix">' +
|
|
|
'<div class="userimg">' +
|
|
|
'<img src="\{{userimg}}" alt="">' +
|
|
|
'<i class="\{{partnerType}}"></i>' +
|
|
|
'</div>' +
|
|
|
'<div class="userinfo">' +
|
|
|
'<h6>\{{username}}</h6> ' +
|
|
|
'<p class="comment-text">\{{content}}</p>' +
|
|
|
'\{{# isSelf}}' +
|
|
|
'<a class="delete-comment" href="javascript:;" pid="{{id}}"></a>' +
|
|
|
'\{{/ isSelf}} ' +
|
|
|
'</div>' +
|
|
|
'</li>',
|
|
|
thirdLogin: false,
|
|
|
isEdit: false,
|
...
|
...
|
@@ -61,7 +50,7 @@ require("./login"); |
|
|
Comment.prototype = {
|
|
|
constructor: Comment,
|
|
|
|
|
|
init:function() {
|
|
|
init: function() {
|
|
|
// 组件的创建主函数。
|
|
|
this._creat();
|
|
|
},
|
...
|
...
|
@@ -78,26 +67,26 @@ require("./login"); |
|
|
this._bindEvent();
|
|
|
},
|
|
|
|
|
|
_creatCommentDom:function() {
|
|
|
_creatCommentDom: function() {
|
|
|
var that = this;
|
|
|
//var id = {id:this.options.cid};
|
|
|
$.ajax({
|
|
|
type:'GET',
|
|
|
url:YohoConfig.mainUrl + this.options.commentPageUrl,
|
|
|
type: 'GET',
|
|
|
url: YohoConfig.mainUrl + this.options.commentPageUrl,
|
|
|
/*data: id,
|
|
|
dataType:'json',*/
|
|
|
success:function(response) {
|
|
|
success: function(response) {
|
|
|
var data = response.data, //返回数据的data
|
|
|
viewMoreNum = data.total - 5, //评论总数-5,除显示评论剩下的评论数量
|
|
|
moreString = viewMoreNum + '', //剩余评论数量转为字符串
|
|
|
moreFirstnum = moreString.slice(0,1), //评论数量的首数字
|
|
|
moreFirstnum = moreString.slice(0, 1), //评论数量的首数字
|
|
|
commentTpl = $('#comment-tpl').html(), //引入评论html模板
|
|
|
commentPage, //分页数据
|
|
|
commentHtml, //用数据渲染后的html
|
|
|
commentData; //评论数据
|
|
|
|
|
|
|
|
|
if(data.length === 0) return;
|
|
|
if (data.length === 0) return;
|
|
|
|
|
|
commentData = {
|
|
|
comment: data.comment
|
...
|
...
|
@@ -108,7 +97,7 @@ require("./login"); |
|
|
commentData = {
|
|
|
comment: data.comment,
|
|
|
more: {
|
|
|
moreNum : viewMoreNum
|
|
|
moreNum: viewMoreNum
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -119,7 +108,7 @@ require("./login"); |
|
|
commentData = {
|
|
|
comment: data.comment,
|
|
|
more: {
|
|
|
moreNum : viewMoreNum
|
|
|
moreNum: viewMoreNum
|
|
|
},
|
|
|
page: commentPage
|
|
|
}
|
...
|
...
|
@@ -137,7 +126,6 @@ require("./login"); |
|
|
} else if (moreString.length === 5) {
|
|
|
$(".view-more").find("span").text(moreFirstnum + 'w+');
|
|
|
}
|
|
|
=======
|
|
|
var Comment = function(element, options) {
|
|
|
this.options = options;
|
|
|
this.$element = $(element);
|
...
|
...
|
@@ -250,14 +238,13 @@ require("./login"); |
|
|
$(".view-more").find("span").text(moreFirstnum + 'k+');
|
|
|
} else if (moreString.length === 5) {
|
|
|
$(".view-more").find("span").text(moreFirstnum + 'w+');
|
|
|
}
|
|
|
>>>>>>> develop
|
|
|
} >>> >>> > develop
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
<< << << < HEAD
|
|
|
//创建评论文本域
|
|
|
/*_creatTextareaDom:function(){
|
|
|
=======
|
...
|
...
|
@@ -291,9 +278,9 @@ require("./login"); |
|
|
|
|
|
},*/
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
<< << << < HEAD
|
|
|
//创建第三方登录
|
|
|
_creatThirdLogin:function(){
|
|
|
_creatThirdLogin: function() {
|
|
|
var thirdLoginTpl = $("#third-login-tpl").html();
|
|
|
|
|
|
if (this.options.thirdLogin === true) {
|
...
|
...
|
@@ -303,10 +290,10 @@ require("./login"); |
|
|
},
|
|
|
|
|
|
//事件绑定
|
|
|
_bindEvent: function(){
|
|
|
_bindEvent: function() {
|
|
|
var that = this;
|
|
|
//查看更多评论
|
|
|
this.$element.on("click.comment",".view-more",function() {
|
|
|
this.$element.on("click.comment", ".view-more", function() {
|
|
|
that.$element.find("li").show(); //显示第一页后五条
|
|
|
that.$element.find(".comment-pager-content").show(); //显示分页按钮
|
|
|
that.$element.find(".view-more").remove(); //移除view more
|
...
|
...
|
@@ -343,26 +330,26 @@ require("./login"); |
|
|
$(this).login("loginBoxAnimate");
|
|
|
});*/
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
<< << << < HEAD
|
|
|
//显示删除按钮
|
|
|
if (this.options.isMobile) {
|
|
|
this.$element.find(".delete-comment").show();
|
|
|
} else {
|
|
|
this.$element.on("mouseenter","li",function() {
|
|
|
this.$element.on("mouseenter", "li", function() {
|
|
|
$(this).find(".delete-comment").show();
|
|
|
}).on("mouseleave","li",function(){
|
|
|
}).on("mouseleave", "li", function() {
|
|
|
$(this).find(".delete-comment").hide();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
//发表评论
|
|
|
this.$element.on("click.publish",".publish-btn",function() {
|
|
|
this.$element.on("click.publish", ".publish-btn", function() {
|
|
|
var $textarea = that.$element.find("textarea"),
|
|
|
nameInput = that.$element.find(".name-input"),
|
|
|
emailInput = that.$element.find(".email-input"),
|
|
|
comment = $textarea.val(),
|
|
|
=======
|
|
|
=== === =
|
|
|
//显示删除按钮
|
|
|
if (this.options.isMobile) {
|
|
|
this.$element.find(".delete-comment").show();
|
...
|
...
|
@@ -381,7 +368,7 @@ require("./login"); |
|
|
nameInput = that.$element.find(".name-input"),
|
|
|
emailInput = that.$element.find(".email-input"),
|
|
|
comment = $textarea.val(),
|
|
|
>>>>>>> develop
|
|
|
>>> >>> > develop
|
|
|
cid,
|
|
|
data,
|
|
|
commentsNum,
|
...
|
...
|
@@ -392,32 +379,25 @@ require("./login"); |
|
|
//验证名字
|
|
|
if (!tools.IYOHO_isUserName(nameInput.val())) {
|
|
|
box.alert(tips.getTips("commentUncompleted"), 5, function() {
|
|
|
nameInput.focus();
|
|
|
<<<<<<< HEAD
|
|
|
});
|
|
|
=======
|
|
|
});
|
|
|
>>>>>>> develop
|
|
|
nameInput.focus(); << << << < HEAD
|
|
|
}); === === =
|
|
|
}); >>> >>> > develop
|
|
|
return false;
|
|
|
};
|
|
|
|
|
|
//验证邮箱
|
|
|
if (emailInput.val() !== '' && !tools.IYOHO_isEmail(emailInput.val())) {
|
|
|
box.alert(tips.getTips("commentUncompleted"), 5, function() {
|
|
|
emailInput.focus();
|
|
|
<<<<<<< HEAD
|
|
|
});
|
|
|
=======
|
|
|
});
|
|
|
>>>>>>> develop
|
|
|
emailInput.focus(); << << << < HEAD
|
|
|
}); === === =
|
|
|
}); >>> >>> > develop
|
|
|
return false;
|
|
|
};
|
|
|
|
|
|
//验证评论
|
|
|
if (typeof(comment) === 'undefined' || $.trim(comment) === '') {
|
|
|
box.alert(tips.getTips("commentUncompleted"), 5, function() {
|
|
|
$textarea.focus();
|
|
|
<<<<<<< HEAD
|
|
|
$textarea.focus(); << << << < HEAD
|
|
|
});
|
|
|
return false;
|
|
|
};
|
...
|
...
|
@@ -432,7 +412,12 @@ require("./login"); |
|
|
return false;
|
|
|
};
|
|
|
|
|
|
data = {id:cid,comment:comment,sync:'222',title:'111'};
|
|
|
data = {
|
|
|
id: cid,
|
|
|
comment: comment,
|
|
|
sync: '222',
|
|
|
title: '111'
|
|
|
};
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
...
|
...
|
@@ -448,7 +433,7 @@ require("./login"); |
|
|
var $commentsList = $(".comments-list");
|
|
|
publishHtml = mustache.render(that.options.commentItemTpl, response.data);
|
|
|
|
|
|
if ($commentsList .find("li").size() === 0){
|
|
|
if ($commentsList.find("li").size() === 0) {
|
|
|
$commentsList.html(publishHtml);
|
|
|
} else {
|
|
|
$commentsList.find("li").eq(0).before(publishHtml);
|
...
|
...
|
@@ -458,8 +443,8 @@ require("./login"); |
|
|
$(".comment-textarea textarea").val('');
|
|
|
|
|
|
commentsNum = 1;
|
|
|
if(!!parseInt(that.options.commentNum.eq(0).text())){
|
|
|
commentsNum = parseInt(that.options.commentNum.eq(0).text())+1;
|
|
|
if (!!parseInt(that.options.commentNum.eq(0).text())) {
|
|
|
commentsNum = parseInt(that.options.commentNum.eq(0).text()) + 1;
|
|
|
};
|
|
|
that.options.commentNum.text(commentsNum);
|
|
|
} else if (900000 === response.code) {
|
...
|
...
|
@@ -540,7 +525,7 @@ require("./login"); |
|
|
});
|
|
|
|
|
|
//评论翻页
|
|
|
this.$element.on("click.commentPage",".pager-item",function(){
|
|
|
this.$element.on("click.commentPage", ".pager-item", function() {
|
|
|
var url = $(this).attr("href"),
|
|
|
pageHtml,
|
|
|
pageIcon,
|
...
|
...
|
@@ -554,7 +539,7 @@ require("./login"); |
|
|
pageHtml = mustache.render(that.options.commentItemTpl, response.data.comment);
|
|
|
$(".comments-list").html(pageHtml);
|
|
|
|
|
|
pageIcon = $('<div class="channel-index-pager">'+response.data.page+'</div>');
|
|
|
pageIcon = $('<div class="channel-index-pager">' + response.data.page + '</div>');
|
|
|
$(".comment-pager-content").html(pageIcon);
|
|
|
|
|
|
commentListTop = $(".comments-list").offset().top - $("#minEnterprise").outerHeight();
|
...
|
...
|
@@ -568,25 +553,22 @@ require("./login"); |
|
|
|
|
|
|
|
|
//删除评论
|
|
|
this.$element.on("click.deleteComment",".delete-comment",function(){
|
|
|
this.$element.on("click.deleteComment", ".delete-comment", function() {
|
|
|
var _this = $(this);
|
|
|
var id = _this.attr('pid');
|
|
|
var deleteTip = tips.getTips("deleteComment");
|
|
|
if(that.options.isFeedback){
|
|
|
if (that.options.isFeedback) {
|
|
|
deleteTip = tips.getTips("deleteFeedback");
|
|
|
}else if(that.options.isEdit){
|
|
|
} else if (that.options.isEdit) {
|
|
|
deleteTip = tips.getTips("deleteEdit");
|
|
|
}
|
|
|
box.confirm(deleteTip, function()
|
|
|
{
|
|
|
$.ajax
|
|
|
({
|
|
|
type:'POST',
|
|
|
url:YohoConfig.mainUrl+that.options.deleteUrl,
|
|
|
data:'id='+id,
|
|
|
dataType:'json',
|
|
|
success:function(response)
|
|
|
=======
|
|
|
box.confirm(deleteTip, function() {
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: YohoConfig.mainUrl + that.options.deleteUrl,
|
|
|
data: 'id=' + id,
|
|
|
dataType: 'json',
|
|
|
success: function(response) === === =
|
|
|
});
|
|
|
return false;
|
|
|
};
|
...
|
...
|
@@ -735,8 +717,7 @@ require("./login"); |
|
|
=======
|
|
|
}
|
|
|
}); */
|
|
|
});
|
|
|
>>>>>>> develop
|
|
|
}); >>> >>> > develop
|
|
|
|
|
|
//评论翻页
|
|
|
this.$element.on("click.commentPage", ".pager-item", function() {
|
...
|
...
|
@@ -804,8 +785,7 @@ require("./login"); |
|
|
if (!_this.attr('ref')) return;
|
|
|
window.open(_this.attr('ref'), "", "width=760,height=650,top=300,left=300");
|
|
|
return false;
|
|
|
})
|
|
|
$(".third-login-box").on("click", "a.yoho", function() {
|
|
|
}) $(".third-login-box").on("click", "a.yoho", function() {
|
|
|
$(this).login("loginBoxAnimate");
|
|
|
})
|
|
|
},
|
...
|
...
|
@@ -837,4 +817,4 @@ require("./login"); |
|
|
$.fn.comment = Plugin;
|
|
|
$.fn.comment.Constructor = Comment;
|
|
|
|
|
|
})(this); |
|
|
\ No newline at end of file |
|
|
})(this); |
|
|
\ No newline at end of file |
...
|
...
|
|