mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-11 22:41:38 +08:00
添加Metronic(作为LFS)
This commit is contained in:
838
frontend/static/js/common/article_cell.js
Normal file
838
frontend/static/js/common/article_cell.js
Normal file
@@ -0,0 +1,838 @@
|
||||
(function(old) {
|
||||
$.fn.attr = function() {
|
||||
if(arguments.length === 0) {
|
||||
if(this.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
$.each(this[0].attributes, function() {
|
||||
if(this.specified) {
|
||||
obj[this.name] = this.value;
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
return old.apply(this, arguments);
|
||||
};
|
||||
})($.fn.attr);
|
||||
|
||||
jQuery.extend({
|
||||
getCommonProblemCellElement:function(problemEntity,cellId,options){
|
||||
if(options == null){
|
||||
options = {};
|
||||
}
|
||||
var elementStr = "";
|
||||
var problemId = problemEntity.id;
|
||||
var mainId = 0;
|
||||
if(options.isShowFeedInfo){
|
||||
|
||||
var feedObjForId = options.feedObj;
|
||||
mainId = feedObjForId.id;
|
||||
|
||||
}else if(options.isShowTrendInfo){
|
||||
var trendObjForId = options.trendObj;
|
||||
mainId = trendObjForId.id;
|
||||
}else if(options.customId != null){
|
||||
mainId = options.customId;
|
||||
}else{
|
||||
mainId = problemId;
|
||||
|
||||
}
|
||||
|
||||
elementStr += '<div id="' + cellId + mainId + '" class="commonProblemCell">';
|
||||
|
||||
if(options.isShowFeedInfo){
|
||||
var feedObj = options.feedObj;
|
||||
if(feedObj != null){
|
||||
var feedFromUser = feedObj.fromUser;
|
||||
var feedFromUserAvatar = "";
|
||||
var feedFromUserName = "";
|
||||
var feedInfo = "";
|
||||
var feedFromUserGuid = "";
|
||||
if(feedFromUser == null){
|
||||
feedFromUserAvatar = "/public/img/default_avatar.jpg";
|
||||
feedFromUserName = "该用户已被删除";
|
||||
}else{
|
||||
feedFromUserAvatar = feedFromUser.avatarThumbUrl + "&w=60&h=60";
|
||||
feedFromUserName = feedFromUser.userName;
|
||||
feedFromUserGuid = feedFromUser.guid;
|
||||
}
|
||||
var feedCreationTime = $.getMeaningfulTimeStr(feedObj.creationTime);
|
||||
if(feedObj.type == 5){
|
||||
feedInfo = " 关注了一个问题 • "+feedCreationTime;
|
||||
}
|
||||
|
||||
elementStr += '<div class="commonProblemCellFeedInfo">\
|
||||
<div class="commonProblemCellFeedUserInfo">\
|
||||
<a target="_blank" href="/users/get?guid='+feedFromUserGuid+'"><img data-placement="bottom" class="img-circle commonProblemCellFeedAvatar" src="'+feedFromUserAvatar+'"/></a>\
|
||||
<div class="commonProblemCellFeedUserNameInfo">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/users/get?guid='+feedFromUserGuid+'">'+$.htmlspecialchars(feedFromUserName)+'</a>'+$.htmlspecialchars(feedInfo)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
|
||||
elementStr += '<div class="clear"></div></div>';
|
||||
|
||||
|
||||
|
||||
}
|
||||
}else if(options.isShowTrendInfo){
|
||||
var trendObj = options.trendObj;
|
||||
if(trendObj != null){
|
||||
var trendFromUser = trendObj.user;
|
||||
var trendFromUserAvatar = "";
|
||||
var trendFromUserName = "";
|
||||
var trendInfo = "";
|
||||
var trendFromUserGuid = "";
|
||||
if(trendFromUser == null){
|
||||
trendFromUserAvatar = "/public/img/default_avatar.jpg";
|
||||
trendFromUserName = "该用户已被删除";
|
||||
}else{
|
||||
trendFromUserAvatar = trendFromUser.avatarThumbUrl + "&w=60&h=60";
|
||||
trendFromUserName = trendFromUser.userName;
|
||||
trendFromUserGuid = trendFromUser.guid;
|
||||
}
|
||||
var trendCreationTime = $.getMeaningfulTimeStr(trendObj.creationTime);
|
||||
if(trendObj.type == 3){
|
||||
trendInfo = " 关注了一个问题 • "+trendCreationTime;
|
||||
}
|
||||
|
||||
elementStr += '<div class="commonProblemCellFeedInfo">\
|
||||
<div class="commonProblemCellFeedUserInfo">\
|
||||
<a target="_blank" href="/users/get?guid='+trendFromUserGuid+'"><img data-placement="bottom" class="img-circle commonProblemCellFeedAvatar" src="'+trendFromUserAvatar+'"/></a>\
|
||||
<div class="commonProblemCellFeedUserNameInfo">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/users/get?guid='+trendFromUserGuid+'">'+$.htmlspecialchars(trendFromUserName)+'</a>'+$.htmlspecialchars(trendInfo)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
|
||||
elementStr += '<div class="clear"></div></div>';
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(options.isNotShowMark){
|
||||
|
||||
}else{
|
||||
var markElementStr = "";
|
||||
var markArr = problemEntity.marks;
|
||||
for(var j = 0; j < markArr.length; j++){
|
||||
markElementStr += '<a target="_blank" href="/articles/listbymark?mark_id='+markArr[j].id+'"><span class="commonProblemCellMarkSpanContainer">'+$.htmlspecialchars(markArr[j].name)+'</span></a>';
|
||||
}
|
||||
|
||||
|
||||
elementStr += '<div class="commonProblemCellMarkContainer">'+markElementStr+'</div>';
|
||||
}
|
||||
|
||||
|
||||
var problemTitle = problemEntity.content;
|
||||
|
||||
problemTitle = $.htmlspecialchars(problemTitle);
|
||||
|
||||
if(options.isNotShowTitle){
|
||||
|
||||
}else{
|
||||
elementStr += '<p class="commonProblemCellTitle"><a href="/problems/get?guid='+problemEntity.guid+'" target="_blank">'+problemTitle+'</a></p>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
var followCount = problemEntity.followCount;
|
||||
var followClass = "";
|
||||
if(problemEntity.hasFollow == 1){
|
||||
followClass = "dragonfont-unfollow";
|
||||
followCount = "已关注|" + followCount;
|
||||
}else{
|
||||
followClass = "dragonfont-follow";
|
||||
followCount = "关注问题|" + followCount;
|
||||
}
|
||||
|
||||
if(options.isNotShowCount){
|
||||
|
||||
}else{
|
||||
elementStr += '<div class="commonProblemCellCountContainer">\
|
||||
<a id="commonProblemCellFollow'+mainId+'" href="javascript:;" class="linkBlue commonProblemCellFollow">\
|
||||
<span class="dragonfont '+followClass+'"></span>\
|
||||
<span>'+followCount+'</span>\
|
||||
</a>\
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
elementStr += '</div>';
|
||||
var element = $(elementStr);
|
||||
return element;
|
||||
|
||||
|
||||
},
|
||||
|
||||
getCommonArticleCellElement:function(articleEntity,cellId,options) {
|
||||
if(options == null){
|
||||
options = {};
|
||||
}
|
||||
var elementStr = "";
|
||||
var articleId = articleEntity.id;
|
||||
var mainId = 0;
|
||||
if(options.isShowFeedInfo){
|
||||
|
||||
var feedObjForId = options.feedObj;
|
||||
mainId = feedObjForId.id;
|
||||
|
||||
}else if(options.isShowTrendInfo){
|
||||
var trendObjForId = options.trendObj;
|
||||
mainId = trendObjForId.id;
|
||||
}else if(options.customId != null){
|
||||
mainId = options.customId;
|
||||
}else{
|
||||
mainId = articleId;
|
||||
|
||||
}
|
||||
elementStr += '<div id="' + cellId + mainId + '" class="commonArticleCell">';
|
||||
|
||||
if(options.isShowFeedInfo){
|
||||
var feedObj = options.feedObj;
|
||||
if(feedObj != null){
|
||||
if(feedObj.type == 3 || feedObj.type == 4){
|
||||
var feedFromUser = feedObj.fromUser;
|
||||
var feedFromUserAvatar = "";
|
||||
var feedFromUserName = "";
|
||||
var feedInfo = "";
|
||||
var feedFromUserGuid = "";
|
||||
if(feedFromUser == null){
|
||||
feedFromUserAvatar = "/public/img/default_avatar.jpg";
|
||||
feedFromUserName = "该用户已被删除";
|
||||
}else{
|
||||
feedFromUserAvatar = feedFromUser.avatarThumbUrl + "&w=60&h=60";
|
||||
feedFromUserName = feedFromUser.userName;
|
||||
feedFromUserGuid = feedFromUser.guid;
|
||||
}
|
||||
var feedCreationTime = $.getMeaningfulTimeStr(feedObj.creationTime);
|
||||
if(feedObj.type == 3){
|
||||
feedInfo = " 回答了一个问题 • "+feedCreationTime;
|
||||
}else if(feedObj.type == 4){
|
||||
feedInfo = " 推荐了一个回答 • "+feedCreationTime;
|
||||
}
|
||||
|
||||
var feedHasTeamClass = "";
|
||||
if(articleEntity.team_id > 0){
|
||||
feedHasTeamClass = "hasTeamInfo";
|
||||
}
|
||||
elementStr += '<div class="commonArticleCellFeedInfo">\
|
||||
<div class="commonArticleCellFeedUserInfo '+feedHasTeamClass+' ">\
|
||||
<a target="_blank" href="/users/get?guid='+feedFromUserGuid+'"><img data-placement="bottom" class="img-circle commonArticleCellFeedAvatar" src="'+feedFromUserAvatar+'"/></a>\
|
||||
<div class="commonArticleCellFeedUserNameInfo">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/users/get?guid='+feedFromUserGuid+'">'+$.htmlspecialchars(feedFromUserName)+'</a>'+$.htmlspecialchars(feedInfo)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
|
||||
//team相关信息在feed内显示在此处
|
||||
if(articleEntity.team_id > 0){
|
||||
var feedTeamIcon = "";
|
||||
var feedTeamName = "";
|
||||
var feedTeamId = 0;
|
||||
if(articleEntity.team == null){
|
||||
feedTeamName = "该团队已被删除";
|
||||
}else{
|
||||
feedTeamIcon = articleEntity.team.iconThumbUrl + "&w=60&h=60";
|
||||
feedTeamName = articleEntity.team.name;
|
||||
feedTeamId = articleEntity.team.id;
|
||||
}
|
||||
elementStr += '<div class="commonArticleCellFeedTeamPartInfo">\
|
||||
<a target="_blank" href="/teams/get?id='+feedTeamId+'"><img data-placement="bottom" class="img-circle commonArticleCellFeedTeamPartAvatar" src='+feedTeamIcon+'/></a>\
|
||||
<div class="commonArticleCellFeedTeamPartName">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/teams/get?id='+feedTeamId+'">'+$.htmlspecialchars(feedTeamName)+'</a></p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
}
|
||||
|
||||
elementStr += '<div class="clear"></div></div>';
|
||||
}else if(feedObj.type == 6){
|
||||
var feedFromTeam = feedObj.fromTeam;
|
||||
var feedFromTeamIcon = "";
|
||||
var feedFromTeamName = "";
|
||||
var feedInfo = "";
|
||||
var feedFromTeamId = 0;
|
||||
if(feedFromTeam == null){
|
||||
feedFromTeamName = "该团队已被删除";
|
||||
}else{
|
||||
feedFromTeamIcon = feedFromTeam.iconThumbUrl + "&w=60&h=60";
|
||||
feedFromTeamName = feedFromTeam.name;
|
||||
feedFromTeamId = feedFromTeam.id;
|
||||
}
|
||||
if(feedObj.type == 6){
|
||||
feedInfo = " 团队添加了一个回答";
|
||||
}
|
||||
|
||||
elementStr += '<div class="commonArticleCellFeedInfo">\
|
||||
<div class="commonArticleCellFeedTeamInfo">\
|
||||
<a target="_blank" href="/teams/get?id='+feedFromTeamId+'"><img data-placement="bottom" class="img-circle commonArticleCellFeedAvatar" src="'+feedFromTeamIcon+'"/></a>\
|
||||
<div class="commonArticleCellFeedTeamNameInfo">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/teams/get?id='+feedFromTeamId+'">'+$.htmlspecialchars(feedFromTeamName)+'</a>'+$.htmlspecialchars(feedInfo)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
|
||||
elementStr += '<div class="clear"></div></div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}else if(options.isShowTrendInfo){
|
||||
var trendObj = options.trendObj;
|
||||
if(trendObj != null){
|
||||
var trendFromUser = trendObj.user;
|
||||
var trendFromUserAvatar = "";
|
||||
var trendFromUserName = "";
|
||||
var trendInfo = "";
|
||||
var trendFromUserGuid = "";
|
||||
if(trendFromUser == null){
|
||||
trendFromUserAvatar = "/public/img/default_avatar.jpg";
|
||||
trendFromUserName = "该用户已被删除";
|
||||
}else{
|
||||
trendFromUserAvatar = trendFromUser.avatarThumbUrl + "&w=60&h=60";
|
||||
trendFromUserName = trendFromUser.userName;
|
||||
trendFromUserGuid = trendFromUser.guid;
|
||||
}
|
||||
var trendCreationTime = $.getMeaningfulTimeStr(trendObj.creationTime);
|
||||
if(trendObj.type == 1){
|
||||
trendInfo = " 回答了一个问题 • "+trendCreationTime;
|
||||
}else if(trendObj.type == 2){
|
||||
trendInfo = " 推荐了一个回答 • "+trendCreationTime;
|
||||
}
|
||||
|
||||
elementStr += '<div class="commonArticleCellFeedInfo">\
|
||||
<div class="commonArticleCellFeedUserInfo">\
|
||||
<a target="_blank" href="/users/get?guid='+trendFromUserGuid+'"><img data-placement="bottom" class="img-circle commonArticleCellFeedAvatar" src="'+trendFromUserAvatar+'"/></a>\
|
||||
<div class="commonArticleCellFeedUserNameInfo">\
|
||||
<p><a data-placement="bottom" target="_blank" href="/users/get?guid='+trendFromUserGuid+'">'+$.htmlspecialchars(trendFromUserName)+'</a>'+$.htmlspecialchars(trendInfo)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
</div>';
|
||||
|
||||
elementStr += '<div class="clear"></div></div>';
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(articleEntity.team_id != 0){
|
||||
var teamId = articleEntity.team_id;
|
||||
var teamName = "";
|
||||
var teamIconUrl = "";
|
||||
if(articleEntity.team == null){
|
||||
teamName = "该团队已被删除";
|
||||
}else{
|
||||
teamName = articleEntity.team.name;
|
||||
teamIconUrl = articleEntity.team.iconThumbUrl + "&w=60&h=60";
|
||||
}
|
||||
if(options.isNotShowTeam){
|
||||
|
||||
}else{
|
||||
elementStr += '<div class="commonArticleCellTeamContainer">';
|
||||
elementStr += '<a target="_blank" href="/teams/get?id='+teamId+'"><img data-placement="bottom" class="img-circle commonArticleCellTeamIcon" src="'+teamIconUrl+'"/></a>';
|
||||
elementStr += '<a target="_blank" href="/teams/get?id='+teamId+'" data-placement="bottom" class="commonArticleCellTeamName">'+teamName+'</a>'
|
||||
elementStr += '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
var articleTitle = "";
|
||||
if(articleEntity.problem_id != 0){
|
||||
|
||||
if(articleEntity.problem == null){
|
||||
|
||||
articleTitle = "该问题已被删除";
|
||||
|
||||
}else{
|
||||
articleTitle = articleEntity.problem.content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
articleTitle = articleEntity.title;
|
||||
}
|
||||
articleTitle = $.htmlspecialchars(articleTitle);
|
||||
|
||||
if(options.isNotShowTitle){
|
||||
|
||||
}else{
|
||||
if(articleEntity.problem_id != 0){
|
||||
//link为问题detail
|
||||
elementStr += '<p class="commonArticleCellTitle"><a href="/problems/get?guid='+articleEntity.problem.guid+'" target="_blank">'+articleTitle+'</a></p>';
|
||||
}else{
|
||||
//link为文章detail
|
||||
elementStr += '<p class="commonArticleCellTitle"><a href="/articles/get?guid='+articleEntity.guid+'" target="_blank">'+articleTitle+'</a></p>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
var articleCreatorId = articleEntity.creator_id;
|
||||
var articleCreator = articleEntity.creator;
|
||||
var articleCreatorAvatar = "";
|
||||
var articleCreatorUserName = "";
|
||||
var articleCreatorWord = "";
|
||||
var articleCreatorGuid = "";
|
||||
|
||||
if(articleCreator == null){
|
||||
articleCreatorAvatar = "/public/img/default_avatar.jpg";
|
||||
articleCreatorUserName = "该用户已被删除";
|
||||
articleCreatorWord = "";
|
||||
articleCreatorGuid = "";
|
||||
|
||||
}else{
|
||||
articleCreatorAvatar = articleCreator.avatarThumbUrl + "&w=100&h=100";
|
||||
articleCreatorUserName = articleCreator.userName;
|
||||
articleCreatorWord = articleCreator.word;
|
||||
articleCreatorGuid = articleCreator.guid;
|
||||
if(articleCreatorWord != ""){
|
||||
articleCreatorWord = ","+articleCreatorWord;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(options.isNotShowCreator){
|
||||
|
||||
}else{
|
||||
elementStr += '<div class="commonArticleCellCreatorInfo">';
|
||||
elementStr += '<a target="_blank" href="/users/get?guid='+articleCreatorGuid+'"><img data-placement="bottom" src="'+articleCreatorAvatar+'" class="img-circle commonArticleCellCreatorAvatar"></a>';
|
||||
elementStr += '<p class="commonArticleCellCreatorNameInfo"><a data-placement="bottom" target="_blank" href="/users/get?guid='+articleCreatorGuid+'">'+$.htmlspecialchars(articleCreatorUserName)+'</a>'+$.htmlspecialchars(articleCreatorWord)+'</p>';
|
||||
elementStr += '<div class="clear"></div>'
|
||||
elementStr += '</div>';
|
||||
}
|
||||
|
||||
|
||||
if(articleEntity.coverlist_id != 0){
|
||||
|
||||
var coverUrl = articleEntity.coverListMediumUrl;
|
||||
if(options.isNotShowCover){
|
||||
|
||||
}else{
|
||||
elementStr += '<a href="/articles/get?guid='+articleEntity.guid+'" target="_blank"><img class="commonArticleCellCover" src="'+coverUrl+'"/></a>';
|
||||
}
|
||||
|
||||
}
|
||||
var articleContent = articleEntity.content;
|
||||
var bMore = false;
|
||||
if(articleContent.length > 110){
|
||||
articleContent = articleContent.substr(0,111);
|
||||
articleContent = articleContent + "……";
|
||||
bMore = true;
|
||||
}
|
||||
articleContent = $.htmlspecialchars(articleContent);
|
||||
|
||||
if(options.isNotShowContent){
|
||||
|
||||
}else{
|
||||
if(bMore){
|
||||
elementStr += '<p id="commonArticleCellContent'+mainId+'" class="commonArticleCellContent">'+articleContent+'<a id="commonArticleCellShowMore'+mainId+'" class="commonArticleCellShowMore" href="/articles/get?guid='+articleEntity.guid+'" target="_blank">(更多)</a></p>';
|
||||
}else{
|
||||
elementStr += '<p id="commonArticleCellContent'+mainId+'" class="commonArticleCellContent">'+articleContent+'</p>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var recommendCount = articleEntity.recommendCount;
|
||||
var remarkCount = articleEntity.remarkCount;
|
||||
var heatClass = "dragonfont-heartempty";
|
||||
|
||||
var appendElement = "";
|
||||
if(articleEntity.problem_id > 0){
|
||||
//是回答显示关注
|
||||
if(articleEntity.problem != null){
|
||||
var followCount = articleEntity.problem.followCount;
|
||||
var followClass = "";
|
||||
if(articleEntity.problem.hasFollow == 1){
|
||||
followClass = "dragonfont-unfollow";
|
||||
followCount = "已关注|" + followCount;
|
||||
}else{
|
||||
followClass = "dragonfont-follow";
|
||||
followCount = "关注问题|" + followCount;
|
||||
}
|
||||
appendElement = '<a id="commonArticleCellFollow'+mainId+'" href="javascript:;" class="linkGray commonArticleCellFollow">\
|
||||
<span class="dragonfont '+followClass+'"></span>\
|
||||
<span>'+followCount+'</span>\
|
||||
</a>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(articleEntity.hasRecommend == 1){
|
||||
recommendCount = '已推荐|' + recommendCount;
|
||||
heatClass = "dragonfont-heart";
|
||||
}else{
|
||||
recommendCount = '推荐|' + recommendCount;
|
||||
heatClass = "dragonfont-heartempty";
|
||||
}
|
||||
if(options.isNotShowCount){
|
||||
|
||||
}else{
|
||||
elementStr += '<div class="commonArticleCellCountContainer">\
|
||||
<a id="commonArticleCellRecommend'+mainId+'" href="javascript:;" class="linkBlue commonArticleCellRecommend">\
|
||||
<span class="dragonfont '+heatClass+'"></span>\
|
||||
<span>'+recommendCount+'</span>\
|
||||
</a>'+appendElement+'\
|
||||
<a href="/articles/get?guid='+articleEntity.guid+'&source=remark" target="_blank" class="linkGray commonArticleCellRemark">\
|
||||
<span class="dragonfont dragonfont-chatbubble"></span>\
|
||||
<span>'+remarkCount+' 条评论</span>\
|
||||
</a>\
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
var timeStr = $.getMeaningfulTimeStr(articleEntity.createdAt);
|
||||
|
||||
if(options.isNotShowTimeAndOpr){
|
||||
|
||||
}else{
|
||||
elementStr += '<div class="commonArticleCellOprContainer">\
|
||||
<span>'+timeStr+'</span>\
|
||||
<span id="commonArticleCellDot'+mainId+'" class="commonArticleCellDot">•</span>\
|
||||
<a href="javascript:;" tabindex="0" id="commonArticleCellOpr'+mainId+'" class="linkGray commonArticleCellOpr"><span class="dragonfont dragonfont-ellipsis"></span></a>\
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
elementStr += '</div>';
|
||||
var element = $(elementStr);
|
||||
return element;
|
||||
},
|
||||
installCommonProblemCellEffect:function(id,options){
|
||||
//安装点关注相关
|
||||
var hasLogin = options.hasLogin;
|
||||
var problemEntity = options.problemEntity;
|
||||
var redirectLoginUrl = options.redirectLoginUrl;
|
||||
|
||||
//问题关注操作
|
||||
$("#commonProblemCellFollow"+id).click(function(){
|
||||
if(!hasLogin){
|
||||
window.location.href=redirectLoginUrl;
|
||||
return;
|
||||
}
|
||||
if(problemEntity == null){
|
||||
return;
|
||||
}
|
||||
if(problemEntity.hasFollow == 0){
|
||||
|
||||
problemEntity.hasFollow = 1;
|
||||
problemEntity.followCount = problemEntity.followCount + 1;
|
||||
|
||||
$("#commonProblemCellFollow"+id + " > span:first-child").removeClass("dragonfont-follow").addClass('dragonfont-unfollow');
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellUnFollow").addClass("feedProblemCellAlreadyFollow");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/problems/followproblem",
|
||||
data : "problem_id=" + problemEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonProblemCellFollow"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonProblemCellFollow"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
problemEntity.followCount = data.followCount;
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonProblemCellFollow"+id + " > span:first-child").removeClass("dragonfont-unfollow").addClass('dragonfont-follow');
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellAlreadyFollow").addClass("feedProblemCellUnFollow");
|
||||
}});
|
||||
|
||||
$("#commonProblemCellFollow"+id).data("jRequest",jRequest);
|
||||
|
||||
|
||||
}else{
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonProblemCellFollow"+id + " > span:first-child").removeClass("dragonfont-unfollow").addClass('dragonfont-follow');
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellAlreadyFollow").addClass("feedProblemCellUnFollow");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/problems/unfollowproblem",
|
||||
data : "problem_id=" + problemEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonProblemCellFollow"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonProblemCellFollow"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
problemEntity.followCount = data.followCount;
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonProblemCellFollow"+id + " > span:first-child").removeClass("dragonfont-follow").addClass('dragonfont-unfollow');
|
||||
$("#commonProblemCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellUnFollow").addClass("feedProblemCellAlreadyFollow");
|
||||
}});
|
||||
|
||||
$("#commonProblemCellFollow"+id).data("jRequest",jRequest);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
installCommonArticleCellEffect:function(id,options){
|
||||
if($("#commonArticleCellShowMore" + id).length > 0){
|
||||
//安装hover内容同步hover更多
|
||||
$("#commonArticleCellContent" + id).hover(function(){
|
||||
$("#commonArticleCellShowMore" + id).addClass("commonArticleCellShowMoreDynamic");
|
||||
},function(){
|
||||
$("#commonArticleCellShowMore" + id).removeClass("commonArticleCellShowMoreDynamic");
|
||||
});
|
||||
|
||||
}
|
||||
var articleEntity = options.articleEntity;
|
||||
//安装原文链接跳转相关
|
||||
$("#commonArticleCellContent" + id).on("click",function(){
|
||||
window.open("/articles/get?guid="+articleEntity.guid);
|
||||
});
|
||||
|
||||
|
||||
//安装点赞相关
|
||||
var hasLogin = options.hasLogin;
|
||||
var redirectLoginUrl = options.redirectLoginUrl;
|
||||
$("#commonArticleCellRecommend"+id).click(function(){
|
||||
|
||||
if(!hasLogin){
|
||||
window.location.href=redirectLoginUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
if(articleEntity == null){
|
||||
return;
|
||||
}
|
||||
if(articleEntity.hasRecommend == 0){
|
||||
|
||||
articleEntity.hasRecommend = 1;
|
||||
articleEntity.recommendCount = articleEntity.recommendCount + 1;
|
||||
|
||||
$("#commonArticleCellRecommend"+id + " > span:first-child").removeClass("dragonfont-heartempty").addClass('dragonfont-heart');
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("已推荐|" + articleEntity.recommendCount );
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/articles/recommend",
|
||||
data : "articleId=" + articleEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonArticleCellRecommend"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonArticleCellRecommend"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
articleEntity.recommendCount = data.recommendCount;
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("已推荐|" + articleEntity.recommendCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
articleEntity.hasRecommend = 0;
|
||||
articleEntity.recommendCount = articleEntity.recommendCount - 1;
|
||||
|
||||
$("#commonArticleCellRecommend"+id + " > span:first-child").removeClass("dragonfont-heart").addClass('dragonfont-heartempty');
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("推荐|" + articleEntity.recommendCount );
|
||||
}});
|
||||
|
||||
$("#commonArticleCellRecommend"+id).data("jRequest",jRequest);
|
||||
|
||||
|
||||
}else{
|
||||
articleEntity.hasRecommend = 0;
|
||||
articleEntity.recommendCount = articleEntity.recommendCount - 1;
|
||||
|
||||
$("#commonArticleCellRecommend"+id + " > span:first-child").removeClass("dragonfont-heart").addClass('dragonfont-heartempty');
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("推荐|" + articleEntity.recommendCount );
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/articles/unrecommend",
|
||||
data : "articleId=" + articleEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonArticleCellRecommend"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonArticleCellRecommend"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
articleEntity.recommendCount = data.recommendCount;
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("推荐|" + articleEntity.recommendCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
articleEntity.hasRecommend = 1;
|
||||
articleEntity.recommendCount = articleEntity.recommendCount + 1;
|
||||
|
||||
$("#commonArticleCellRecommend"+id + " > span:first-child").removeClass("dragonfont-heartempty").addClass('dragonfont-heart');
|
||||
$("#commonArticleCellRecommend"+id + " > span:eq(1)").text("已推荐|" + articleEntity.recommendCount );
|
||||
}});
|
||||
|
||||
$("#commonArticleCellRecommend"+id).data("jRequest",jRequest);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//安装关注相关
|
||||
var problemEntity = articleEntity.problem;
|
||||
if(problemEntity != null){
|
||||
|
||||
|
||||
//问题关注操作
|
||||
$("#commonArticleCellFollow"+id).click(function(){
|
||||
if(!hasLogin){
|
||||
window.location.href=redirectLoginUrl;
|
||||
return;
|
||||
}
|
||||
if(problemEntity == null){
|
||||
return;
|
||||
}
|
||||
if(problemEntity.hasFollow == 0){
|
||||
|
||||
problemEntity.hasFollow = 1;
|
||||
problemEntity.followCount = problemEntity.followCount + 1;
|
||||
|
||||
$("#commonArticleCellFollow"+id + " > span:first-child").removeClass("dragonfont-follow").addClass('dragonfont-unfollow');
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellUnFollow").addClass("feedProblemCellAlreadyFollow");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/problems/followproblem",
|
||||
data : "problem_id=" + problemEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonArticleCellFollow"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonArticleCellFollow"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
problemEntity.followCount = data.followCount;
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonArticleCellFollow"+id + " > span:first-child").removeClass("dragonfont-unfollow").addClass('dragonfont-follow');
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellAlreadyFollow").addClass("feedProblemCellUnFollow");
|
||||
}});
|
||||
|
||||
$("#commonArticleCellFollow"+id).data("jRequest",jRequest);
|
||||
|
||||
|
||||
}else{
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonArticleCellFollow"+id + " > span:first-child").removeClass("dragonfont-unfollow").addClass('dragonfont-follow');
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellAlreadyFollow").addClass("feedProblemCellUnFollow");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/problems/unfollowproblem",
|
||||
data : "problem_id=" + problemEntity.id,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("#commonArticleCellFollow"+id).data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("#commonArticleCellFollow"+id).data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
problemEntity.followCount = data.followCount;
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("关注问题|" + problemEntity.followCount );
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
problemEntity.hasFollow = 0;
|
||||
problemEntity.followCount = problemEntity.followCount - 1;
|
||||
|
||||
$("#commonArticleCellFollow"+id + " > span:first-child").removeClass("dragonfont-follow").addClass('dragonfont-unfollow');
|
||||
$("#commonArticleCellFollow"+id + " > span:eq(1)").text("已关注|" + problemEntity.followCount );
|
||||
//$("#feedProblemCellFollow"+arg).removeClass("feedProblemCellUnFollow").addClass("feedProblemCellAlreadyFollow");
|
||||
}});
|
||||
|
||||
$("#commonArticleCellFollow"+id).data("jRequest",jRequest);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
117
frontend/static/js/common/common.js
Normal file
117
frontend/static/js/common/common.js
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 定义全局JS函数
|
||||
*/
|
||||
//保存后禁用按钮,防止重复提交
|
||||
function Disabled($this,btn_text){
|
||||
$this.attr('disabled','disabled').text(btn_text).val(btn_text);
|
||||
}
|
||||
//设置按钮为可用状态
|
||||
function Enabled($this,btn_text){
|
||||
$this.removeAttr('disabled').empty().text(btn_text).val(btn_text);
|
||||
}
|
||||
|
||||
//loading
|
||||
function Loading($this,bgColor){
|
||||
var $loading=$('<div class="loading">'+
|
||||
'<div class="loading1"></div>'+
|
||||
'<div class="loading2"></div>'+
|
||||
'<div class="loading3"></div>'+
|
||||
'</div>');
|
||||
$this.append($loading);
|
||||
arguments[1]&&arguments[1]!=''?$this.find('.loading div').css('background',bgColor):'';
|
||||
}
|
||||
|
||||
|
||||
/* 查看是否拥有该权限 */
|
||||
function hasAuth(DropDownArray,authList_array){
|
||||
var returnValue=[];
|
||||
for(var j=0;j<DropDownArray.length;j++){
|
||||
for(var i=0;i<authList_array.length;i++){
|
||||
/* 判断是否拥有该权限 */
|
||||
var flag = authList_array[i].module===DropDownArray[j].module &&
|
||||
authList_array[i].controller===DropDownArray[j].controller &&
|
||||
authList_array[i].action===DropDownArray[j].action &&
|
||||
authList_array[i].method===DropDownArray[j].method;
|
||||
if(flag){
|
||||
var returnValue_json={};
|
||||
returnValue_json.index=j;
|
||||
returnValue_json.menuItem=DropDownArray[j].menuItem;
|
||||
returnValue_json.link='/'+authList_array[i].controller+'/'+authList_array[i].action;
|
||||
returnValue.push(returnValue_json);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
//MODAL
|
||||
function ModalOperation(showModalElem){
|
||||
/* 显示Modal框 */
|
||||
showModalElem.click(function(){
|
||||
$('.modal,.modal-background').show();
|
||||
});
|
||||
/* 隐藏Modal框 */
|
||||
$(document).on('click','.modal-background,.modal-footer input[type="reset"],.modal .close-btn',function(){
|
||||
$('.input-area').val('');
|
||||
$('.modal,.modal-background').hide();
|
||||
});
|
||||
}
|
||||
|
||||
//图片在容器居中显示
|
||||
function centerCropImg(url,$container){
|
||||
/* 取图片正中间部分 */
|
||||
var img=new Image();
|
||||
img.src=url;
|
||||
img.onload=function(){
|
||||
/* 容器宽高 */
|
||||
var containerHeight=$container.height(),containerWidth=$container.width();
|
||||
/* 容器比例 */
|
||||
var containerScale=containerWidth/containerHeight;
|
||||
/* 等比例缩放后图片宽高 */
|
||||
var imgHeight,imgWidth;
|
||||
/* 横图 */
|
||||
if(img.width/img.height>containerScale){
|
||||
imgWidth=img.width/img.height*containerHeight;
|
||||
var _left=(imgWidth-containerWidth)/2;
|
||||
$container.find('img').height(containerHeight).css({
|
||||
'left':'-'+_left+'px'
|
||||
});
|
||||
}
|
||||
/* 竖图 */
|
||||
else{
|
||||
imgHeight=img.height/img.width*containerWidth;
|
||||
var _top=(imgHeight-containerHeight)/2;
|
||||
$container.find('img').width(containerWidth).css({
|
||||
'top':'-'+_top+'px'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//时间戳转换日期
|
||||
function timeStampToDateString(ts){
|
||||
var datetime=new Date(parseInt(ts)*1000);
|
||||
var year=datetime.getFullYear();
|
||||
var month=datetime.getMonth()+1;
|
||||
var date=datetime.getDate();
|
||||
var dateString=year+'-'+month+'-'+date;
|
||||
return dateString;
|
||||
}
|
||||
//JSON数组排序函数
|
||||
function getSortFun(order, sortBy) {
|
||||
var ordAlpah = (order == 'asc') ? '>' : '<';
|
||||
var sortFun = new Function('a', 'b', 'return a.' + sortBy + ordAlpah + 'b.' + sortBy + '?1:-1');
|
||||
return sortFun;
|
||||
}
|
||||
|
||||
function lazyload(){
|
||||
var $unload=$('.shot-image .unload');
|
||||
for(var i=0;i<$unload.length;i++){
|
||||
var top=$(window).scrollTop(),height=$(window).height();
|
||||
/* 未加载的图片元素进入可视区域 */
|
||||
if(top+height>$unload.eq(i).offset().top){
|
||||
var url=$unload.eq(i).data('url');
|
||||
$unload.eq(i).removeClass('unload').addClass('loaded').attr('src',url).fadeIn(500);
|
||||
}
|
||||
}
|
||||
}
|
680
frontend/static/js/common/component.js
Normal file
680
frontend/static/js/common/component.js
Normal file
@@ -0,0 +1,680 @@
|
||||
(function(old) {
|
||||
$.fn.attr = function() {
|
||||
if(arguments.length === 0) {
|
||||
if(this.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
$.each(this[0].attributes, function() {
|
||||
if(this.specified) {
|
||||
obj[this.name] = this.value;
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
return old.apply(this, arguments);
|
||||
};
|
||||
})($.fn.attr);
|
||||
|
||||
jQuery.extend({
|
||||
drWindowLocation:function(href,isShownLoading){
|
||||
if(isShownLoading){
|
||||
$('#loadingBar').drloadingbar("startLoad");
|
||||
}
|
||||
window.location.href=href;
|
||||
},
|
||||
adjustNode:function(node,isRoot){
|
||||
var childNodes = node.children();
|
||||
var tagName = node[0].tagName.toLowerCase();
|
||||
if(tagName == null){
|
||||
//普通字符串节点,不转化
|
||||
return;
|
||||
}
|
||||
|
||||
if(childNodes.length > 0){
|
||||
//不是叶子节点,先去调整所有子节点
|
||||
for(var i = 0; i < childNodes.length; i++){
|
||||
$.adjustNode($(childNodes[i]),false);
|
||||
}
|
||||
}else{
|
||||
//叶子节点
|
||||
var display = $.getElementDefaultDisplay(tagName);
|
||||
if(display == "block" || display=="list-item"){
|
||||
if(tagName == "p"){
|
||||
//本身就是段落,不替换
|
||||
}else if(tagName == "hr"){
|
||||
//分割线,不替换
|
||||
}else{
|
||||
//替换成段落
|
||||
if(node.hasClass("drimgCaption")){
|
||||
//不替换
|
||||
}else{
|
||||
node.contents().unwrap().wrap("<p></p>");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//行内元素,不替换
|
||||
if(tagName=="img"){
|
||||
//图片元素,包裹imgcaption
|
||||
if(!node.parent().hasClass("drimgPackage")){
|
||||
node.wrap('<div class="drimgPackage"></div>');
|
||||
node.parent().append($('<div class="drimgCaption"> <br></div>'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
//非叶子节点调整完所有底部节点后
|
||||
|
||||
//处理换行问题
|
||||
var hasBr = false;;
|
||||
for(var i = 0; i < node.children().length; i++){
|
||||
if(node.children()[i].tagName.toLowerCase() == "br"){
|
||||
if(node.closest(".drimgPackage").length > 0){
|
||||
|
||||
}else{
|
||||
hasBr = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(hasBr){
|
||||
var brNodePosition = [];
|
||||
var contentsChild = node.contents();
|
||||
for(var i = 0; i < contentsChild.length; i++){
|
||||
var content = contentsChild[i];
|
||||
if(content.nodeType == 1){
|
||||
var contentTagName = content.tagName.toLowerCase();
|
||||
if(contentTagName == "br"){
|
||||
brNodePosition.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
var shouldWrapNodePosition = [];
|
||||
var wrapGroup = [];
|
||||
for(var i = 0; i < brNodePosition.length;i++){
|
||||
var j = i + 1;
|
||||
var k = i - 1;
|
||||
var allPrevNode = [];
|
||||
if(i == 0){
|
||||
|
||||
for(var index = 0; index < brNodePosition[i]; index++ ){
|
||||
allPrevNode.push($(node.contents()[index]));
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
var allPostNode = [];
|
||||
if(j < brNodePosition.length){
|
||||
|
||||
for(var index = brNodePosition[i] + 1; index < brNodePosition[j]; index++ ){
|
||||
allPostNode.push($(node.contents()[index]));
|
||||
}
|
||||
|
||||
}else{
|
||||
for(var index = brNodePosition[i] + 1; index < node.contents().length; index++ ){
|
||||
allPostNode.push($(node.contents()[index]));
|
||||
}
|
||||
|
||||
}
|
||||
wrapGroup.push(allPrevNode);
|
||||
wrapGroup.push(allPostNode);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
var originContent = node.contents();
|
||||
for(var i = 0; i < wrapGroup.length; i++){
|
||||
var wrapObj = originContent.filter(function(){
|
||||
for(var j = 0; j < wrapGroup[i].length;j++){
|
||||
if(wrapGroup[i][j][0] == this){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
wrapObj.wrapAll("<p></p>");
|
||||
}
|
||||
//去掉br
|
||||
node.find("br").remove();
|
||||
|
||||
}
|
||||
if(isRoot){
|
||||
return;
|
||||
}
|
||||
var display = $.getElementDefaultDisplay(tagName);
|
||||
if(display == "block" || display=="list-item"){
|
||||
if(tagName == "p"){
|
||||
//本身就是段落,不替换
|
||||
}else if(tagName=="aside" || tagName=="blockquote" || tagName == "ul" || tagName == "ol" || tagName =="dl"
|
||||
|| tagName == "div" || tagName=="section" || tagName=="article" || tagName=="header" || tagName=="footer"
|
||||
|| tagName == "div" || tagName =="form" || tagName == "head" || tagName == "nav"){
|
||||
//容器类
|
||||
if(tagName == "div" && (node.hasClass("drimgPackage") || node.hasClass("drimgCaption") )){
|
||||
|
||||
}else{
|
||||
var prev = node.prev();
|
||||
var next = node.next();
|
||||
var parent = node.parent();
|
||||
if(prev.length > 0){
|
||||
node.children().insertAfter(prev);
|
||||
}else if(next.length > 0){
|
||||
node.children().insertBefore(next);
|
||||
}else{
|
||||
node.children().prependTo(parent);
|
||||
}
|
||||
node.remove();
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
$newElement = $("<p></p>");
|
||||
var oldAttrs = node.attr();
|
||||
for(var key in oldAttrs){
|
||||
$newElement.attr(key,oldAttrs[key]);
|
||||
}
|
||||
$newElement.html(node.html());
|
||||
$newElement.insertAfter(node);
|
||||
node.remove();
|
||||
}
|
||||
|
||||
}else{
|
||||
//行内元素
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
getElementDefaultDisplay:function(tag) {
|
||||
var cStyle,
|
||||
t = document.createElement(tag),
|
||||
gcs = "getComputedStyle" in window;
|
||||
|
||||
document.body.appendChild(t);
|
||||
cStyle = (gcs ? window.getComputedStyle(t, "") : t.currentStyle).display;
|
||||
document.body.removeChild(t);
|
||||
|
||||
return cStyle;
|
||||
},
|
||||
clearNode:function(node){
|
||||
if(node != null){
|
||||
if(node.hasClass("drimgCaption")){
|
||||
node.removeAttr("class");
|
||||
node.addClass("drimgCaption");
|
||||
}else if(node.hasClass("drimgPackage")){
|
||||
node.removeAttr("class");
|
||||
node.addClass("drimgPackage");
|
||||
}else{
|
||||
node.removeAttr("class");
|
||||
}
|
||||
|
||||
|
||||
node.removeAttr("style");
|
||||
|
||||
if(node[0].tagName == null){
|
||||
//普通文本,没有tag
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//去掉所有内置属性
|
||||
var tagName = node[0].tagName.toLowerCase();
|
||||
var attrObj = node.attr();
|
||||
for(var key in attrObj){
|
||||
if(tagName == "img" && key == "src"){
|
||||
continue;
|
||||
}else if(tagName=="a" && key=="href"){
|
||||
node.attr("target","_blank");
|
||||
continue;
|
||||
}else if(tagName=="a" && key=="target"){
|
||||
continue;
|
||||
}else if(key=="class"){
|
||||
continue;
|
||||
}
|
||||
node.removeAttr(key);
|
||||
}
|
||||
|
||||
if($.shouldbeEmptyNode(node)){
|
||||
|
||||
//本节点自身为空,去除
|
||||
return true;
|
||||
}else{
|
||||
var children = node.children();
|
||||
var removeNode = [];
|
||||
for(var i = 0; i < children.length; i++){
|
||||
if($.clearNode($(children[i]))){
|
||||
removeNode.push($(children[i]));
|
||||
}
|
||||
}
|
||||
|
||||
for(var i = 0; i < removeNode.length; i++){
|
||||
removeNode[i].remove();
|
||||
}
|
||||
//子节点移除后判断父节点是否为空
|
||||
if($.shouldbeEmptyNode(node)){
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
shouldbeEmptyNode:function(node){
|
||||
var tagName = node[0].tagName.toLowerCase();
|
||||
|
||||
if(tagName == "img"){
|
||||
return false;
|
||||
}
|
||||
if(tagName == "hr"){
|
||||
return false;
|
||||
}
|
||||
if(tagName == "br"){
|
||||
|
||||
return false;
|
||||
}
|
||||
if(tagName == "div" && (node.hasClass("drimgCaption") || node.hasClass("drimgPackage"))){
|
||||
return false;
|
||||
}
|
||||
var ret = ($.trim(node.text()) === '' && node.children().length == 0);
|
||||
return ret;
|
||||
},
|
||||
removeEmptyNode:function(node){
|
||||
node.filter(function() {
|
||||
var returnValue = ($.trim($(this).text()) === '' && $(this).children().length == 0);
|
||||
return returnValue;
|
||||
}).remove();
|
||||
},
|
||||
getGuid:function(){
|
||||
function S4() {
|
||||
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
||||
}
|
||||
return (S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4());
|
||||
},
|
||||
// processContentEditableStr:function(blockElement){
|
||||
// var content = "";
|
||||
// var inputChildren = blockElement.children();
|
||||
// for(var i = 0; i < inputChildren.length; i++){
|
||||
// if($(inputChildren[i])[0].tagName.toLowerCase() == "br"){
|
||||
// content = content + "\n";
|
||||
// continue;
|
||||
// }
|
||||
// var tagName = inputChildren[i].tagName.toLowerCase();
|
||||
//
|
||||
// if($.getElementDefaultDisplay(tagName)=="block" || $.getElementDefaultDisplay(tagName)=="list-item"){
|
||||
// if($(inputChildren[i]).text() != ""){
|
||||
// content = content + "\n" + $.processContentEditableStr($(inputChildren[i]));
|
||||
// }else{
|
||||
// content = content + $.processContentEditableStr($(inputChildren[i]));
|
||||
// }
|
||||
//
|
||||
// }else{
|
||||
// content = content + $(inputChildren[i]).text();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// var parentContent = blockElement.contents().filter(function() {
|
||||
// return this.nodeType === 3;
|
||||
// }).text();
|
||||
// content = parentContent + content;
|
||||
// return content;
|
||||
// },
|
||||
processContentEditableStr:function(blockElement,isRoot){
|
||||
var content = "";
|
||||
var inputChildren = blockElement.contents();
|
||||
|
||||
for(var i = 0; i < inputChildren.length; i++){
|
||||
if(inputChildren[i].nodeType === 3){
|
||||
content = content + $(inputChildren[i]).text();
|
||||
continue;
|
||||
}
|
||||
if(inputChildren[i].tagName.toLowerCase() == "br"){
|
||||
content = content + "\n";
|
||||
continue;
|
||||
}
|
||||
var tagName = inputChildren[i].tagName.toLowerCase();
|
||||
|
||||
if($.getElementDefaultDisplay(tagName)=="block" || $.getElementDefaultDisplay(tagName)=="list-item"){
|
||||
var textNode= $(inputChildren[i]).contents().filter(function() {
|
||||
return this.nodeType === 3;
|
||||
});
|
||||
if(textNode.length > 0){
|
||||
content = content + "\n" + $.processContentEditableStr($(inputChildren[i]),false);
|
||||
}else{
|
||||
content = content + $.processContentEditableStr($(inputChildren[i]),false);
|
||||
}
|
||||
|
||||
}else{
|
||||
content = content + $.processContentEditableStr($(inputChildren[i]),false);
|
||||
}
|
||||
|
||||
}
|
||||
// var parentContent = blockElement.contents().filter(function() {
|
||||
// return this.nodeType === 3;
|
||||
// }).text();
|
||||
// content = parentContent + content;
|
||||
if(isRoot){
|
||||
//去掉第一个回车
|
||||
if(content != "" && content[0] == "\n"){
|
||||
content = content.substring(1,content.length);
|
||||
}
|
||||
}
|
||||
return content;
|
||||
},
|
||||
nl2br:function(str, is_xhtml) {
|
||||
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br/>' : '<br>';
|
||||
//return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
|
||||
str=str.replace(/\r\n/g,breakTag);
|
||||
str=str.replace(/\n/g,breakTag);
|
||||
return str;
|
||||
},
|
||||
setSelectionRange:function(input, selectionStart, selectionEnd) {
|
||||
if (input.setSelectionRange) {
|
||||
input.focus();
|
||||
input.setSelectionRange(selectionStart, selectionEnd);
|
||||
}
|
||||
else if (input.createTextRange) {
|
||||
var range = input.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', selectionEnd);
|
||||
range.moveStart('character', selectionStart);
|
||||
range.select();
|
||||
}
|
||||
},
|
||||
focuscurorInContentEditable:function(selector,position){
|
||||
selector.each(function(){
|
||||
var el = this;
|
||||
var range = document.createRange();
|
||||
var sel = window.getSelection();
|
||||
range.setStart(el.childNodes[0], position);
|
||||
range.collapse(true);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getDeviceWidthType: function(){
|
||||
var clientWidth = document.documentElement.clientWidth;
|
||||
if(clientWidth <= 800){
|
||||
return 1;
|
||||
}else{
|
||||
return 4; //>800统一按照pc处理暂时
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getDeviceWidth:function(){
|
||||
var clientWidth = document.documentElement.clientWidth;
|
||||
return clientWidth;
|
||||
},
|
||||
getDeviceHeight:function(){
|
||||
var clientHeight = document.documentElement.clientHeight;
|
||||
return clientHeight;
|
||||
},
|
||||
|
||||
htmlspecialchars:function(str){
|
||||
str = str.replace(/&/g, '&');
|
||||
str = str.replace(/</g, '<');
|
||||
str = str.replace(/>/g, '>');
|
||||
str = str.replace(/"/g, '"');
|
||||
str = str.replace(/'/g, ''');
|
||||
return str;
|
||||
},
|
||||
|
||||
getDateFormat:function(time){
|
||||
time = new Date(time*1000);
|
||||
var year=time.getYear() + 1900;
|
||||
var month=time.getMonth()+1;
|
||||
var date=time.getDate();
|
||||
var hour=time.getHours();
|
||||
var minute=time.getMinutes();
|
||||
var second=time.getSeconds();
|
||||
return year+"."+month+"."+date;
|
||||
},
|
||||
|
||||
|
||||
getMeaningfulTimeStr:function(time){
|
||||
var nowTime = (Date.parse(new Date()))/1000;
|
||||
var time = time;
|
||||
var delta = nowTime-time;
|
||||
if(delta < 60){
|
||||
return "1 分钟前";
|
||||
}else if(delta < 3600){
|
||||
delta = Math.floor(delta/60);
|
||||
return delta+" 分钟前";
|
||||
}else if(delta < 86400){
|
||||
delta = Math.floor(delta/3600);
|
||||
return delta+" 小时前";
|
||||
}else {
|
||||
//判断是否是昨天
|
||||
var today = new Date();
|
||||
today.setHours(0);
|
||||
today.setMinutes(0);
|
||||
today.setSeconds(0);
|
||||
today.setMilliseconds(0);
|
||||
var oneday = 1000* 60 * 60 * 24;
|
||||
var yesterday = new Date(today - oneday);
|
||||
var yesterdayTime = (Date.parse(yesterday))/1000;
|
||||
|
||||
timeDate = new Date(time*1000);
|
||||
var year=timeDate.getYear() + 1900;
|
||||
var month=timeDate.getMonth()+1;
|
||||
var date=timeDate.getDate();
|
||||
var hour=timeDate.getHours();
|
||||
var minute=timeDate.getMinutes();
|
||||
var second=timeDate.getSeconds();
|
||||
|
||||
if (month.toString().length == 1) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (date.toString().length == 1) {
|
||||
date = "0" + date;
|
||||
}
|
||||
|
||||
if (minute.toString().length == 1) {
|
||||
minute = "0" + minute;
|
||||
}
|
||||
|
||||
if (hour.toString().length == 1) {
|
||||
hour = "0" + hour;
|
||||
}
|
||||
if (second.toString().length == 1) {
|
||||
second = "0" + second;
|
||||
}
|
||||
|
||||
if(yesterdayTime <= time){
|
||||
//是昨天
|
||||
return "昨天 " + hour +":"+minute;
|
||||
|
||||
}else{
|
||||
return year+"-"+month+"-"+date + " " + hour +":"+minute;
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
getTransitionEnd:function() {
|
||||
var el = document.createElement('dragon')
|
||||
|
||||
var transEndEventNames = {
|
||||
WebkitTransition : 'webkitTransitionEnd',
|
||||
MozTransition : 'transitionend',
|
||||
OTransition : 'oTransitionEnd otransitionend',
|
||||
transition : 'transitionend'
|
||||
}
|
||||
|
||||
for (var name in transEndEventNames) {
|
||||
if (el.style[name] !== undefined) {
|
||||
return { end: transEndEventNames[name] }
|
||||
}
|
||||
}
|
||||
|
||||
return false // explicit for ie8 ( ._.)
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
//补充jquery被废弃的broswer变量判断浏览器类型
|
||||
var matched, browser;
|
||||
|
||||
jQuery.uaMatch = function( ua ) {
|
||||
ua = ua.toLowerCase();
|
||||
|
||||
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(msie)[\s?]([\w.]+)/.exec( ua ) ||
|
||||
/(trident)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
||||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
||||
[];
|
||||
|
||||
return {
|
||||
browser: match[ 1 ] || "",
|
||||
version: match[ 2 ] || "0"
|
||||
};
|
||||
};
|
||||
|
||||
matched = jQuery.uaMatch( navigator.userAgent );
|
||||
//IE 11+ fix (Trident)
|
||||
matched.browser = matched.browser == 'trident' ? 'msie' : matched.browser;
|
||||
browser = {};
|
||||
|
||||
if ( matched.browser ) {
|
||||
browser[ matched.browser ] = true;
|
||||
browser.version = matched.version;
|
||||
}
|
||||
|
||||
// Chrome is Webkit, but Webkit is also Safari.
|
||||
if ( browser.chrome ) {
|
||||
browser.webkit = true;
|
||||
} else if ( browser.webkit ) {
|
||||
browser.safari = true;
|
||||
}
|
||||
|
||||
jQuery.browser = browser;
|
||||
|
||||
|
||||
(function( $ ){
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.drcontenteditable.options, options );
|
||||
return this.each(function(){
|
||||
|
||||
$this.on("paste",function(e){
|
||||
|
||||
var pasteText = e.originalEvent.clipboardData.getData("text/plain");
|
||||
//替换/r/n为br
|
||||
pasteText = pasteText.replace(/\r\n/g,"<br/>");
|
||||
pasteText = pasteText.replace(/\r/g,"<br/>");
|
||||
pasteText = pasteText.replace(/\n/g,"<br/>");
|
||||
document.execCommand("insertHTML", false, pasteText);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getContent:function(){
|
||||
|
||||
|
||||
function extractTextWithWhitespaceWorker(elems, lineBreakNodeName)
|
||||
{
|
||||
var ret = "";
|
||||
var elem;
|
||||
|
||||
for (var i = 0; elems[i]; i++)
|
||||
{
|
||||
elem = elems[i];
|
||||
|
||||
if (elem.nodeType === 3 // text node
|
||||
|| elem.nodeType === 4) // CDATA node
|
||||
{
|
||||
ret += elem.nodeValue;
|
||||
}
|
||||
|
||||
if (elem.nodeName === lineBreakNodeName )
|
||||
{
|
||||
if(elem.nodeType == 1 && $(elem).text() != ""){
|
||||
ret += "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(elem.nodeName === "BR"){
|
||||
ret += "\n";
|
||||
}
|
||||
|
||||
if (elem.nodeType !== 8) // comment node
|
||||
{
|
||||
ret += extractTextWithWhitespace(elem.childNodes, lineBreakNodeName);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
function extractTextWithWhitespace(elems)
|
||||
{
|
||||
var lineBreakNodeName = "BR"; // Use <br> as a default
|
||||
if ($.browser.webkit)
|
||||
{
|
||||
lineBreakNodeName = "DIV";
|
||||
}
|
||||
else if ($.browser.msie)
|
||||
{
|
||||
lineBreakNodeName = "P";
|
||||
}
|
||||
else if ($.browser.mozilla)
|
||||
{
|
||||
lineBreakNodeName = "BR";
|
||||
}
|
||||
else if ($.browser.opera)
|
||||
{
|
||||
lineBreakNodeName = "P";
|
||||
}
|
||||
var extractedText = extractTextWithWhitespaceWorker(elems, lineBreakNodeName);
|
||||
|
||||
return extractedText;
|
||||
}
|
||||
|
||||
return extractTextWithWhitespace(this.contents());
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.drcontenteditable = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.drcontenteditable' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.drcontenteditable.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
181
frontend/static/js/common/createproblem.js
Normal file
181
frontend/static/js/common/createproblem.js
Normal file
@@ -0,0 +1,181 @@
|
||||
(function( $ ){
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.createproblem.options, options );
|
||||
|
||||
return this.each(function(){
|
||||
|
||||
$("#createProblemMarkContainer").markinput("init",{adjustLeftComponent:$("#problemModalBody")});
|
||||
|
||||
|
||||
|
||||
$("#createProblemSummary").on("keydown",function(e){
|
||||
var keyCode = e.keyCode;
|
||||
if(keyCode == 13){
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
});
|
||||
$("#createProblemSummary").on("paste",function(e){
|
||||
var pasteText = e.originalEvent.clipboardData.getData("text/plain");
|
||||
pasteText = pasteText.replace(/\r\n/g,"");
|
||||
pasteText = pasteText.replace(/\r/g,"");
|
||||
pasteText = pasteText.replace(/\n/g,"");
|
||||
document.execCommand("insertHTML", false, pasteText);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
//统计字数
|
||||
$("#createProblemSummary").on("keydown cut copy paste",function(){
|
||||
setTimeout(function(){
|
||||
|
||||
$("#createProblemModel").modal("adjustBackdrop");
|
||||
|
||||
var inputText = $("#createProblemSummary").text();
|
||||
if(inputText.length > 500){
|
||||
$("#problemSummaryLimit").show();
|
||||
$("#problemSummaryLimit").css("color","red");
|
||||
$("#problemSummaryLimit").text(inputText.length + " / 500");
|
||||
}else if(inputText.length > 350){
|
||||
$("#problemSummaryLimit").show();
|
||||
$("#problemSummaryLimit").css("color","#838383");
|
||||
$("#problemSummaryLimit").text(inputText.length + " / 500");
|
||||
}else{
|
||||
$("#problemSummaryLimit").hide();
|
||||
}
|
||||
|
||||
},0);
|
||||
});
|
||||
|
||||
$("#createProblemContent").on("keydown cut copy paste",function(){
|
||||
setTimeout(function(){
|
||||
var inputText = $("#createProblemContent").val();
|
||||
if(inputText.length > 100){
|
||||
$("#problemContentLimit").show();
|
||||
$("#problemContentLimit").css("color","red");
|
||||
$("#problemContentLimit").text(inputText.length + " / 100");
|
||||
}else if(inputText.length > 80){
|
||||
$("#problemContentLimit").show();
|
||||
$("#problemContentLimit").css("color","#838383");
|
||||
$("#problemContentLimit").text(inputText.length + " / 100");
|
||||
}else{
|
||||
$("#problemContentLimit").hide();
|
||||
}
|
||||
|
||||
},0);
|
||||
});
|
||||
|
||||
|
||||
$("#createProblemCancel").on("click",function(){
|
||||
$("#createProblemModel").modal("hide");
|
||||
});
|
||||
|
||||
$("#createProblemSubmit").on("click",function(){
|
||||
var problemContent = $("#createProblemContent").val();
|
||||
var problemSummary = $("#createProblemSummary").text();
|
||||
if(problemContent.length <= 0){
|
||||
$("#drTipbar").drtipbar("showMsg","请输入问题");
|
||||
return;
|
||||
}
|
||||
if(problemContent.length > 100){
|
||||
$("#drTipbar").drtipbar("showMsg","问题内容最多100个字");
|
||||
return;
|
||||
}
|
||||
if(problemSummary.length > 500){
|
||||
$("#drTipbar").drtipbar("showMsg","问题描述最多500个字");
|
||||
return;
|
||||
}
|
||||
|
||||
//验证是否以问号结尾
|
||||
var lastStr = problemContent.substr(problemContent.length - 1,problemContent.length);
|
||||
if(lastStr != '?' && lastStr != '?'){
|
||||
$("#drTipbar").drtipbar("showMsg","问题必须以问号结尾");
|
||||
return;
|
||||
}
|
||||
|
||||
problemContent = encodeURIComponent(problemContent);
|
||||
problemSummary = encodeURIComponent(problemSummary);
|
||||
|
||||
var markArr = $("#createProblemMarkContainer").markinput("getMarkArray");
|
||||
if(markArr.length == 0){
|
||||
$("#drTipbar").drtipbar("showMsg","问题必须带标签");
|
||||
return;
|
||||
}
|
||||
var markDataString = JSON.stringify(markArr);
|
||||
markDataString = encodeURIComponent(markDataString);
|
||||
|
||||
$("#createProblemSubmit").attr("disabled",true);
|
||||
jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/problems/create",
|
||||
data : "content="+problemContent+"&summary="+problemSummary+"&markstr="+markDataString,
|
||||
beforeSend: function(request) {
|
||||
|
||||
$('#loadingBar').drloadingbar("startLoad");
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
//disable不能去除,在页面跳转前会有再被点的风险
|
||||
$.drWindowLocation("/problems/get?guid="+data.guid,true);
|
||||
|
||||
|
||||
|
||||
},
|
||||
error : function(data){
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
$("#createProblemSubmit").removeAttr("disabled");
|
||||
|
||||
if(data.responseJSON == null){
|
||||
$("#drTipbar").drtipbar("showMsg","网络不给力");
|
||||
}else{
|
||||
if(data.responseJSON.errCode != null){
|
||||
$("#drTipbar").drtipbar("showMsg",data.responseJSON.errMessage);
|
||||
|
||||
}else{
|
||||
$("#drTipbar").drtipbar("showMsg","网络不给力");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
modalShow:function(){
|
||||
|
||||
$("#createProblemModel").modal("show");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.createproblem = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.createproblem' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.createproblem.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
71
frontend/static/js/common/file-input.js
Normal file
71
frontend/static/js/common/file-input.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* file-input.js
|
||||
* target container must be id "preview"
|
||||
*/
|
||||
function previewImage(file,className,id)
|
||||
{
|
||||
var MAXWIDTH,MAXHEIGHT;
|
||||
var div = $('#'+id).get(0);
|
||||
if(className==='preview-long'){
|
||||
MAXWIDTH = 200;
|
||||
MAXHEIGHT = 356;
|
||||
}
|
||||
else if(className==='preview-short'){
|
||||
MAXWIDTH = 200;
|
||||
MAXHEIGHT = 300;
|
||||
}
|
||||
else{
|
||||
MAXWIDTH = 120;
|
||||
MAXHEIGHT = 120;
|
||||
}
|
||||
if (file.files && file.files[0])
|
||||
{
|
||||
div.innerHTML = '<img class=imghead>';
|
||||
var img = $('#'+id).find('.imghead').get(0);
|
||||
img.onload = function(){
|
||||
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
|
||||
img.width = rect.width;
|
||||
img.height = rect.height;
|
||||
img.style.marginLeft = rect.left+'px';
|
||||
img.style.marginTop = rect.top+'px';
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt){img.src = evt.target.result;}
|
||||
reader.readAsDataURL(file.files[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
|
||||
file.select();
|
||||
var src = document.selection.createRange().text;
|
||||
div.innerHTML = '<img class=imghead>';
|
||||
var img = $('#'+id).find('.imghead').get(0);
|
||||
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
|
||||
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
|
||||
status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
|
||||
div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";
|
||||
}
|
||||
$('.file').attr('name','image');
|
||||
|
||||
}
|
||||
|
||||
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
|
||||
var param = {top:0, left:0, width:width, height:height};
|
||||
if( width>maxWidth || height>maxHeight )
|
||||
{
|
||||
rateWidth = width / maxWidth;
|
||||
rateHeight = height / maxHeight;
|
||||
if( rateWidth > rateHeight )
|
||||
{
|
||||
param.width = maxWidth;
|
||||
param.height = Math.round(height / rateWidth);
|
||||
}else
|
||||
{
|
||||
param.width = Math.round(width / rateHeight);
|
||||
param.height = maxHeight;
|
||||
}
|
||||
}
|
||||
param.left = Math.round((maxWidth - param.width) / 2);
|
||||
param.top = Math.round((maxHeight - param.height) / 2);
|
||||
return param;
|
||||
}
|
39
frontend/static/js/common/form-validation.js
Normal file
39
frontend/static/js/common/form-validation.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* form validation
|
||||
*/
|
||||
function formValidation(_element){
|
||||
if(_element.next('.help-block').length<1){
|
||||
var $help_block=$('<span class="help-block"></span>');
|
||||
$help_block.insertAfter(_element);
|
||||
}
|
||||
// 验证错误
|
||||
if(!_element.valid()){
|
||||
_element.next('.help-block').children('.iconfont.success').remove();
|
||||
if(_element.next('.help-block').children('.iconfont').length<1){
|
||||
var $error_icon=$('<i class="iconfont fl error" ></i>');
|
||||
$error_icon.insertBefore(_element.next('.help-block').children('h5'));
|
||||
}
|
||||
}
|
||||
// 验证成功
|
||||
else{
|
||||
_element.next('.help-block').children('.iconfont.error').remove();
|
||||
if(_element.next('.help-block').children('.iconfont').length<1){
|
||||
var $success_icon=$('<i class="iconfont fl success" ></i>');
|
||||
$success_icon.insertBefore(_element.next('.help-block').children('h5'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function errorMessageShow(error,element){
|
||||
if(element.next('.help-block').length<1){
|
||||
var $help_block=$('<span class="help-block"></span>');
|
||||
$help_block.insertAfter(element);
|
||||
}
|
||||
error.appendTo(element.next('.help-block'));
|
||||
element.next('.help-block').children('.iconfont.success').remove();
|
||||
if(element.next('.help-block').children('.iconfont').length<1){
|
||||
var $error_icon=$('<i class="iconfont fl error" ></i>');
|
||||
$error_icon.insertBefore(element.next('.help-block').children('h5'));
|
||||
}
|
||||
}
|
16
frontend/static/js/common/gldatepicker.min.js
vendored
Normal file
16
frontend/static/js/common/gldatepicker.min.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/*! glDatePicker v2.0 | Tue Jan 1 2013 | http://glad.github.com/glDatePicker/ */;
|
||||
(function(){$.fn.glDatePicker=function(a){var G=this.data("glDatePicker");return!G?this.each(function(){return $(this).data("glDatePicker",new O(this,a))}):!0===a?G:this};$.fn.glDatePicker.defaults={cssName:"default",zIndex:1E3,borderSize:1,calendarOffset:{x:0,y:1},showAlways:!1,hideOnClick:!0,allowMonthSelect:!0,allowYearSelect:!0,todayDate:new Date,selectedDate:null,prevArrow:"\u25c4",nextArrow:"\u25ba",selectableDates:null,selectableDateRange:null,specialDates:null,selectableMonths:null,selectableYears:null,
|
||||
selectableDOW:null,monthNames:null,dowNames:null,dowOffset:0,onClick:function(a,G,g){a.val(g.toLocaleDateString())},onHover:function(){},onShow:function(a){a.show()},onHide:function(a){a.hide()},firstDate:null};var O=function(){function a(a,g){var d=this;d.el=$(a);var b=d.el;d.options=$.extend(!0,{},$.fn.glDatePicker.defaults,g);var c=d.options;d.calendar=$($.find("[gldp-el="+b.attr("gldp-id")+" ]"));c.selectedDate=c.selectedDate||c.todayDate;c.firstDate=(new Date(c.firstDate||c.selectedDate))._first();
|
||||
(b.attr("gldp-id")||"").length||b.attr("gldp-id","gldp-"+Math.round(1E10*Math.random()));b.addClass("gldp-el").bind("click",function(b){d.show(b)}).bind("focus",function(b){d.show(b)});d.calendar.length&&!c.showAlways&&d.calendar.hide();$(document).bind("mouseup",function(a){var a=a.target,c=d.calendar;!b.is(a)&&(!c.is(a)&&0===c.has(a).length&&c.is(":visible"))&&d.hide()});d.render()}a.prototype={show:function(){$.each($(".gldp-el").not(this.el),function(a,g){if(g.length)g.options.onHide(g.calendar)});
|
||||
this.options.onShow(this.calendar)},hide:function(){if(this.options&&!this.options.showAlways)this.options.onHide(this.calendar)},render:function(a){var g=this,d=g.el,b=g.options,c=g.calendar,j="gldp-"+b.cssName,t=b.todayDate._val(),u=t.time,h=b.borderSize+"px",y=function(b,m,a){for(var c=[],e=b;e<=m;e++)c.push(e);if(a){var d=[];$.each(a,function(a,c){c>=b&&(c<=m&&0>d._indexOf(c))&&d.push(c)});c=d.length?d:c}c.sort();return c},H=y(0,11,b.selectableMonths),v=y(t.year-5,t.year+5,b.selectableYears),
|
||||
y=y(0,6,b.selectableDOW),z=b.dowNames||"Sun Mon Tue Wed Thu Fri Sat".split(" "),t=b.monthNames||"January February March April May June July August September October November December".split(" "),f=d.outerWidth(),e,k=f/7+6*(b.borderSize/7),f=f/8+7*(b.borderSize/8);c.length?eval(c.data("is"))||(f=c.outerWidth(),e=c.outerHeight(),k=f/7+6*(b.borderSize/7),f=e/8+7*(b.borderSize/8)):(g.calendar=c=$("<div/>").attr("gldp-el",d.attr("gldp-id")).data("is",!0).css({display:b.showAlways?void 0:"none",zIndex:b.zIndex,
|
||||
width:7*k+"px"}),$("body").append(c));d.is(":visible")||c.hide();c.removeClass().addClass(j).children().remove();j=function(){var i=d.offset();c.css({top:i.top+d.outerHeight()+b.calendarOffset.y+"px",left:i.left+b.calendarOffset.x+"px"})};$(window).resize(j);j();var j={width:k+"px",height:f+"px",lineHeight:f+"px"},f=function(i){for(var m=new Date(b.firstDate),i=i||0;;){m.setMonth(m.getMonth()+i);m.setDate(Math.min(1,m._max()));if(0==i)break;var c=m._val(),a=c.year;if(-1!=H._indexOf(c.month))if(-1!=
|
||||
v._indexOf(a))break;else if(a<v[0]||a>v[v.length-1])return null}return m},A=f(-1),B=f(1),f=b.firstDate=f();e=f._val();var I=e.month,J=e.year,f=new Date(f);e=Math.abs(Math.min(6,Math.max(0,b.dowOffset)));var l=f.getDay()-e,l=1>l?-7-l:-l,z=z.concat(z).slice(e,e+7);f._add(l);e=$("<div/>").addClass(" core border monyear ").css($.extend({},j,{borderWidth:h+" 0 0 "+h})).append($("<a/>").addClass("prev-arrow"+(A?"":"-off")).html(b.prevArrow)).mousedown(function(){return!1}).click(function(i){""!=b.prevArrow&&
|
||||
A&&(i.stopPropagation(),A&&(b.firstDate=A,g.render()))});k=5*k-5*b.borderSize+b.borderSize;k=$("<div/>").addClass(" core border monyear title").css($.extend({},j,{width:k+"px",borderTopWidth:h,marginLeft:"-"+h}));l=$("<div/>").addClass(" core border monyear ").css($.extend({},j,{marginLeft:"-"+h,borderWidth:h+" "+h+" 0 0"})).append($("<a/>").addClass("next-arrow"+(B?"":"-off")).html(b.nextArrow)).mousedown(function(){return!1}).click(function(i){""!=b.nextArrow&&B&&(i.stopPropagation(),B&&(b.firstDate=
|
||||
B,g.render()))});c.append(e).append(k).append(l);for(l=e=0;7>e;e++)for(var q=0;7>q;q++,l++){var C=new Date(f),n="day",r=b.zIndex+l,w=$("<div/>");if(e){C._add(q+7*(e-1));var p=C._val(),x=p.time,K=null,s=!0,D=function(b,a){!0===b.repeatYear&&a.setYear(p.year);!0===b.repeatMonth&&a.setMonth(p.month);return a._val()};w.html(p.date);b.selectableDateRange&&(s=!1,$.each(b.selectableDateRange,function(b,a){var c=a.from,d=a.to||null,d=d||new Date(a.from.getFullYear(),a.from.getMonth(),a.from._max()),c=D(a,
|
||||
c),d=D(a,d);if(x>=c.time&&x<=d.time)return s=!0}));if(b.selectableDates){if(b.selectableDateRange&&!s||s&&!b.selectableDateRange)s=!1;$.each(b.selectableDates,function(b,a){if(D(a,a.date).time==x)return s=!0})}!s||0>v._indexOf(p.year)||0>H._indexOf(p.month)||0>y._indexOf(p.day)?n="noday":(n="sun mon tue wed thu fri sat".split(" ")[p.day],I!=p.month&&(n+=" outday"),u==x&&(n="today",r+=50),b.selectedDate._time()==x&&(n="selected",r+=51),b.specialDates&&$.each(b.specialDates,function(b,a){D(a,a.date).time==
|
||||
x&&(n=a.cssClass||"special",r+=52,K=a.data)}),w.mousedown(function(){return!1}).hover(function(a){a.stopPropagation();a=$(this).data("data");b.onHover(d,w,a.date,a.data)}).click(function(a){a.stopPropagation();a=$(this).data("data");b.selectedDate=b.firstDate=a.date;g.render(function(){!b.showAlways&&b.hideOnClick&&g.hide()});b.onClick(d,$(this),a.date,a.data)}))}else n="dow",w.html(z[q]),C=null;$.extend(j,{borderTopWidth:h,borderBottomWidth:h,borderLeftWidth:0<e||!e&&!q?h:0,borderRightWidth:0<e||
|
||||
!e&&6==q?h:0,marginLeft:0<q?"-"+h:0,marginTop:0<e?"-"+h:0,zIndex:r});w.data("data",{date:C,data:K}).addClass(" core border "+n).css(j);c.append(w)}var N=function(a){b.allowMonthSelect&&(L.css({display:!a?"none":"inline-block"}),E.css({display:!a?"inline-block":"none"}));b.allowYearSelect&&(M.css({display:a?"none":"inline-block"}),F.css({display:a?"inline-block":"none"}))},u=function(){b.firstDate=new Date(F.val(),E.val(),1);g.render()},E=$("<select/>").hide().change(u),F=$("<select/>").hide().change(u),
|
||||
L=$("<span/>").html(t[I]).mousedown(function(){return!1}).click(function(a){a.stopPropagation();N(!1)}),M=$("<span/>").html(J).mousedown(function(){return!1}).click(function(a){a.stopPropagation();N(!0)});$.each(t,function(a,c){if(b.allowMonthSelect&&-1!=H._indexOf(a)){var d=$("<option/>").html(c).attr("value",a);a==I&&d.attr("selected","selected");E.append(d)}});$.each(v,function(a,c){if(b.allowYearSelect){var d=$("<option/>").html(c).attr("value",c);c==J&&d.attr("selected","selected");F.append(d)}});
|
||||
u=$("<div/>").append(L).append(E).append(M).append(F);k.children().remove();k.append(u);(a||function(){})()}};return a}();Date.prototype._clear=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this};Date.prototype._time=function(){return this._clear().getTime()};Date.prototype._max=function(){return[31,28+(1==(new Date(this.getYear(),1,29)).getMonth()?1:0),31,30,31,30,31,31,30,31,30,31][this.getMonth()]};Date.prototype._add=function(a){this.setDate(this.getDate()+
|
||||
a)};Date.prototype._first=function(){var a=new Date(this);a.setDate(1);return a};Date.prototype._val=function(){this._clear();return{year:this.getFullYear(),month:this.getMonth(),date:this.getDate(),time:this.getTime(),day:this.getDay()}};Array.prototype._indexOf=function(a){return $.inArray(a,this)}})();
|
39
frontend/static/js/common/imgPreview.js
Normal file
39
frontend/static/js/common/imgPreview.js
Normal file
@@ -0,0 +1,39 @@
|
||||
jQuery.fn.extend({
|
||||
imgPreview: function (opts) {
|
||||
var _self = this,
|
||||
_this = $(this);
|
||||
opts = jQuery.extend({
|
||||
id: "imgPreview",
|
||||
width: '100px',
|
||||
height: '100px',
|
||||
imgType: ["gif", "jpeg", "jpg", "bmp", "png"],
|
||||
callback: function () {}
|
||||
}, opts || {});
|
||||
$("#" + opts.id).css({
|
||||
'width': opts.width,
|
||||
'height': opts.height
|
||||
});
|
||||
_self.getObjectURL = function (file) {
|
||||
var url = null;
|
||||
if (window.createObjectURL != undefined) {
|
||||
url = window.createObjectURL(file);
|
||||
} else if (window.URL != undefined) {
|
||||
url = window.URL.createObjectURL(file);
|
||||
} else if (window.webkitURL != undefined) {
|
||||
url = window.webkitURL.createObjectURL(file);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
_this.change(function () {
|
||||
if (this.value) {
|
||||
if (!RegExp("\.(" + opts.imgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
|
||||
alert("选择文件错误,图片类型必须是" + opts.imgType.join(",") + "中的一种");
|
||||
this.value = "";
|
||||
return false;
|
||||
}
|
||||
$("#" + opts.id).attr('src', _self.getObjectURL(this.files[0]));
|
||||
opts.callback();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
1
frontend/static/js/common/jquery.imgareaselect.pack.js
Normal file
1
frontend/static/js/common/jquery.imgareaselect.pack.js
Normal file
File diff suppressed because one or more lines are too long
37
frontend/static/js/common/leftBar.js
Normal file
37
frontend/static/js/common/leftBar.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* LeftBar Generate
|
||||
*/
|
||||
var LeftBar=function(){
|
||||
|
||||
var MarkCategory=function(text,markcategories_Array){
|
||||
/* LeftBar init*/
|
||||
$('.leftbar .title').text(text);
|
||||
$('.mark-category li:first').addClass('active');
|
||||
|
||||
/* 切换标签类别 */
|
||||
$(document).on('click','.mark-category li',function(){
|
||||
var $this=$(this);
|
||||
$('.mark-category li').removeClass('active');
|
||||
$this.addClass('active');
|
||||
$('.mark-category').hide();
|
||||
$('.leftbar .title').text($this.text());
|
||||
var index=$this.attr('id');
|
||||
$('.bar-content li:not(:first)').remove();
|
||||
for(var i=0;i<markcategories_Array[index].marks.length;i++){
|
||||
$('.bar-content').append('<li><a href="/marks/listscreenshotbymark?mark_id='+markcategories_Array[index].marks[i].id+'">'+markcategories_Array[index].marks[i].name+'</a></li>');
|
||||
}
|
||||
})
|
||||
/* 显示隐藏标签类别 */
|
||||
$(".dropdown-area").hover(function(){
|
||||
$('.mark-category').stop().slideDown('fast');
|
||||
},function(){
|
||||
$('.mark-category').stop().slideUp('fast');
|
||||
})
|
||||
};
|
||||
|
||||
return {
|
||||
init:function(text,markcategories_Array){
|
||||
MarkCategory(text,markcategories_Array);
|
||||
}
|
||||
};
|
||||
}();
|
334
frontend/static/js/common/loadMoreData.js
Normal file
334
frontend/static/js/common/loadMoreData.js
Normal file
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* ajax load more data
|
||||
*/
|
||||
|
||||
/**
|
||||
* 加载更多(供index&标签详情使用)
|
||||
*/
|
||||
function loadData(params){
|
||||
/* 打开页面首次加载数据 */
|
||||
var returnJson={};
|
||||
getReturnJson(returnJson,params);
|
||||
|
||||
/* 点击加载更多 */
|
||||
$('.loadMore').click(function(){
|
||||
/* 正常加载数据 */
|
||||
if(returnJson.status===0){
|
||||
params.page++;
|
||||
getReturnJson(returnJson,params);
|
||||
}
|
||||
/* 没有更多数据 */
|
||||
else if(returnJson.status===1){
|
||||
$('.loadTips').text('没有更多数据').stop().fadeIn(500).fadeOut(1500);
|
||||
}
|
||||
/* 加载数据异常,重试 */
|
||||
else{
|
||||
getReturnJson(returnJson,params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//获取ajax的success or error回调函数返回的JSON
|
||||
function getReturnJson(returnJson,params){
|
||||
Disabled($('.loadMore'),'');
|
||||
Loading($('.loadMore'));
|
||||
$.when(getScreenShotList(params.url,params.page))
|
||||
.done(function(data){
|
||||
returnJson.status=data.status;
|
||||
returnJson.msg=data.msg;
|
||||
})
|
||||
.fail(function(data){
|
||||
returnJson.status=data.status;
|
||||
returnJson.msg=data.msg;
|
||||
});
|
||||
}
|
||||
|
||||
//获取ScreenShotList
|
||||
/* 加载更多(供index&标签详情使用) */
|
||||
function getScreenShotList(url,page){
|
||||
var returnJson={};
|
||||
var defer=$.Deferred();
|
||||
|
||||
/* ajax请求获取数据 */
|
||||
$.ajax({
|
||||
type:"GET",
|
||||
url:url,
|
||||
dataType:'json',
|
||||
data:{
|
||||
page:page
|
||||
},
|
||||
contentType : 'application/json',
|
||||
success:function(data,status){
|
||||
console.log(status);
|
||||
console.log('screenshots:'+data);
|
||||
//获取json数据不为空
|
||||
if(data.content.length>0){
|
||||
/* 遍历screenshorts */
|
||||
$.each(data.content,function(key,value){
|
||||
$('.shot-container').append(
|
||||
'<div class="shot third column" id="screenshot'+value.id+'" data-application="">'+
|
||||
'<div class="shot-image">'+
|
||||
'<div class="actions">'+
|
||||
'</div>'+
|
||||
'<img src="http://www.placehold.it/286x508/EFEFEF/AAAAAA&text=egggo.cn" data-url="'+value.pic.mediumFileUrl+'" class="unload"/>'+
|
||||
'<div class="cover"></div>'+
|
||||
'</div>'+
|
||||
'<div class="shot-info">'+
|
||||
'<div class="text-overflow"><a class="two-thirds dark-gray text-align-left" href="/applications/get/'+value.application.id+'" target="_blank">'+value.application.name+'</a></div>'+
|
||||
'<div class="third text-align-right fr"><i class="iconfont like-count inline-block"></i><h6>'+value.likeCount+'</h6></div>'+
|
||||
'<div id="'+value.id+'" class="mark-container light-gray" name="screenshot-mark-container">'+
|
||||
'<h6 class="text-overflow">'+
|
||||
'</h6>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'
|
||||
);
|
||||
var marks=[],screenShotContents=[],application={};
|
||||
|
||||
/* LikeOrNot */
|
||||
if(value.isLiked===0){
|
||||
$('#screenshot'+value.id).find('.actions').append(
|
||||
'<a class="btn-like text-align-center" id="'+value.id+'" onclick="like(this,'+value.id+')">'+
|
||||
'<i class="iconfont unlike inline-block is-hidden"></i>'+
|
||||
'<i class="iconfont liked inline-block"></i>'+
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
else{
|
||||
$('#screenshot'+value.id).find('.actions').append(
|
||||
'<a class="btn-like text-align-center" id="'+value.id+'" onclick="unlike(this,'+value.id+')">'+
|
||||
'<i class="iconfont unlike inline-block"></i>'+
|
||||
'<i class="iconfont liked inline-block is-hidden"></i>'+
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
|
||||
/* 遍历marks */
|
||||
$.each(value.marks,function(k,v){
|
||||
$('#screenshot'+value.id).find('.mark-container').find('.text-overflow').append(
|
||||
'<a href="/screenshots/searchscreenshot?search='+v.name+'" target="_blank">'+v.name+'</a>'+
|
||||
'<span> , </span>'
|
||||
);
|
||||
marks.push({
|
||||
id:v.id,
|
||||
name:v.name
|
||||
});
|
||||
});
|
||||
/* 遍历ScreenshotsContent */
|
||||
$.each(value.screenShotContents,function(k,v){
|
||||
screenShotContents.push({
|
||||
type:v.type,
|
||||
url:v.pic.mediumFileUrl+'&method=attachment'
|
||||
});
|
||||
});
|
||||
//浏览图片Modal需要的数据
|
||||
var application={
|
||||
screenShotId:value.id,
|
||||
pic:value.pic.originFileUrl,
|
||||
appVersion:value.appVersion,
|
||||
likeCount:value.likeCount,
|
||||
applicationName:value.application.name,
|
||||
applicationIcon:value.application.icon.thumbFileUrl,
|
||||
updatedTime:value.createdAt,
|
||||
marks:marks,
|
||||
screenShotContents:screenShotContents
|
||||
};
|
||||
$('#screenshot'+value.id).data('application',application)
|
||||
.find('.mark-container').find('span:last').remove();
|
||||
});
|
||||
lazyload();
|
||||
returnJson.status=0;
|
||||
returnJson.msg='正常加载数据';
|
||||
Enabled($('.loadMore'),'加载更多');
|
||||
}
|
||||
else{
|
||||
console.log('page out of range');
|
||||
$('.loadTips').text('没有更多数据').stop().fadeIn(500).fadeOut(1500);
|
||||
returnJson.status=1;
|
||||
returnJson.msg='没有更多数据';
|
||||
Enabled($('.loadMore'),'没有更多了');
|
||||
}
|
||||
$('#footer-total-count,#resultsCount').text(data.count);
|
||||
defer.resolve(returnJson);
|
||||
},
|
||||
error:function(data,status){
|
||||
console.log(status);
|
||||
Enabled($('.loadMore'),'加载更多');
|
||||
$('.loadTips').text('加载数据异常,请重试!').stop().fadeIn(500).fadeOut(2000);
|
||||
returnJson.status=2;
|
||||
returnJson.msg='加载数据异常';
|
||||
defer.reject(returnJson);
|
||||
}
|
||||
});
|
||||
return defer.promise();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 加载更多(供搜索标签结果使用)
|
||||
*/
|
||||
function loadSearchScreenshotsData(params,keyword){
|
||||
/* 打开页面首次加载数据 */
|
||||
var returnJson={};
|
||||
getSearchReturnJson(returnJson,params,keyword);
|
||||
|
||||
/* 点击加载更多 */
|
||||
$('.loadMore').click(function(){
|
||||
/* 正常加载数据 */
|
||||
if(returnJson.status===0){
|
||||
params.page++;
|
||||
getSearchReturnJson(returnJson,params,keyword);
|
||||
}
|
||||
/* 没有更多数据 */
|
||||
else if(returnJson.status===1){
|
||||
$('.loadTips').text('没有更多数据').stop().fadeIn(500).fadeOut(1500);
|
||||
}
|
||||
/* 加载数据异常,重试 */
|
||||
else{
|
||||
getSearchReturnJson(returnJson,params,keyword);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//获取ajax的success or error回调函数返回的JSON
|
||||
function getSearchReturnJson(returnJson,params,keyword){
|
||||
Disabled($('.loadMore'),'');
|
||||
Loading($('.loadMore'));
|
||||
$.when(getSearchScreenShotList(params.url,params.page,keyword))
|
||||
.done(function(data){
|
||||
returnJson.status=data.status;
|
||||
returnJson.msg=data.msg;
|
||||
lazyload();
|
||||
})
|
||||
.fail(function(data){
|
||||
returnJson.status=data.status;
|
||||
returnJson.msg=data.msg;
|
||||
});
|
||||
}
|
||||
|
||||
//获取SearchScreenShotList
|
||||
function getSearchScreenShotList(url,page,keyword){
|
||||
var returnJson={};
|
||||
var defer=$.Deferred();
|
||||
|
||||
/* ajax请求获取数据 */
|
||||
$.ajax({
|
||||
type:"GET",
|
||||
url:url,
|
||||
dataType:'json',
|
||||
data:{
|
||||
page:page
|
||||
},
|
||||
contentType : 'application/json',
|
||||
success:function(data,status){
|
||||
console.log(status);
|
||||
console.log('screenshots:'+data);
|
||||
//获取json数据不为空
|
||||
if(data.content.length>0){
|
||||
/* 遍历screenshorts */
|
||||
$.each(data.content,function(key,value){
|
||||
$('.shot-container').append(
|
||||
'<div class="shot third column" id="screenshot'+value.id+'" data-application="">'+
|
||||
'<div class="shot-image">'+
|
||||
'<div class="actions">'+
|
||||
'</div>'+
|
||||
'<img src="http://www.placehold.it/286x508/EFEFEF/AAAAAA&text=egggo.cn" data-url="'+value.pic.mediumFileUrl+'" class="unload"/>'+
|
||||
'<div class="cover"></div>'+
|
||||
'</div>'+
|
||||
'<div class="shot-info">'+
|
||||
'<div class="text-overflow"><a class="two-thirds dark-gray text-align-left" href="/applications/get/'+value.application.id+'" target="_blank">'+value.application.name+'</a></div>'+
|
||||
'<div class="third text-align-right fr"><i class="iconfont like-count inline-block"></i><h6>'+value.likeCount+'</h6></div>'+
|
||||
'<div id="'+value.id+'" class="mark-container light-gray" name="screenshot-mark-container">'+
|
||||
'<h6 class="text-overflow">'+
|
||||
'</h6>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'
|
||||
);
|
||||
var marks=[],screenShotContents=[],application={};
|
||||
/* LikeOrNot */
|
||||
if(value.isLiked===0){
|
||||
$('#screenshot'+value.id).find('.actions').append(
|
||||
'<a class="btn-like text-align-center" id="'+value.id+'" onclick="like(this,'+value.id+')">'+
|
||||
'<i class="iconfont unlike inline-block is-hidden"></i>'+
|
||||
'<i class="iconfont liked inline-block"></i>'+
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
else{
|
||||
$('#screenshot'+value.id).find('.actions').append(
|
||||
'<a class="btn-like text-align-center" id="'+value.id+'" onclick="unlike(this,'+value.id+')">'+
|
||||
'<i class="iconfont unlike inline-block"></i>'+
|
||||
'<i class="iconfont liked inline-block is-hidden"></i>'+
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
/* 遍历marks */
|
||||
$.each(value.marks,function(k,v){
|
||||
if(v.name.indexOf(keyword)>-1){
|
||||
$('#screenshot'+value.id).find('.mark-container').find('.text-overflow').append(
|
||||
'<a href="/screenshots/searchscreenshot?search='+v.name+'" class="highlight" target="_blank">'+v.name+'</a>'+
|
||||
'<span> , </span>'
|
||||
);
|
||||
}else{
|
||||
$('#screenshot'+value.id).find('.mark-container').find('.text-overflow').append(
|
||||
'<a href="/screenshots/searchscreenshot?search='+v.name+'" target="_blank">'+v.name+'</a>'+
|
||||
'<span> , </span>'
|
||||
);
|
||||
}
|
||||
marks.push({
|
||||
id:v.id,
|
||||
name:v.name
|
||||
});
|
||||
});
|
||||
/* 遍历ScreenshotsContent */
|
||||
$.each(value.screenShotContents,function(k,v){
|
||||
screenShotContents.push({
|
||||
type:v.type,
|
||||
url:v.pic.mediumFileUrl+'&method=attachment'
|
||||
});
|
||||
});
|
||||
//浏览图片Modal需要的数据
|
||||
var application={
|
||||
screenShotId:value.id,
|
||||
pic:value.pic.originFileUrl,
|
||||
appVersion:value.appVersion,
|
||||
likeCount:value.likeCount,
|
||||
applicationName:value.application.name,
|
||||
applicationIcon:value.application.icon.thumbFileUrl,
|
||||
updatedTime:value.createdAt,
|
||||
marks:marks,
|
||||
screenShotContents:screenShotContents
|
||||
};
|
||||
$('#screenshot'+value.id).data('application',application)
|
||||
.find('.mark-container').find('span:last').remove();
|
||||
});
|
||||
lazyload();
|
||||
returnJson.status=0;
|
||||
returnJson.msg='正常加载数据';
|
||||
Enabled($('.loadMore'),'加载更多');
|
||||
}
|
||||
else{
|
||||
console.log('page out of range');
|
||||
$('.loadTips').text('没有更多数据').stop().fadeIn(500).fadeOut(1500);
|
||||
returnJson.status=1;
|
||||
returnJson.msg='没有更多数据';
|
||||
Enabled($('.loadMore'),'没有更多了');
|
||||
}
|
||||
$('#footer-total-count,#resultsCount').text(data.count);
|
||||
defer.resolve(returnJson);
|
||||
},
|
||||
error:function(data,status){
|
||||
console.log(status);
|
||||
Enabled($('.loadMore'),'加载更多');
|
||||
$('.loadTips').text('加载数据异常,请重试!').stop().fadeIn(500).fadeOut(2000);
|
||||
returnJson.status=2;
|
||||
returnJson.msg='加载数据异常';
|
||||
defer.reject(returnJson);
|
||||
}
|
||||
});
|
||||
return defer.promise();
|
||||
}
|
88
frontend/static/js/common/loadingbar.js
Normal file
88
frontend/static/js/common/loadingbar.js
Normal file
@@ -0,0 +1,88 @@
|
||||
(function( $ ){
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.drloadingbar.options, options );
|
||||
$this.data("isLoading",false);
|
||||
$this.data("loadingLoop",false);
|
||||
return this.each(function(){
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
startLoad:function(){
|
||||
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
function loading(){
|
||||
|
||||
|
||||
$this.removeClass("loadingBarLoadStaticPhase").addClass("loadingBarLoadPhase1");
|
||||
$this.one(($.getTransitionEnd()).end, function() {
|
||||
|
||||
//$this.one('webkitTransitionEnd', function() {
|
||||
$this.removeClass("loadingBarLoadPhase1").addClass("loadingBarLoadStaticPhase");
|
||||
if($this.data("loadingLoop")){
|
||||
$this.data("nextTimer",setTimeout(loading,500));
|
||||
//setTimeout(loading,500);
|
||||
//loading();
|
||||
}else{
|
||||
//console.log("已停止");
|
||||
$this.data("isLoading",false);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
if(!$this.data("isLoading")){
|
||||
$this.data("isLoading",true);
|
||||
$this.data("loadingLoop",true);
|
||||
//console.log("开始");
|
||||
loading();
|
||||
}else{
|
||||
//console.log("运行中");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
stopLoad:function(){
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
//console.log("结束");
|
||||
$this.data("loadingLoop", false);
|
||||
|
||||
var timer = $this.data("nextTimer");
|
||||
if(timer != null){
|
||||
clearTimeout(timer);
|
||||
$this.data("nextTimer",null);
|
||||
$this.data("isLoading",false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.drloadingbar = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.drloadingbar' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.drloadingbar.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
482
frontend/static/js/common/markinput.js
Normal file
482
frontend/static/js/common/markinput.js
Normal file
@@ -0,0 +1,482 @@
|
||||
(function( $ ){
|
||||
|
||||
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.markinput.options, options );
|
||||
return this.each(function(){
|
||||
var $thisMarkInput = $(this);
|
||||
var markData = options.markData;
|
||||
if(markData == null){
|
||||
markData = [];
|
||||
}
|
||||
$thisMarkInput .data("markData",markData);
|
||||
var adjustLeftComponent = options.adjustLeftComponent;
|
||||
if(adjustLeftComponent != null){
|
||||
$thisMarkInput .data("adjustLeftComponent",adjustLeftComponent);
|
||||
}
|
||||
var $appendVar = $('<div id="drMarkInputContentContainer"><div id="drMarkInputContent" contentEditable="true" data-placeHolder="添加至多 3 个标签(输入标签后按回车确定)"></div></div>\
|
||||
<div id="drMarkInputErrorPopoverContainer" style="display:none;">\
|
||||
<div id="drMarkInputErrorPopover">\
|
||||
<p id="drMarkInputErrorPopoverContent">输入内容过长</p>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div id="drMarkInputPopoverSearchContainer" style="display:none;">\
|
||||
<ul id="drMarkInputPopoverSearch">\
|
||||
</ul>\
|
||||
</div>');
|
||||
$thisMarkInput.append($appendVar);
|
||||
|
||||
for(var i = 0; i < markData.length; i++){
|
||||
$element = $("<span></span>");
|
||||
$element.text(markData[i]);
|
||||
$element.addClass("drMarkSpanContainer");
|
||||
$element.insertBefore($("#drMarkInputContentContainer"));
|
||||
}
|
||||
|
||||
if(markData.length > 0){
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","");
|
||||
}else{
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","添加至多 3 个标签(输入标签后按回车确定)");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function isMarkInputErrorShown(){
|
||||
return $("#drMarkInputContent").data('bs.popover').tip().hasClass('in');
|
||||
}
|
||||
function isMarkSearchResShown(){
|
||||
return $("#drMarkInputContentContainer").data('bs.popover').tip().hasClass('in');
|
||||
}
|
||||
|
||||
function deleteOneMark($element){
|
||||
var markData = $thisMarkInput.data("markData");
|
||||
if(markData.length <= 0){
|
||||
return;
|
||||
}
|
||||
if($element == null){
|
||||
//删除最后一个
|
||||
$(".drMarkSpanContainer")[markData.length - 1].remove();
|
||||
markData.splice(markData.length-1,1);
|
||||
if(markData.length > 0){
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","");
|
||||
}else{
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","添加至多 3 个标签(输入标签后按回车确定)");
|
||||
}
|
||||
}else{
|
||||
|
||||
var tagName = $element.text();
|
||||
|
||||
for(var i = 0; i < markData.length; i++){
|
||||
if(markData[i] == tagName){
|
||||
markData.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(markData.length > 0){
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","");
|
||||
}else{
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","添加至多 3 个标签(输入标签后按回车确定)");
|
||||
}
|
||||
$element.remove();
|
||||
}
|
||||
}
|
||||
function addOneMark(markName){
|
||||
var markData = $thisMarkInput.data("markData");
|
||||
if(markName == ""){
|
||||
return;
|
||||
}else if(markName.length > 30){
|
||||
//提示长度
|
||||
$("#drMarkInputErrorPopoverContent").text("标签最大字数为 30 个");
|
||||
if(isMarkInputErrorShown()){
|
||||
|
||||
}else{
|
||||
$("#drMarkInputContent").popover("show");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i = 0; i < markData.length; i++){
|
||||
if(markName == markData[i]){
|
||||
//提示重复
|
||||
$("#drMarkInputErrorPopoverContent").text("已经添加了该标签");
|
||||
if(isMarkInputErrorShown()){
|
||||
|
||||
}else{
|
||||
$("#drMarkInputContent").popover("show");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
markData.push(markName);
|
||||
if(markData.length > 0){
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","");
|
||||
}else{
|
||||
$("#drMarkInputContent")[0].setAttribute("data-placeholder","添加至多 3 个标签(输入标签后按回车确定)");
|
||||
}
|
||||
|
||||
$element = $("<span></span>");
|
||||
$element.text(markName);
|
||||
$element.addClass("drMarkSpanContainer");
|
||||
$element.insertBefore($("#drMarkInputContentContainer"));
|
||||
$("#drMarkInputContent").text("");
|
||||
if(isMarkSearchResShown()){
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
}
|
||||
}
|
||||
|
||||
function searchMarkKeyword(keyword){
|
||||
if(keyword == null || keyword == ""){
|
||||
if(isMarkSearchResShown()){
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
}
|
||||
return;
|
||||
}
|
||||
keyword = encodeURIComponent(keyword);
|
||||
var jRequest = $.ajax({
|
||||
type : "GET",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/marks/searchforchoose?q="+keyword,
|
||||
beforeSend:function(){
|
||||
$('#loadingBar').drloadingbar("startLoad");
|
||||
var currentReq = $("#drMarkInputContentContainer").data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
success : function(data){
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
|
||||
var dataLength = data.length;
|
||||
if(dataLength > 0){
|
||||
if(isMarkSearchResShown()){
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
}
|
||||
$("#drMarkInputPopoverSearch").empty();
|
||||
for(var i = 0; i < dataLength; i++){
|
||||
$element = $("<li class='drMarkInputPopoverSearchList'><span><strong>"+data[i].name+"</strong>("+data[i].useCount+")</span></li>");
|
||||
$element.appendTo($("#drMarkInputPopoverSearch"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$("#drMarkInputContentContainer").popover("show");
|
||||
}else{
|
||||
if(isMarkSearchResShown()){
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
error : function(data){
|
||||
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
|
||||
}});
|
||||
$("#drMarkInputContentContainer").data("jRequest",jRequest);
|
||||
}
|
||||
$("#drMarkInputContent").on("paste",function(e){
|
||||
var markData = $thisMarkInput.data("markData");
|
||||
|
||||
if(markData.length >= 3){
|
||||
//提示只能输入3个标签
|
||||
$("#drMarkInputErrorPopoverContent").text("只能添加 3 个标签");
|
||||
if(isMarkInputErrorShown()){
|
||||
|
||||
}else{
|
||||
$("#drMarkInputContent").popover("show");
|
||||
}
|
||||
|
||||
|
||||
e.preventDefault();
|
||||
return
|
||||
}
|
||||
if(isMarkInputErrorShown()){
|
||||
$("#drMarkInputContent").popover("hide");
|
||||
}
|
||||
var pasteText = e.originalEvent.clipboardData.getData("text/plain");
|
||||
pasteText = pasteText.replace(/\r\n/g,"");
|
||||
pasteText = pasteText.replace(/\r/g,"");
|
||||
pasteText = pasteText.replace(/\n/g,"");
|
||||
document.execCommand("insertHTML", false, pasteText);
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
searchMarkKeyword($(this).text());
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#drMarkInputContent").on("blur",function(e){
|
||||
if(isMarkInputErrorShown()){
|
||||
$("#drMarkInputContent").popover("hide");
|
||||
}
|
||||
if(isMarkSearchResShown()){
|
||||
|
||||
setTimeout(function(){
|
||||
//延迟200毫秒触发,否则若点击在content cell内部则立马被hide掉,无法触发
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
},200);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$("#drMarkInputContent").on("keydown",function(e){
|
||||
|
||||
var markData = $thisMarkInput.data("markData");
|
||||
var keyCode = e.keyCode;
|
||||
if(keyCode == 8 || keyCode == 46){
|
||||
if(isMarkInputErrorShown()){
|
||||
$("#drMarkInputContent").popover("hide");
|
||||
}
|
||||
if($(this).text() == "" && markData.length > 0){
|
||||
deleteOneMark();
|
||||
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(markData.length >= 3){
|
||||
$(this).text("");
|
||||
//提示只能输入3个标签
|
||||
$("#drMarkInputErrorPopoverContent").text("只能添加 3 个标签");
|
||||
if(isMarkInputErrorShown()){
|
||||
|
||||
}else{
|
||||
$("#drMarkInputContent").popover("show");
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if(isMarkInputErrorShown()){
|
||||
$("#drMarkInputContent").popover("hide");
|
||||
}
|
||||
|
||||
|
||||
if(keyCode == 13 || keyCode == 108){
|
||||
e.preventDefault();
|
||||
if(isMarkInputErrorShown()){
|
||||
$("#drMarkInputContent").popover("hide");
|
||||
}
|
||||
|
||||
//处理标签
|
||||
var content = "";
|
||||
if(isMarkSearchResShown() && $(".drMarkInputPopoverSearchList.isActive").length > 0){
|
||||
|
||||
content = $(".drMarkInputPopoverSearchList.isActive span strong").text();
|
||||
$("#drMarkInputContentContainer").popover("hide");
|
||||
}else{
|
||||
content = $(this).text();
|
||||
}
|
||||
var checkContent = $.trim(content);
|
||||
if(checkContent != ""){
|
||||
addOneMark(content);
|
||||
}
|
||||
|
||||
return;
|
||||
}else if(keyCode==40){
|
||||
//下
|
||||
if(isMarkSearchResShown()){
|
||||
if($(".drMarkInputPopoverSearchList.isActive").length > 0){
|
||||
if($(".drMarkInputPopoverSearchList.isActive")[0].nextSibling == null){
|
||||
//指向第一个
|
||||
$(".drMarkInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
$(".drMarkInputPopoverSearchList").first().addClass("isActive");
|
||||
}else{
|
||||
//指向下一个
|
||||
var nextNode = $($(".drMarkInputPopoverSearchList.isActive")[0].nextSibling);
|
||||
$(".drMarkInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
nextNode.addClass("isActive");
|
||||
|
||||
}
|
||||
}else{
|
||||
//指向第一个
|
||||
$(".drMarkInputPopoverSearchList").first().addClass("isActive");
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
}else if(keyCode==38){
|
||||
//上
|
||||
if(isMarkSearchResShown()){
|
||||
if($(".drMarkInputPopoverSearchList.isActive").length > 0){
|
||||
if($(".drMarkInputPopoverSearchList.isActive")[0].previousSibling == null){
|
||||
//指向最后一个
|
||||
$(".drMarkInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
$(".drMarkInputPopoverSearchList").last().addClass("isActive");
|
||||
}else{
|
||||
//指向上一个
|
||||
var previousNode = $($(".drMarkInputPopoverSearchList.isActive")[0].previousSibling);
|
||||
$(".drMarkInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
previousNode.addClass("isActive");
|
||||
|
||||
}
|
||||
}else{
|
||||
//指向最后一个
|
||||
$(".drMarkInputPopoverSearchList").last().addClass("isActive");
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
var $this = $(this);
|
||||
setTimeout(function(){
|
||||
searchMarkKeyword($this.text());
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
$("#drMarkInputContent").popover({
|
||||
trigger:"manual",
|
||||
html : true,
|
||||
animation:false,
|
||||
placement:"top",
|
||||
content: function(){
|
||||
return $('#drMarkInputErrorPopoverContainer').html();
|
||||
}
|
||||
});
|
||||
|
||||
$("#drMarkInputContent").on('hide.bs.popover', function(e){
|
||||
if(e.target != $("#drMarkInputContent")[0]){
|
||||
return;
|
||||
}
|
||||
$('#drMarkInputErrorPopoverContainer').append($('#drMarkInputErrorPopover'));
|
||||
|
||||
|
||||
});
|
||||
$("#drMarkInputContent").on('shown.bs.popover', function(e){
|
||||
if(e.target != $("#drMarkInputContent")[0]){
|
||||
return;
|
||||
}
|
||||
$('#drMarkInputErrorPopoverContainer #drMarkInputErrorPopover').remove();
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#drMarkInputContentContainer").popover({
|
||||
trigger:"manual",
|
||||
html : true,
|
||||
animation:false,
|
||||
placement:"bottom",
|
||||
content: function(){
|
||||
return $('#drMarkInputPopoverSearchContainer').html();
|
||||
}
|
||||
});
|
||||
|
||||
$("#drMarkInputContentContainer").on('hide.bs.popover',function(e){
|
||||
if(e.target != $("#drMarkInputContentContainer")[0]){
|
||||
return;
|
||||
}
|
||||
$('#drMarkInputPopoverSearchContainer').append($('#drMarkInputPopoverSearch'));
|
||||
|
||||
|
||||
});
|
||||
$("#drMarkInputContentContainer").on('shown.bs.popover',function(e){
|
||||
if(e.target != $("#drMarkInputContentContainer")[0]){
|
||||
return;
|
||||
}
|
||||
var topVal = parseInt($('#drMarkInputContentContainer+.popover').css('top').substr(0,$('#drMarkInputContentContainer+.popover').css('top').length - 2));
|
||||
$('#drMarkInputContentContainer+.popover').css('top',(topVal - 15 ) + 'px');
|
||||
//重新计算left
|
||||
var left = 0;
|
||||
var adjustLeftComponent = $thisMarkInput.data("adjustLeftComponent");
|
||||
if(adjustLeftComponent == null){
|
||||
left = $("#drMarkInputContentContainer").offset().left;
|
||||
}else{
|
||||
var left1 = $("#drMarkInputContentContainer").offset().left;
|
||||
var left2 = adjustLeftComponent.offset().left;
|
||||
left = left1 - left2;
|
||||
}
|
||||
|
||||
//var left = $("#markInputContentContainer+.popover").css('left');
|
||||
|
||||
|
||||
var inText = $("#drMarkInputContent").text();
|
||||
|
||||
$('#drMarkInputContentContainer+.popover').css('left', (left - 20) + 'px');
|
||||
$('#drMarkInputContentContainer+.popover .arrow').css('left', (20 + 14 * inText.length / 2 ) + 'px');
|
||||
|
||||
|
||||
$('#drMarkInputPopoverSearchContainer #drMarkInputPopoverSearch').remove();
|
||||
|
||||
$("#drMarkInputPopoverSearch").off("mouseenter");
|
||||
$("#drMarkInputPopoverSearch").off("mouseleave");
|
||||
$("#drMarkInputPopoverSearch").off("click");
|
||||
$("#drMarkInputPopoverSearch").on("mouseenter",".drMarkInputPopoverSearchList",function(){
|
||||
if(!$(this).hasClass("isActive")){
|
||||
$(".drMarkInputPopoverSearchList.isActive").each(function(){
|
||||
$(this).removeClass("isActive");
|
||||
});
|
||||
$(this).addClass("isActive");
|
||||
}
|
||||
});
|
||||
$("#drMarkInputPopoverSearch").on("mouseleave",".drMarkInputPopoverSearchList",function(){
|
||||
$(this).removeClass("isActive");
|
||||
});
|
||||
$("#drMarkInputPopoverSearch").on("click",".drMarkInputPopoverSearchList.isActive",function(){
|
||||
//选中输入
|
||||
var content = $(this).find("span strong").text();
|
||||
addOneMark(content);
|
||||
$("#drMarkInputContent").focus();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$thisMarkInput.on("click",".drMarkSpanContainer",function(e){
|
||||
|
||||
deleteOneMark($(this));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
getMarkArray:function(){
|
||||
return this.data("markData");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.markinput = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.markinput' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.markinput.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
107
frontend/static/js/common/navbar.js
Normal file
107
frontend/static/js/common/navbar.js
Normal file
@@ -0,0 +1,107 @@
|
||||
(function( $ ){
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.drnavbar.options, options );
|
||||
|
||||
$this.data('previousScroll', 0);
|
||||
|
||||
$('#drNavbarUser').click(function(e){
|
||||
var isVisible = $(".drNavbarPopover").is(":visible");
|
||||
if(isVisible){
|
||||
$this.drnavbar("hideDropDownMenu");
|
||||
}else{
|
||||
$('#drNavbarUser').trigger("drNavbarPopoverFocus");
|
||||
}
|
||||
});
|
||||
|
||||
//focusout在safari下无法获取related target,不得已加入mousedown check focus out
|
||||
function installMouseDown(){
|
||||
$(document).one("mousedown",function(e){
|
||||
var target = e.target;
|
||||
if(target != null){
|
||||
if(target==$('#drNavbarUser')[0]){
|
||||
return;
|
||||
}
|
||||
var targetParents = $(target).parents();
|
||||
for(var i = 0; i < targetParents.length;i++){
|
||||
var parent = targetParents[i];
|
||||
if(parent == $(".drNavbarDropDownMenu")[0]){
|
||||
installMouseDown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$('#drNavbarUser').trigger("click");
|
||||
});
|
||||
}
|
||||
$('#drNavbarUser').on("drNavbarPopoverFocus",function(){
|
||||
$this.drnavbar("showDropDownMenu");
|
||||
setTimeout(installMouseDown,200);
|
||||
});
|
||||
//设置
|
||||
$("#drNavbarDropdownSetting").hover(function(){
|
||||
$("#drNavbarDropdownSetting span").css("color","black");
|
||||
},function(){
|
||||
$("#drNavbarDropdownSetting span").css("color","");
|
||||
});
|
||||
//退出
|
||||
$("#drNavbarDropdownLogout").hover(function(){
|
||||
$("#drNavbarDropdownLogout span").css("color","black");
|
||||
},function(){
|
||||
$("#drNavbarDropdownLogout span").css("color","");
|
||||
});
|
||||
|
||||
|
||||
showDropDownMenu:function(){
|
||||
$(".drNavbarPopover").show();
|
||||
var deviceType = $.getDeviceWidthType();
|
||||
var deviceWidth = $.getDeviceWidth();
|
||||
var deviceHeight = $.getDeviceHeight();
|
||||
if(deviceType == 1){
|
||||
var top = 71;
|
||||
var width = deviceWidth;
|
||||
var height = deviceHeight - top;
|
||||
|
||||
var arrowTop = -14;
|
||||
var arrowLeft = width - 38;
|
||||
$(".drNavbarPopover").css("top",top+"px");
|
||||
$(".drNavbarPopover").css("width",width+"px");
|
||||
$(".drNavbarPopover").css("height",height+"px");
|
||||
$(".drNavbarPopover").css("left","0px");
|
||||
$(".drNavbarPopoverArrow").css("left",arrowLeft+"px");
|
||||
|
||||
}
|
||||
},
|
||||
hideDropDownMenu:function(){
|
||||
$(".drNavbarPopover").hide();
|
||||
$(".drNavbarPopover").css("top","");
|
||||
$(".drNavbarPopover").css("width","");
|
||||
$(".drNavbarPopover").css("height","");
|
||||
$(".drNavbarPopover").css("left","");
|
||||
$(".drNavbarPopoverArrow").css("left","");
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.drnavbar = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.drnavbar' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.drnavbar.options = {notificationUnReadTotalCount:0, personallettersUnReadTotalCount:0};
|
||||
|
||||
})( jQuery );
|
72
frontend/static/js/common/pagination.js
Normal file
72
frontend/static/js/common/pagination.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* pagination.js
|
||||
* target container must be id "page-container"
|
||||
*/
|
||||
function setPage(currPage,totalCount,urlHeader) //currPage 当前页数; totalCount 总数量
|
||||
{
|
||||
var container = document.getElementById('page-container');
|
||||
var iPageSize = 20; //每页的数量
|
||||
var b = ((totalCount%iPageSize)!=0);
|
||||
var iPageCount = parseInt(totalCount/iPageSize)+(b?1:0);//总共页数
|
||||
//if (currPage > iPageCount) return false;
|
||||
currPage = parseInt(currPage);
|
||||
var sTemp = "";
|
||||
var sTemp1 = "<div class=\"page-number-container inline-block\"><span class=\"page-number\">"+ currPage +"</span>/<span class=\"page-number\">"+ iPageCount +"</span></div>";
|
||||
var sTemp2 = "<div class=\"page-btn-container inline-block\"><input type=\"text\" id=\"goPageNo\" value=\""+currPage+"\" class=\"search-area-for-page border text-align-center\" /><a class=\"btn inline-block border-btn page-btn\" type=\"button\" href=\"Javascript:toPage('"+urlHeader+"');\");\">跳转</a></div>"
|
||||
if (totalCount==0)
|
||||
{
|
||||
sTemp = "无";
|
||||
container.innerHTML = sTemp;
|
||||
}
|
||||
else if (iPageCount==1)
|
||||
{
|
||||
sTemp = "<a href='#' class='disabled'>上一页</a>"+ sTemp1 +"<a href='#' class='disabled'>下一页</a>";
|
||||
container.innerHTML = sTemp +" "+ sTemp2 ;
|
||||
}
|
||||
else if (iPageCount==currPage)
|
||||
{
|
||||
sTemp = "<a href='#'>上一页</a>"+ sTemp1 +"<a href='#' class='disabled'>下一页</a>";
|
||||
container.innerHTML = sTemp +" "+ sTemp2 ;
|
||||
}
|
||||
else if (currPage==1)
|
||||
{
|
||||
sTemp = "<a href='#' class='disabled'>上一页</a>"+ sTemp1 +"<a href='#'>下一页</a>";
|
||||
container.innerHTML = sTemp +" "+ sTemp2 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sTemp = " <a href='#'>上一页</a>"+ sTemp1 +"<a href='#'>下一页</a>";
|
||||
container.innerHTML = sTemp +" "+ sTemp2 ;
|
||||
}
|
||||
|
||||
//事件点击
|
||||
var pageClick = function() {
|
||||
var oAlink = container.getElementsByTagName("a");
|
||||
var inx = currPage; //初始的页码
|
||||
if(oAlink.length > 1){
|
||||
oAlink[0].onclick = function() { //点击上一页
|
||||
if (inx == 1) {
|
||||
return false;
|
||||
}
|
||||
inx--;
|
||||
window.location.href=urlHeader+inx;
|
||||
return false;
|
||||
}
|
||||
oAlink[1].onclick = function() { //点击下一页
|
||||
if (inx == iPageCount) {
|
||||
return false;
|
||||
}
|
||||
inx++;
|
||||
//setPage(container, count, inx);
|
||||
window.location.href=urlHeader+inx;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} ()
|
||||
}
|
||||
|
||||
function toPage(s) {
|
||||
var tempUrl = "";
|
||||
tempUrl = s + document.getElementById('goPageNo').value;
|
||||
window.location.href = tempUrl;
|
||||
}
|
85
frontend/static/js/common/personalletters.js
Normal file
85
frontend/static/js/common/personalletters.js
Normal file
@@ -0,0 +1,85 @@
|
||||
(function($) {
|
||||
$(document).ready(function(){
|
||||
var currentPathName = window.location.pathname;
|
||||
// 格式化粘贴文本控件初始化
|
||||
$("#createPersonallettersContent").drcontenteditable("init");
|
||||
// 取消
|
||||
$("#createPersonallettersCancel").on("click", function(){
|
||||
$("#createPersonallettersModel").modal("hide");
|
||||
});
|
||||
// 统计字数
|
||||
$("#createPersonallettersContent").on("keydown cut copy paste", function(){
|
||||
setTimeout(function(){
|
||||
var inputText = $("#createPersonallettersContent").drcontenteditable("getContent");
|
||||
$("#createPersonallettersModel").modal("adjustBackdrop");
|
||||
if(inputText.length > 3000){
|
||||
$("#personallettersContentLimit").show();
|
||||
$("#personallettersContentLimit").css("color","red");
|
||||
$("#personallettersContentLimit").text(inputText.length + " / 3000");
|
||||
}else if(inputText.length > 2500){
|
||||
$("#personallettersContentLimit").show();
|
||||
$("#personallettersContentLimit").css("color","#838383");
|
||||
$("#personallettersContentLimit").text(inputText.length + " / 3000");
|
||||
}else{
|
||||
$("#personallettersContentLimit").hide();
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
// 提交
|
||||
$("#createPersonallettersSubmit").on("click", function(){
|
||||
var toUserId = $(".drUserSpanContainer[data-userid]").attr("data-userid");
|
||||
var content = $("#createPersonallettersContent").drcontenteditable("getContent");
|
||||
|
||||
if(!toUserId){
|
||||
$("#drTipbar").drtipbar("showMsg","请选择收件人");
|
||||
return;
|
||||
}
|
||||
if(content.length == 0){
|
||||
$("#drTipbar").drtipbar("showMsg","私信内容不能为空");
|
||||
return;
|
||||
}
|
||||
if(content.length > 3000){
|
||||
$("#drTipbar").drtipbar("showMsg","私信内容最多3000个字");
|
||||
return;
|
||||
}
|
||||
|
||||
content = encodeURIComponent(content);
|
||||
|
||||
$("#createPersonallettersSubmit").attr("disabled",true);
|
||||
jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/personalletters/create",
|
||||
data : "content="+content+"&toUserId="+toUserId,
|
||||
beforeSend : function(request) {
|
||||
$('#loadingBar').drloadingbar("startLoad");
|
||||
},
|
||||
success : function(data){
|
||||
$("#createPersonallettersContent").empty();
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
$("#drTipbar").drtipbar("showMsg","发送成功");
|
||||
$("#createPersonallettersModel").modal("hide");
|
||||
$('#createPersonallettersModel').on('hidden.bs.modal', function (e) {
|
||||
$("#createPersonallettersSubmit").removeAttr("disabled");
|
||||
});
|
||||
if(currentPathName == "/personalletters/enterlistconversations" || currentPathName == "/personalletters/enterlistletters"){
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
error : function(data){
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
$("#createPersonallettersSubmit").removeAttr("disabled");
|
||||
if(data.responseJSON == null){
|
||||
$("#drTipbar").drtipbar("showMsg","网络不给力");
|
||||
}else{
|
||||
if(data.responseJSON.errCode != null){
|
||||
$("#drTipbar").drtipbar("showMsg",data.responseJSON.errMessage);
|
||||
}else{
|
||||
$("#drTipbar").drtipbar("showMsg","网络不给力");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
261
frontend/static/js/common/preview-image.js
Normal file
261
frontend/static/js/common/preview-image.js
Normal file
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* preview image
|
||||
*/
|
||||
var PreviewImage=function(){
|
||||
var Preview=function(params,keyword){
|
||||
//关闭图片预览Modal
|
||||
$(document).on('click','.image-preview-close',function(){
|
||||
$('.image-preview-background').fadeOut(500).removeClass('image-preview-background-hover');
|
||||
$('.shot-container .curPreview').removeClass('curPreview');
|
||||
})
|
||||
|
||||
//显示Modal浏览图片
|
||||
$(document).on('click','.shot-image .cover,.shot-image img',function(){
|
||||
var $curShot=$(this).parents('.shot');
|
||||
generatePreviewImgModal($curShot);
|
||||
})
|
||||
|
||||
//鼠标点击下一张
|
||||
$(document).on('click','.image-preview-next',function(){
|
||||
goToPage(false,params,keyword);
|
||||
})
|
||||
|
||||
//鼠标点击上一张
|
||||
$(document).on('click','.image-preview-prev',function(){
|
||||
goToPage(true,params,keyword);
|
||||
})
|
||||
|
||||
//方向键控制左右翻页
|
||||
$(document).keydown(function(event){
|
||||
//Modal处于显示状态才能触发翻页操作
|
||||
if($('.image-preview-background').css('display')=='block'){
|
||||
// -->
|
||||
if (event.keyCode == 39){
|
||||
goToPage(false,params,keyword);
|
||||
}
|
||||
// <--
|
||||
else if(event.keyCode == 37){
|
||||
goToPage(true,params,keyword);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
init:function(params,keyword){
|
||||
Preview(params,keyword);
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
|
||||
/**
|
||||
* 图片预览左右翻页
|
||||
* 上一张:flag=true , 下一张:flag=false
|
||||
*/
|
||||
function goToPage(flag,params,keyword){
|
||||
// 上一张
|
||||
if(flag){
|
||||
//存在上一张
|
||||
if($('.shot-container .curPreview').prev().length>=1){
|
||||
slider(true);
|
||||
}
|
||||
//已经是第一张
|
||||
else{
|
||||
console.log('已经是第一张');
|
||||
$('.loadTips').text('已经是第一张 !').stop().fadeIn(500).fadeOut(1500);
|
||||
}
|
||||
}
|
||||
// 下一张
|
||||
else{
|
||||
//存在下一张
|
||||
if($('.shot-container .curPreview').next().length>=1){
|
||||
slider(false);
|
||||
}
|
||||
//已经是最后一张
|
||||
else{
|
||||
//触发操作,加载更多数据
|
||||
params.page++;
|
||||
Disabled($('.loadMore'),'');
|
||||
Loading($('.loadMore'));
|
||||
$.when(keyword==''?getScreenShotList(params.url,params.page):getSearchScreenShotList(params.url,params.page,keyword))
|
||||
.done(function(data){
|
||||
if($('.shot-container .curPreview').next().length>=1){
|
||||
slider(false);
|
||||
}
|
||||
else{
|
||||
console.log('已经是最后一张');
|
||||
$('.loadTips').text('已经是最后一张 !').stop().fadeIn(500).fadeOut(1500);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* slider效果
|
||||
* 上一张:flag=true , 下一张:flag=false
|
||||
*/
|
||||
function slider(flag){
|
||||
if(flag){
|
||||
$('.image-preview-container').addClass('image-preview-container-prev');
|
||||
var $curShot=$('.shot-container .curPreview').removeClass('curPreview').prev();
|
||||
}
|
||||
else{
|
||||
$('.image-preview-container').addClass('image-preview-container-next');
|
||||
var $curShot=$('.shot-container .curPreview').removeClass('curPreview').next();
|
||||
}
|
||||
generatePreviewImgModal($curShot);
|
||||
setTimeout(function(){
|
||||
if(flag){
|
||||
$('.image-preview-container').removeClass('image-preview-container-prev');
|
||||
}
|
||||
else{
|
||||
$('.image-preview-container').removeClass('image-preview-container-next');
|
||||
}
|
||||
},500);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成图片预览Modal
|
||||
*/
|
||||
function generatePreviewImgModal($curShot){
|
||||
$curShot.addClass('curPreview');
|
||||
//滚动条随预览图片滚动
|
||||
var scrollTop=$('.curPreview').offset().top;
|
||||
$("html,body").animate({scrollTop:scrollTop+"px"},500);
|
||||
|
||||
var application=$curShot.data('application');
|
||||
if($('.image-preview-background').length<1){
|
||||
$('body').append(
|
||||
'<div class="image-preview-background is-hidden">'+
|
||||
'<i class="iconfont image-preview-ctrl image-preview-close"></i>'+
|
||||
'<i class="iconfont image-preview-ctrl image-preview-prev"></i>'+
|
||||
'<i class="iconfont image-preview-ctrl image-preview-next"></i>'+
|
||||
|
||||
'<div class="image-preview-wrapper">'+
|
||||
'<div class="image-preview-container white">'+
|
||||
'<div class="column three-fifths text-align-center">'+
|
||||
'<img class="main-image" src="">'+
|
||||
'<h6 class="fastKey">键盘快捷键: ← 前一张图片 → 后一张图片</h6>'+
|
||||
'</div>'+
|
||||
'<div class="column two-fifths text-align-left">'+
|
||||
'<i class="iconfont like-icon inline-block"></i> 喜欢 <span class="likeCount"></span>'+
|
||||
|
||||
'<div class="edit-screenshots-items">'+
|
||||
|
||||
'</div>'+
|
||||
|
||||
'<hr class="horizontal-line text-align-left">'+
|
||||
|
||||
'<ul class="screenshot-info">'+
|
||||
'<li>'+
|
||||
'<img class="app-logo" src=""/>'+
|
||||
'<a class="app-name" target="_blank"></a>'+
|
||||
'</li>'+
|
||||
'<li>'+
|
||||
'<h6>版本号</h6>'+
|
||||
'<h6 class="app-version"></h6>'+
|
||||
'</li>'+
|
||||
'<li>'+
|
||||
'<h6>更新时间</h6>'+
|
||||
'<h6 class="updateTime"></h6>'+
|
||||
'</li>'+
|
||||
'<li>'+
|
||||
'<h6>所属标签</h6>'+
|
||||
'<div class="Marks">'+
|
||||
'</div>'+
|
||||
'</li>'+
|
||||
'</ul>'+
|
||||
|
||||
'<div class="downloadPic-area">'+
|
||||
'</div>'+
|
||||
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
$image_preview_background=$('.image-preview-background');
|
||||
FillModalData(application,$image_preview_background);
|
||||
$('.image-preview-background').fadeIn(500).addClass('image-preview-background-hover');
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充Modal数据
|
||||
*/
|
||||
function FillModalData(application,$image_preview_background){
|
||||
$image_preview_background.find('.column.three-fifths img').attr('src',application.pic);
|
||||
$image_preview_background.find('.column.two-fifths .likeCount').text(application.likeCount);
|
||||
$image_preview_background.find('.app-logo').attr('src',application.applicationIcon);
|
||||
$image_preview_background.find('.app-name').text(application.applicationName).attr('href','/applications/get/'+application.id);
|
||||
$image_preview_background.find('.app-version').text(application.appVersion);
|
||||
$image_preview_background.find('.updateTime').text(timeStampToDateString(application.updatedTime));
|
||||
//遍历Marks
|
||||
$image_preview_background.find('.screenshot-info .Marks').empty();
|
||||
$.each(application.marks,function(key,value){
|
||||
$image_preview_background.find('.screenshot-info .Marks').append(
|
||||
'<a class="edit-btn" href="/screenshots/searchscreenshot?search='+value.name+'" target="_blank">'+value.name+'</a>'
|
||||
);
|
||||
});
|
||||
|
||||
var sizeArray=['640X960','640X1136','750X1334','1080X1920'];
|
||||
// 按Type从小到大排序
|
||||
var newArray=application.screenShotContents;
|
||||
if(newArray.length<1){
|
||||
$image_preview_background.find('.downloadPic-area').empty().append('抱歉,暂时没有更新下载截图。')
|
||||
}
|
||||
else{
|
||||
$image_preview_background.find('.downloadPic-area').empty().append('下载:');
|
||||
newArray.sort(getSortFun('asc', 'type'));
|
||||
//遍历screenShotContents
|
||||
$.each(newArray,function(key,value){
|
||||
$image_preview_background.find('.downloadPic-area').append(
|
||||
'<a class="downloadPic-btn" href="'+value.url+'">'+sizeArray[value.type-1]+'</a>'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
//EditScreenShot
|
||||
var EditScreenShot_Array=[{
|
||||
'module':'default',
|
||||
'controller':'screenshots',
|
||||
'action':'enterscreenshotcontent',
|
||||
'method':'GET',
|
||||
'menuItem':'编辑截图包'
|
||||
},
|
||||
{
|
||||
'module':'default',
|
||||
'controller':'screenshots',
|
||||
'action':'enterupdate',
|
||||
'method':'GET',
|
||||
'menuItem':'编辑基本信息'
|
||||
},
|
||||
{
|
||||
'module':'default',
|
||||
'controller':'screenshots',
|
||||
'action':'delete',
|
||||
'method':'POST',
|
||||
'menuItem':'删除界面'
|
||||
}];
|
||||
|
||||
$('.edit-screenshots-items').empty();
|
||||
for(var i=0;i<EditScreenShot_Array.length;i++){
|
||||
$('.edit-screenshots-items').append('<a class="is-hidden edit-btn edit-btn-'+i+'" href="" target="_blank">'+EditScreenShot_Array[i].menuItem+'</a>');
|
||||
}
|
||||
var $editScreenShot=$('.edit-screenshots-items');
|
||||
$editScreenShot.find(".edit-btn-0").attr('href','/screenshots/enterscreenshotcontent?screenShotId='+application.screenShotId);
|
||||
$editScreenShot.find(".edit-btn-1").attr('href','/screenshots/enterupdate/'+application.screenShotId);
|
||||
$editScreenShot.find(".edit-btn-2").attr('href','/screenshots/delete/'+application.screenShotId);
|
||||
|
||||
/* 根据权限显示ScreenShot操作按钮 */
|
||||
var returnValue=hasAuth(EditScreenShot_Array,authList_array);
|
||||
for(var i=0;i<returnValue.length;i++){
|
||||
$editScreenShot.find('.edit-btn-'+returnValue[i].index).removeClass('is-hidden');
|
||||
}
|
||||
$editScreenShot.find('.is-hidden').remove();
|
||||
|
||||
}
|
||||
|
17
frontend/static/js/common/projectstatus.js
Normal file
17
frontend/static/js/common/projectstatus.js
Normal file
@@ -0,0 +1,17 @@
|
||||
function getProjectRole(){
|
||||
var role = ["产品经理","设计师","硬件工程师","软件工程师","运营","公关",
|
||||
"市场销售","人力资源","财务","法务","其他"];
|
||||
return role;
|
||||
}
|
||||
|
||||
function getProjectPhase(){
|
||||
var phase = ["想法阶段","Demo 阶段","产品已上线","有运营数据","已停止运营"];
|
||||
return phase;
|
||||
}
|
||||
|
||||
function getFinancePhase(){
|
||||
var phase = ["种子","天使","Pre-A","A 轮","B 轮","C 轮","D 轮","E 轮","F 轮","Pre-IPO"];
|
||||
return phase;
|
||||
}
|
||||
|
||||
|
24
frontend/static/js/common/provinceandcity.js
Normal file
24
frontend/static/js/common/provinceandcity.js
Normal file
@@ -0,0 +1,24 @@
|
||||
function getProvince(){
|
||||
var province = ["上海"];
|
||||
return province;
|
||||
}
|
||||
|
||||
function getCityByProvince(province){
|
||||
var arr = getProvinceAndCity();
|
||||
return arr[province];
|
||||
}
|
||||
|
||||
function getProvinceAndCity(){
|
||||
var arr = {"上海": ["上海"]};
|
||||
return arr;
|
||||
}
|
||||
|
||||
function getDistrictByCity(city){
|
||||
var arr = getCityAndDistrict();
|
||||
return arr[city];
|
||||
}
|
||||
|
||||
function getCityAndDistrict(){
|
||||
var arr = {"上海": ["黄浦区","徐汇区","长宁区","静安区","普陀区","虹口区","闸北区","杨浦区","闵行区","宝山区","青浦区","松江区","嘉定区","奉贤区","金山区","浦东新区","崇明县"]};
|
||||
return arr;
|
||||
}
|
36
frontend/static/js/common/require.js
Normal file
36
frontend/static/js/common/require.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
RequireJS 2.1.17 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
|
||||
Available via the MIT or new BSD license.
|
||||
see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
var requirejs,require,define;
|
||||
(function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function T(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function t(b,c){return fa.call(b,c)}function m(b,c){return t(b,c)&&b[c]}function B(b,c){for(var d in b)if(t(b,d)&&c(b[d],d))break}function U(b,c,d,e){c&&B(c,function(c,g){if(d||!t(b,g))e&&"object"===typeof c&&c&&!H(c)&&!G(c)&&!(c instanceof
|
||||
RegExp)?(b[g]||(b[g]={}),U(b[g],c,d,e)):b[g]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ca(b){throw b;}function da(b){if(!b)return b;var c=ba;v(b.split("."),function(b){c=c[b]});return c}function C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=e;d&&(c.originalError=d);return c}function ga(b){function c(a,k,b){var f,l,c,d,e,g,i,p,k=k&&k.split("/"),h=j.map,n=h&&h["*"];if(a){a=a.split("/");l=a.length-1;j.nodeIdCompat&&
|
||||
Q.test(a[l])&&(a[l]=a[l].replace(Q,""));"."===a[0].charAt(0)&&k&&(l=k.slice(0,k.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)if(d=l[c],"."===d)l.splice(c,1),c-=1;else if(".."===d&&!(0===c||1===c&&".."===l[2]||".."===l[c-1])&&0<c)l.splice(c-1,2),c-=2;a=a.join("/")}if(b&&h&&(k||n)){l=a.split("/");c=l.length;a:for(;0<c;c-=1){e=l.slice(0,c).join("/");if(k)for(d=k.length;0<d;d-=1)if(b=m(h,k.slice(0,d).join("/")))if(b=m(b,e)){f=b;g=c;break a}!i&&(n&&m(n,e))&&(i=m(n,e),p=c)}!f&&i&&(f=i,g=p);f&&(l.splice(0,
|
||||
g,f),a=l.join("/"))}return(f=m(j.pkgs,a))?f:a}function d(a){z&&v(document.getElementsByTagName("script"),function(k){if(k.getAttribute("data-requiremodule")===a&&k.getAttribute("data-requirecontext")===i.contextName)return k.parentNode.removeChild(k),!0})}function e(a){var k=m(j.paths,a);if(k&&H(k)&&1<k.length)return k.shift(),i.require.undef(a),i.makeRequire(null,{skipMap:!0})([a]),!0}function n(a){var k,c=a?a.indexOf("!"):-1;-1<c&&(k=a.substring(0,c),a=a.substring(c+1,a.length));return[k,a]}function p(a,
|
||||
k,b,f){var l,d,e=null,g=k?k.name:null,j=a,p=!0,h="";a||(p=!1,a="_@r"+(K+=1));a=n(a);e=a[0];a=a[1];e&&(e=c(e,g,f),d=m(r,e));a&&(e?h=d&&d.normalize?d.normalize(a,function(a){return c(a,g,f)}):-1===a.indexOf("!")?c(a,g,f):a:(h=c(a,g,f),a=n(h),e=a[0],h=a[1],b=!0,l=i.nameToUrl(h)));b=e&&!d&&!b?"_unnormalized"+(O+=1):"";return{prefix:e,name:h,parentMap:k,unnormalized:!!b,url:l,originalName:j,isDefine:p,id:(e?e+"!"+h:h)+b}}function s(a){var k=a.id,b=m(h,k);b||(b=h[k]=new i.Module(a));return b}function q(a,
|
||||
k,b){var f=a.id,c=m(h,f);if(t(r,f)&&(!c||c.defineEmitComplete))"defined"===k&&b(r[f]);else if(c=s(a),c.error&&"error"===k)b(c.error);else c.on(k,b)}function w(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(v(c,function(b){if(b=m(h,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)g.onError(a)}function x(){R.length&&(ha.apply(A,[A.length,0].concat(R)),R=[])}function y(a){delete h[a];delete V[a]}function F(a,b,c){var f=a.map.id;a.error?a.emit("error",a.error):(b[f]=!0,v(a.depMaps,function(f,
|
||||
d){var e=f.id,g=m(h,e);g&&(!a.depMatched[d]&&!c[e])&&(m(b,e)?(a.defineDep(d,r[e]),a.check()):F(g,b,c))}),c[f]=!0)}function D(){var a,b,c=(a=1E3*j.waitSeconds)&&i.startTime+a<(new Date).getTime(),f=[],l=[],g=!1,h=!0;if(!W){W=!0;B(V,function(a){var i=a.map,j=i.id;if(a.enabled&&(i.isDefine||l.push(a),!a.error))if(!a.inited&&c)e(j)?g=b=!0:(f.push(j),d(j));else if(!a.inited&&(a.fetched&&i.isDefine)&&(g=!0,!i.prefix))return h=!1});if(c&&f.length)return a=C("timeout","Load timeout for modules: "+f,null,
|
||||
f),a.contextName=i.contextName,w(a);h&&v(l,function(a){F(a,{},{})});if((!c||b)&&g)if((z||ea)&&!X)X=setTimeout(function(){X=0;D()},50);W=!1}}function E(a){t(r,a[0])||s(p(a[0],null,!0)).init(a[1],a[2])}function I(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function J(){var a;
|
||||
for(x();A.length;){a=A.shift();if(null===a[0])return w(C("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));E(a)}}var W,Z,i,L,X,j={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},h={},V={},$={},A=[],r={},S={},aa={},K=1,O=1;L={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?
|
||||
a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return m(j.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};Z=function(a){this.events=m($,a.id)||{};this.map=a;this.shim=m(j.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=
|
||||
c;this.inited=!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
||||
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&&
|
||||
(f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=
|
||||
this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f);
|
||||
if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval",
|
||||
"fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b,
|
||||
a);this.check()}));this.errback?q(a,"error",u(this,this.errback)):this.events.error&&q(a,"error",u(this,function(a){this.emit("error",a)}))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,
|
||||
registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p,nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);
|
||||
b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b,a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,
|
||||
q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,
|
||||
e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!==e&&(!("."===k||".."===k)||1<e))d=b.substring(e,b.length),b=b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return t(r,p(b,a,!1,!0).id)},specified:function(b){b=p(b,a,!1,!0).id;return t(r,b)||t(h,b)}});a||(j.undef=function(b){x();var c=p(b,a,!0),e=m(h,b);d(b);delete r[b];delete S[c.url];delete $[b];T(A,function(a,c){a[0]===b&&A.splice(c,1)});e&&(e.events.defined&&($[b]=e.events),y(b))});return j},enable:function(a){m(h,a.id)&&
|
||||
s(a).enable()},completeLoad:function(a){var b,c,d=m(j.shim,a)||{},g=d.exports;for(x();A.length;){c=A.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(h,a);if(!b&&!t(r,a)&&c&&!c.inited){if(j.enforceDefine&&(!g||!da(g)))return e(a)?void 0:w(C("nodefine","No define call for "+a,null,[a]));E([a,d.deps||[],d.exportsFn])}D()},nameToUrl:function(a,b,c){var d,e,h;(d=m(j.pkgs,a))&&(a=d);if(d=m(aa,a))return i.nameToUrl(d,b,c);if(g.jsExtRegExp.test(a))d=a+(b||"");else{d=j.paths;
|
||||
a=a.split("/");for(e=a.length;0<e;e-=1)if(h=a.slice(0,e).join("/"),h=m(d,h)){H(h)&&(h=h[0]);a.splice(0,e,h);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":j.baseUrl)+d}return j.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+j.urlArgs):d},load:function(a,b){g.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ja.test((a.currentTarget||a.srcElement).readyState))N=null,a=I(a),i.completeLoad(a.id)},
|
||||
onScriptError:function(a){var b=I(a);if(!e(b.id))return w(C("scripterror","Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();return i}var g,x,y,D,I,E,N,J,s,O,ka=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,la=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,Q=/\.js$/,ia=/^\.\//;x=Object.prototype;var K=x.toString,fa=x.hasOwnProperty,ha=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),ea=!z&&"undefined"!==typeof importScripts,ja=
|
||||
z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},q={},R=[],M=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(G(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!G(require)&&(q=require,require=void 0);g=requirejs=function(b,c,d,e){var n,p="_";!H(b)&&"string"!==typeof b&&(n=b,H(c)?(b=c,c=d,d=e):b=[]);n&&n.context&&(p=n.context);(e=m(F,p))||(e=F[p]=g.s.newContext(p));
|
||||
n&&e.configure(n);return e.require(b,c,d)};g.config=function(b){return g(b)};g.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.17";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=z;x=g.s={contexts:F,newContext:ga};g({});v(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=F._;return c.require[b].apply(c,arguments)}});if(z&&(y=x.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))y=
|
||||
x.head=D.parentNode;g.onError=ca;g.createNode=function(b){var c=b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};g.load=function(b,c,d){var e=b&&b.config||{};if(z)return e=g.createNode(e,c,d),e.setAttribute("data-requirecontext",b.contextName),e.setAttribute("data-requiremodule",c),e.attachEvent&&!(e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code"))&&
|
||||
!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)):(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),
|
||||
s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl=O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===
|
||||
b.readyState)return N=b}),e=N;e&&(b||(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this);
|
153
frontend/static/js/common/screenshothover.js
Normal file
153
frontend/static/js/common/screenshothover.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* screenshothover.js
|
||||
* each file using screenshots must include this file
|
||||
*/
|
||||
/* hover */
|
||||
$(document).on('mouseenter','.shot .shot-image',function(){
|
||||
$(this).addClass('shot-image-hover');
|
||||
$(this).find('.cover').addClass('cover-hover');
|
||||
$(this).find('.actions').fadeIn(500).addClass('actions-hover');
|
||||
});
|
||||
$(document).on('mouseleave','.shot .shot-image',function(){
|
||||
$(this).removeClass('shot-image-hover');
|
||||
$(this).find('.cover').removeClass('cover-hover');
|
||||
$(this).find('.actions').fadeOut(500).removeClass('actions-hover');
|
||||
});
|
||||
/* like */
|
||||
$(document).on('click','.actions',function(){
|
||||
if(!$.isEmptyObject(currentUserInfo)){
|
||||
$(this).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
});
|
||||
|
||||
function like(e,id){
|
||||
if($.isEmptyObject(currentUserInfo)){
|
||||
alert("请先登录");
|
||||
}else{
|
||||
var id = $(e).attr("id");
|
||||
$.ajax( {
|
||||
url:'/screenshots/likescreenshot',
|
||||
data:{
|
||||
screenshot_id : id
|
||||
},
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
success:function(data) {
|
||||
//alert("操作成功!");
|
||||
e.setAttribute("onclick", "unlike(this,"+id+")");
|
||||
if($(e).find('.unlike').hasClass('is-hidden')){
|
||||
$(e).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
},
|
||||
error : function() {
|
||||
//alert("操作失败!");
|
||||
if($(e).find('.like').hasClass('is-hidden')){
|
||||
$(e).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
e.setAttribute("onclick", "like(this,"+id+")");
|
||||
if($(e).find('.liked').hasClass('is-hidden')){
|
||||
$(e).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function unlike(e,id){
|
||||
if($.isEmptyObject(currentUserInfo)){
|
||||
alert("请先登录");
|
||||
}else{
|
||||
var id = $(e).attr("id");
|
||||
$.ajax( {
|
||||
url:'/screenshots/dislikescreenshot',
|
||||
data:{
|
||||
screenshot_id : id
|
||||
},
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
success:function(data) {
|
||||
//alert("操作成功!");
|
||||
e.setAttribute("onclick", "like(this,"+id+")");
|
||||
if($(e).find('.liked').hasClass('is-hidden')){
|
||||
$(e).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
},
|
||||
error : function() {
|
||||
//alert("操作失败!");
|
||||
if($(e).find('.unlike').hasClass('is-hidden')){
|
||||
$(e).find('.iconfont').toggleClass('is-hidden');
|
||||
}
|
||||
e.setAttribute("onclick", "unlike(this,"+id+")");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function detaillike(e,id){
|
||||
if($.isEmptyObject(currentUserInfo)){
|
||||
alert("请先登录");
|
||||
}else{
|
||||
var s = e.getElementsByTagName('span')[0].innerHTML;
|
||||
e.getElementsByTagName('span')[0].innerHTML = parseInt(s)+1;
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
e.onclick=function(){};
|
||||
var id = $(e).attr("id");
|
||||
$.ajax( {
|
||||
url:'/screenshots/likescreenshot',
|
||||
data:{
|
||||
screenshot_id : id
|
||||
},
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
success:function(data) {
|
||||
//alert("操作成功!");
|
||||
e.setAttribute("onclick", "detailunlike(this,"+id+")");
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
},
|
||||
error : function() {
|
||||
//alert("操作失败!");
|
||||
e.setAttribute("onclick", "detaillike(this,"+id+")");
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
e.getElementsByTagName('span')[0].innerHTML = parseInt(s)-2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function detailunlike(e,id){
|
||||
if($.isEmptyObject(currentUserInfo)){
|
||||
alert("请先登录");
|
||||
}else{
|
||||
var s = e.getElementsByTagName('span')[0].innerHTML;
|
||||
e.getElementsByTagName('span')[0].innerHTML = parseInt(s)-1;
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
e.onclick=function(){};
|
||||
var id = $(e).attr("id");
|
||||
$.ajax( {
|
||||
url:'/screenshots/dislikescreenshot',
|
||||
data:{
|
||||
screenshot_id : id
|
||||
},
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
success:function(data) {
|
||||
//alert("操作成功!");
|
||||
e.setAttribute("onclick", "detaillike(this,"+id+")");
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
},
|
||||
error : function() {
|
||||
//alert("操作失败!");
|
||||
e.setAttribute("onclick", "detailunlike(this,"+id+")");
|
||||
e.getElementsByTagName('i')[0].innerHTML = "";
|
||||
e.getElementsByTagName('span')[0].innerHTML = parseInt(s)+2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function cleanMarksStyle(){/* 清除截图下面每行标签的最后一个, */
|
||||
var list = document.getElementsByName('screenshot-mark-container');
|
||||
for(var k=0;k<list.length;k++){
|
||||
var tempList = list[k].getElementsByTagName('span');
|
||||
if(tempList.length>0){
|
||||
var lastSpan = tempList[tempList.length-1];
|
||||
lastSpan.parentNode.removeChild(lastSpan);
|
||||
}
|
||||
}
|
||||
}
|
431
frontend/static/js/common/searchUser.js
Normal file
431
frontend/static/js/common/searchUser.js
Normal file
@@ -0,0 +1,431 @@
|
||||
(function($) {
|
||||
var methods = {
|
||||
init: function(options) {
|
||||
var $this = this;
|
||||
options = $.extend($.fn.searchUser.options, options);
|
||||
return this.each(function() {
|
||||
var $thisSearchUser = $(this);
|
||||
var userData = [].concat(options.userData); // 用户数组[{userId, userName}](解除引用传递)
|
||||
var adjustLeftComponent = options.adjustLeftComponent; // 对齐控件
|
||||
var limitUser = options.limitUser; // 限制用户数量
|
||||
var isChangeable = options.isChangeable; // 是否可以改变用户
|
||||
var placeholder = options.placeholder; // 搜索控件提示文字
|
||||
var deleteOneUserFunc = options.deleteOneUserFunc; //删除一个用户的回调函数
|
||||
var addOneUserFunc = options.addOneUserFunc; //加入一个用户的回调函数
|
||||
|
||||
$thisSearchUser.data("userData", userData);
|
||||
$thisSearchUser.data("adjustLeftComponent", adjustLeftComponent);
|
||||
$thisSearchUser.data("limitUser", limitUser);
|
||||
$thisSearchUser.data("isChangeable", isChangeable);
|
||||
$thisSearchUser.data("placeholder", placeholder);
|
||||
$thisSearchUser.data("deleteOneUserFunc", deleteOneUserFunc);
|
||||
$thisSearchUser.data("addOneUserFunc", addOneUserFunc);
|
||||
|
||||
|
||||
//初始化外部预设的user
|
||||
$(".drUserSpanContainer").off("click");
|
||||
$(".drUserSpanContainer").remove();
|
||||
|
||||
|
||||
|
||||
for(var i = 0; i < userData.length; i++){
|
||||
$thisSearchUser.searchUser("addOneUserSpanView",userData[i]);
|
||||
}
|
||||
|
||||
//初始化placeholder
|
||||
$thisSearchUser.searchUser("setChangeable",isChangeable);
|
||||
|
||||
|
||||
|
||||
// 搜索用户
|
||||
function searchUserKeyword(keyword) {
|
||||
if ($.trim(keyword) == "") {
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}
|
||||
return;
|
||||
}
|
||||
keyword = encodeURIComponent(keyword);
|
||||
var jRequest = $.ajax({
|
||||
type: "GET",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
url: "/indexhome/indexsearch?type=2&searchtype=3&top=8&keyword=" + keyword,
|
||||
beforeSend: function() {
|
||||
$('#loadingBar').drloadingbar("startLoad");
|
||||
var currentReq = $("#drSearchUserContainer").data("jRequest");
|
||||
if (currentReq != null) { // 前面的请求还未完成
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
var userArray = data.content,
|
||||
userLength = userArray.length;
|
||||
if (userLength > 0) {
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}
|
||||
$("#drSearchUserContainer").popover("show");
|
||||
for (var i = 0; i < userLength; i++) {
|
||||
$element = $("<li class='drUserInputPopoverSearchList'><span><img src='" + userArray[i].avatarThumbUrl + "&w=60&h=60' class='img-circle' /></span><span data-userid='" + userArray[i].id + "' ><strong>" + $.htmlspecialchars(userArray[i].userName) + "</strong></span></li>");
|
||||
if(i == 0){ // 默认选中第一个用户
|
||||
$element.addClass("isActive");
|
||||
}
|
||||
$element.appendTo($("#drUserInputPopoverSearch"));
|
||||
}
|
||||
$("#drUserInputPopoverSearch").off("mouseenter");
|
||||
$("#drUserInputPopoverSearch").off("click");
|
||||
// 鼠标移到上面高亮显示
|
||||
$("#drUserInputPopoverSearch").on("mouseenter", ".drUserInputPopoverSearchList", function() {
|
||||
if(!$(this).hasClass("isActive")){
|
||||
$(".drUserInputPopoverSearchList.isActive").each(function(){
|
||||
$(this).removeClass("isActive");
|
||||
});
|
||||
$(this).addClass("isActive");
|
||||
}
|
||||
});
|
||||
// 鼠标单击选中
|
||||
$("#drUserInputPopoverSearch").on("click", ".drUserInputPopoverSearchList.isActive", function(e) {
|
||||
var content = $(this).find("span strong").text();
|
||||
var userId = $(this).find("span[data-userid]").attr("data-userid");
|
||||
$thisSearchUser.searchUser("addOneUser",userId, content);
|
||||
$("#drSearchUser").focus();
|
||||
});
|
||||
} else {
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(data) {
|
||||
if (data.statusText == "abort") {
|
||||
return;
|
||||
}
|
||||
$('#loadingBar').drloadingbar("stopLoad");
|
||||
}
|
||||
});
|
||||
$("#drSearchUserContainer").data("jRequest", jRequest);
|
||||
}
|
||||
// 粘贴事件
|
||||
$("#drSearchUser").on("paste", function(e) {
|
||||
var userData = $thisSearchUser.data("userData");
|
||||
var limitUser = $thisSearchUser.data("limitUser");
|
||||
if (userData.length >= limitUser) {
|
||||
// 提示只能输入多少个用户
|
||||
$("#drUserInputErrorPopoverContent").text("只能添加 " + limitUser + " 个用户");
|
||||
if (!$thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("show");
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if ($thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("hide");
|
||||
}
|
||||
var pasteText = e.originalEvent.clipboardData.getData("text/plain");
|
||||
pasteText = pasteText.replace(/\r\n/g, "");
|
||||
pasteText = pasteText.replace(/\r/g, "");
|
||||
pasteText = pasteText.replace(/\n/g, "");
|
||||
document.execCommand("insertHTML", false, pasteText);
|
||||
searchUserKeyword($(this).text());
|
||||
});
|
||||
// 光标离开事件
|
||||
$("#drSearchUser").on("blur", function(e) {
|
||||
//return;
|
||||
if ($thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("hide");
|
||||
}
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
setTimeout(function() {
|
||||
// 延迟200毫秒触发,否则若点击在content cell内部则立马被hide掉,无法触发
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
// 键盘按键事件
|
||||
$("#drSearchUser").on("keydown", function(e) {
|
||||
var userData = $thisSearchUser.data("userData");
|
||||
var limitUser = $thisSearchUser.data("limitUser");
|
||||
var isChangeable = $thisSearchUser.data("isChangeable");
|
||||
var keyCode = e.keyCode;
|
||||
if(!isChangeable){
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (keyCode == 8 || keyCode == 46) { // BackSpace, Delete
|
||||
if ($thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("hide");
|
||||
}
|
||||
if ($(this).text() == "" && userData.length > 0) {
|
||||
e.preventDefault();
|
||||
$thisSearchUser.searchUser("deleteOneUser");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (userData.length >= limitUser) {
|
||||
e.preventDefault();
|
||||
$(this).text("");
|
||||
if (!$thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("show");
|
||||
// 提示只能输入多少个用户
|
||||
$("#drUserInputErrorPopoverContent").text("只能添加 " + limitUser + " 个用户");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ($thisSearchUser.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("hide");
|
||||
}
|
||||
if (keyCode == 13 || keyCode == 108) { // Enter键
|
||||
e.preventDefault();
|
||||
// 处理标签
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
var content = $(".drUserInputPopoverSearchList.isActive span strong").text();
|
||||
var userId = $(".drUserInputPopoverSearchList.isActive span[data-userid]").attr("data-userid");
|
||||
$thisSearchUser.searchUser("addOneUser",userId, content);
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}
|
||||
} else if (keyCode == 40) { // 下方向键
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
var $nextNode = $($(".drUserInputPopoverSearchList.isActive")[0].nextSibling);
|
||||
$(".drUserInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
if ($nextNode.length == 0) {
|
||||
// 指向第一个
|
||||
$(".drUserInputPopoverSearchList").first().addClass("isActive");
|
||||
} else {
|
||||
// 指向下一个
|
||||
$nextNode.addClass("isActive");
|
||||
}
|
||||
}
|
||||
} else if (keyCode == 38) { // 上方向键
|
||||
if ($thisSearchUser.searchUser("isUserSearchShown")) {
|
||||
var $previousNode = $($(".drUserInputPopoverSearchList.isActive")[0].previousSibling);
|
||||
$(".drUserInputPopoverSearchList.isActive").removeClass("isActive");
|
||||
if ($previousNode.length == 0) {
|
||||
// 指向最后一个
|
||||
$(".drUserInputPopoverSearchList").last().addClass("isActive");
|
||||
} else {
|
||||
// 指向上一个
|
||||
$previousNode.addClass("isActive");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var $this = $(this);
|
||||
setTimeout(function() {
|
||||
searchUserKeyword($this.text());
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
// 错误弹出框初始化
|
||||
$("#drSearchUser").popover({
|
||||
trigger: "manual",
|
||||
html: true,
|
||||
animation: false,
|
||||
placement: "top",
|
||||
content: '<div id="userInputErrorPopoverContainer"><div id="userInputErrorPopover"><p id="drUserInputErrorPopoverContent"></p></div></div>'
|
||||
});
|
||||
// 搜索弹出框初始化
|
||||
$("#drSearchUserContainer").popover({
|
||||
trigger: "manual",
|
||||
html: true,
|
||||
animation: false,
|
||||
placement: "bottom",
|
||||
content: "<div id='userInputPopoverSearchContainer'><ul id='drUserInputPopoverSearch'></ul></div>"
|
||||
});
|
||||
// 搜索弹出框显示后调整位置
|
||||
$("#drSearchUserContainer").on('shown.bs.popover', function(e) {
|
||||
if (e.target != $("#drSearchUserContainer")[0]) {
|
||||
return;
|
||||
}
|
||||
var topVal = parseInt($('#drSearchUserContainer+.popover').css('top').substr(0, $('#drSearchUserContainer+.popover').css('top').length - 2)),
|
||||
inText = $("#drSearchUser").text();
|
||||
$('#drSearchUserContainer+.popover').css('top', (topVal - 15) + 'px');
|
||||
// 重新计算left
|
||||
var left = 0;
|
||||
if (!adjustLeftComponent) {
|
||||
left = $("#drSearchUserContainer").offset().left;
|
||||
} else {
|
||||
var left1 = $("#drSearchUserContainer").offset().left;
|
||||
var left2 = adjustLeftComponent.offset().left;
|
||||
left = left1 - left2;
|
||||
}
|
||||
$('#drSearchUserContainer+.popover').css('left', (left - 20) + 'px');
|
||||
$('#drSearchUserContainer+.popover .arrow').css('left', (20 + 14 * inText.length / 2) + 'px');
|
||||
});
|
||||
// 单击删除一个用户
|
||||
$thisSearchUser.on("click", ".drUserSpanContainer", function(e) {
|
||||
var isChangeable = $thisSearchUser.data("isChangeable");
|
||||
if(!isChangeable){
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
$thisSearchUser.searchUser("deleteOneUser",$(e.target).data("userid"));
|
||||
});
|
||||
});
|
||||
}, // init End
|
||||
getUserArray: function() {
|
||||
return this.data("userData");
|
||||
},
|
||||
resetData:function(userData,isChangeable,limitUser){
|
||||
this.data("userData", userData);
|
||||
this.data("limitUser", limitUser);
|
||||
this.searchUser("setChangeable", isChangeable);
|
||||
$(".drUserSpanContainer").off("click");
|
||||
$(".drUserSpanContainer").remove();
|
||||
for(var i = 0; i < userData.length; i++){
|
||||
this.searchUser("addOneUserSpanView", userData[i]);
|
||||
}
|
||||
},
|
||||
|
||||
setPlaceholder:function(text){
|
||||
var userData = this.data("userData");
|
||||
if(userData.length > 0){
|
||||
$("#drSearchUser")[0].setAttribute("data-placeholder", "");
|
||||
}else{
|
||||
$("#drSearchUser")[0].setAttribute("data-placeholder", text);
|
||||
}
|
||||
|
||||
},
|
||||
setChangeable:function(isChangeable){
|
||||
this.data("isChangeable",isChangeable);
|
||||
var placeholder = this.data("placeholder");
|
||||
if(isChangeable){
|
||||
$("#drSearchUser").css("visibility", "visible");
|
||||
this.searchUser("setPlaceholder",placeholder);
|
||||
}else{
|
||||
$("#drSearchUser").css("visibility", "hidden");
|
||||
}
|
||||
},
|
||||
// 错误输入框popover是否存在
|
||||
isUserInputErrorShown:function(){
|
||||
if($("#drSearchUser").data('bs.popover') != null){
|
||||
return $("#drSearchUser").data('bs.popover').tip().hasClass('in');
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
// 用户popover是否存在
|
||||
isUserSearchShown:function(){
|
||||
if($("#drSearchUserContainer").data('bs.popover') != null){
|
||||
return $("#drSearchUserContainer").data('bs.popover').tip().hasClass('in');
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
//删除一个用户
|
||||
deleteOneUser:function(userId) {
|
||||
var userData = this.data("userData");
|
||||
var placeholder = this.data("placeholder");
|
||||
var deleteOneUserFunc = this.data("deleteOneUserFunc");
|
||||
var limitUser = this.data("limitUser");
|
||||
if (userData.length <= limitUser) {
|
||||
if (this.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("hide");
|
||||
}
|
||||
}
|
||||
|
||||
if(userData.length == 0){
|
||||
return;
|
||||
}
|
||||
var deleteUserData = {};
|
||||
if(userId == null){
|
||||
//删除最后一个
|
||||
var $deleteElement = $($(".drUserSpanContainer")[userData.length - 1]);
|
||||
$deleteElement.off("click");
|
||||
$deleteElement.remove();
|
||||
deleteUserData = userData[userData.length-1];
|
||||
userData.splice(userData.length-1, 1);
|
||||
this.searchUser("setPlaceholder",placeholder);
|
||||
}else{
|
||||
var $deleteElement = $(".drUserSpanContainer[data-userid="+userId+"]");
|
||||
$deleteElement.off("click");
|
||||
$deleteElement.remove();
|
||||
for(var i = 0; i < userData.length; i++){
|
||||
if(userData[i].userId == userId){
|
||||
deleteUserData = userData[i];
|
||||
userData.splice(i, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.searchUser("setPlaceholder",placeholder);
|
||||
}
|
||||
if(deleteOneUserFunc != null){
|
||||
if(arguments.length <= 1){
|
||||
deleteOneUserFunc(deleteUserData);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
//增加用户对应的view操作
|
||||
addOneUserSpanView:function(userDataElement){
|
||||
$element = $("<span></span>");
|
||||
$element.text(userDataElement.userName);
|
||||
$element.attr("data-userid", userDataElement.userId);
|
||||
$element.addClass("drUserSpanContainer");
|
||||
$element.insertBefore($("#drSearchUserContainer"));
|
||||
},
|
||||
// 增加用户
|
||||
addOneUser:function(userId, userName) {
|
||||
var userData = this.data("userData");
|
||||
var placeholder = this.data("placeholder");
|
||||
var limitUser = this.data("limitUser");
|
||||
var addOneUserFunc = this.data("addOneUserFunc");
|
||||
if (userName == "") {
|
||||
return;
|
||||
}
|
||||
if (userData.length >= limitUser) {
|
||||
// 提示只能输入多少个用户
|
||||
|
||||
if (!this.searchUser("isUserInputErrorShown")) {
|
||||
$("#drSearchUser").popover("show");
|
||||
$("#drUserInputErrorPopoverContent").text("只能添加 " + limitUser + " 个用户");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i = 0; i < userData.length; i++){
|
||||
if(userId == userData[i].userId){
|
||||
//提示重复
|
||||
if(!this.searchUser("isUserInputErrorShown")){
|
||||
$("#drSearchUser").popover("show");
|
||||
$("#drUserInputErrorPopoverContent").text("已经添加了该用户");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
var addUserData = {userId:userId, userName:userName};
|
||||
userData.push(addUserData);
|
||||
this.searchUser("setPlaceholder",placeholder);
|
||||
// 添加一个标签
|
||||
this.searchUser("addOneUserSpanView",addUserData);
|
||||
|
||||
$("#drSearchUser").text("");
|
||||
if(this.searchUser("isUserSearchShown")){
|
||||
$("#drSearchUserContainer").popover("hide");
|
||||
}
|
||||
if(addOneUserFunc != null){
|
||||
if(arguments.length <= 2){
|
||||
addOneUserFunc(addUserData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.searchUser = function(method) {
|
||||
// Method calling logic
|
||||
if (methods[method]) {
|
||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
} else if (typeof method === 'object' || !method) {
|
||||
return methods.init.apply(this, arguments);
|
||||
} else {
|
||||
$.error('Method ' + method + ' does not exist on jQuery.searchUser');
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.searchUser.options = {userData: [], limitUser: 1, isChangeable: false, placeholder: "搜索收件人"};
|
||||
|
||||
})(jQuery);
|
380
frontend/static/js/common/spacecalendar.js
Normal file
380
frontend/static/js/common/spacecalendar.js
Normal file
@@ -0,0 +1,380 @@
|
||||
|
||||
;(function() {
|
||||
$.fn.spacecalendar = function(options) {
|
||||
var pluginName = 'spacecalendar';
|
||||
|
||||
// Find the plugin attached to the element
|
||||
var instance = this.data(pluginName);
|
||||
|
||||
// If the instance wasn't found, create it...
|
||||
if(!instance) {
|
||||
// Return the element being bound to
|
||||
return this.each(function() {
|
||||
return $(this).data(pluginName, new spacecalendar(this, options));
|
||||
});
|
||||
}
|
||||
|
||||
// ...otherwise if the user passes true to the plugin (on the second call),
|
||||
// then return the instance of the plugin itself
|
||||
return (options === true) ? instance : this;
|
||||
};
|
||||
|
||||
// Default options
|
||||
$.fn.spacecalendar.defaults =
|
||||
{
|
||||
// The house id
|
||||
houseId: 0,
|
||||
|
||||
// 开始时间
|
||||
startDate: null,
|
||||
|
||||
// 房源配置数组
|
||||
spaceData: [],
|
||||
|
||||
// 是否可以编辑
|
||||
isEditable: true,
|
||||
|
||||
// The date that will be treated as 'today'.
|
||||
todayDate: function(){
|
||||
var today = new Date();
|
||||
return today._clear();
|
||||
},
|
||||
|
||||
// The date that will appear selected when the spacecalendar renders.
|
||||
// By default it will be set to todayDate.
|
||||
selectedDate: null,
|
||||
|
||||
// Names of the month that will be shown in the title.
|
||||
// Will default to 1月, 2月,...,12月
|
||||
monthNames: null,
|
||||
|
||||
// Names of the days of the Week that will be shown below the title.
|
||||
// Will default to 周一, 周二,...,周日
|
||||
dowNames: null,
|
||||
|
||||
// The day of the week to start the spacecalendar on. 0 is Sunday, 1 is Monday and so on.
|
||||
dowOffset: 1,
|
||||
|
||||
// First date of the month.
|
||||
firstDate: null
|
||||
};
|
||||
|
||||
// Our plugin object
|
||||
var spacecalendar = (function() {
|
||||
// Main entry point. Initialize the plugin
|
||||
function spacecalendar(element, userOptions) {
|
||||
// Grab handle to this
|
||||
var self = this;
|
||||
|
||||
// Save bound element to el
|
||||
self.el = $(element);
|
||||
var el = self.el;
|
||||
|
||||
// Merge user options into default options
|
||||
self.options = $.extend(true, {}, $.fn.spacecalendar.defaults, userOptions);
|
||||
var options = self.options;
|
||||
|
||||
// Find the spacecalendar element if the user provided one
|
||||
self.spacecalendar = $($.find('[gldp-el=' + el.attr('gldp-id') + ' ]'));
|
||||
|
||||
if(!(el.attr('gldp-id') || '').length) {
|
||||
el.attr('gldp-id', 'gldp-' + Math.round(Math.random() * 1e10))
|
||||
}
|
||||
|
||||
el.addClass('gldp-el');
|
||||
|
||||
// Render spacecalendar
|
||||
self.render();
|
||||
// self.show();
|
||||
};
|
||||
|
||||
// Public methods
|
||||
spacecalendar.prototype =
|
||||
{
|
||||
// Render the spacecalendar
|
||||
render: function(renderCalback) {
|
||||
var self = this;
|
||||
var el = self.el;
|
||||
var options = self.options;
|
||||
var spacecalendar = self.spacecalendar;
|
||||
|
||||
// Build a core class (with border) that every element would have
|
||||
var coreClass = ' core border ';
|
||||
var cssName = 'gldp-default';
|
||||
|
||||
// Get today
|
||||
var todayVal = options.todayDate()._val();
|
||||
var todayTime = todayVal.time/1000;
|
||||
|
||||
// Constants
|
||||
var maxRow = 6;
|
||||
var maxCol = 7;
|
||||
|
||||
var dowNames = options.dowNames || [ '周日', '周一', '周二', '周三', '周四', '周五', '周六' ];
|
||||
var monthNames = options.monthNames || [ ' 1 月', ' 2 月', ' 3 月', ' 4 月', ' 5 月', ' 6 月', ' 7 月', ' 8 月', ' 9 月', ' 10 月', ' 11 月', ' 12 月' ];
|
||||
|
||||
// Create container width based on el size
|
||||
var containerWidth = el.outerWidth();
|
||||
// Create cell width based on container size
|
||||
var cellWidth = containerWidth / maxCol;
|
||||
|
||||
// If spacecalendar doesn't exist, create it and re-assign it to self
|
||||
if(!spacecalendar.length) {
|
||||
self.spacecalendar = spacecalendar = $('<div/>')
|
||||
.attr('gldp-el', el.attr('gldp-id'))
|
||||
.css(
|
||||
{
|
||||
width: containerWidth + 'px'
|
||||
});
|
||||
|
||||
$(el).append(spacecalendar);
|
||||
}
|
||||
|
||||
// Add core classes and remove spacecalendar's children
|
||||
spacecalendar.removeClass()
|
||||
.addClass(cssName)
|
||||
.children().remove();
|
||||
|
||||
// Helper function to setDate
|
||||
(function() {
|
||||
var _firstDate = new Date(options.startDate);
|
||||
if(_firstDate.getDate() != 1){
|
||||
_firstDate.setDate(1);
|
||||
_firstDate.setMonth(_firstDate.getMonth() + 1);
|
||||
}
|
||||
options.firstDate = _firstDate;
|
||||
})();
|
||||
|
||||
var getStartEndDate = function(_offset) {
|
||||
// Create start date as the first date of the month
|
||||
var _firstDate = new Date(options.firstDate);
|
||||
|
||||
// Default to no offset
|
||||
_offset = _offset || 0;
|
||||
|
||||
// Adjust date for month offset
|
||||
_firstDate.setMonth(_firstDate.getMonth() + _offset);
|
||||
|
||||
var startOffset = _firstDate.getDay() - options.dowOffset;
|
||||
startOffset = startOffset < 1 ? -7 - startOffset : -startOffset;
|
||||
|
||||
var _startDate = _firstDate._add(startOffset)/1000,
|
||||
_endDate = _firstDate._add(7*6-1)/1000;
|
||||
|
||||
return {startDate: _startDate, endDate: _endDate};
|
||||
};
|
||||
|
||||
// Get the previous, next start/end dates
|
||||
var prevDateObj = getStartEndDate(-1),
|
||||
nextDateObj = getStartEndDate(1);
|
||||
|
||||
var prevStartDate = prevDateObj.startDate,
|
||||
prevEndDate = prevDateObj.endDate;
|
||||
|
||||
var nextStartDate = nextDateObj.startDate,
|
||||
nextEndDate = nextDateObj.endDate;
|
||||
|
||||
// Get the first date for the current month being rendered
|
||||
var firstDateVal = options.firstDate._val();
|
||||
var firstDateMonth = firstDateVal.month;
|
||||
var firstDateYear = firstDateVal.year;
|
||||
|
||||
var prevCell = $('<div/>')
|
||||
.addClass("title")
|
||||
.append(
|
||||
$('<img/>')
|
||||
.addClass('prev-arrow')
|
||||
.attr("src", "/public/img/prev.png")
|
||||
)
|
||||
.mousedown(function() { return false; })
|
||||
.click(function(e) {
|
||||
window.location.href = "/spaces/index?house_id=" + options.houseId + "&startDate=" + prevStartDate + "&endDate=" + prevEndDate;
|
||||
});
|
||||
|
||||
var titleCell = $('<div/>').addClass('title');
|
||||
|
||||
var nextCell = $('<div/>')
|
||||
.addClass("title")
|
||||
.append(
|
||||
$('<img/>')
|
||||
.addClass('next-arrow')
|
||||
.attr("src", "/public/img/next.png")
|
||||
)
|
||||
.mousedown(function() { return false; })
|
||||
.click(function(e) {
|
||||
window.location.href = "/spaces/index?house_id=" + options.houseId + "&startDate=" + nextStartDate + "&endDate=" + nextEndDate;
|
||||
});
|
||||
|
||||
// Add cells for prev/title/next
|
||||
spacecalendar
|
||||
.append(prevCell)
|
||||
.append(titleCell)
|
||||
.append(nextCell)
|
||||
.append($('<div style="clear: both;"></div>'));
|
||||
|
||||
// Add all the cells to the spacecalendar
|
||||
for(var row = 0, cellIndex = 0; row < maxRow + 1; row++) {
|
||||
for(var col = 0; col < maxCol; col++, cellIndex++) {
|
||||
var cellDate = new Date(options.startDate);
|
||||
var cellClass = 'day';
|
||||
var cell = $('<div/>');
|
||||
var cellCSS = {width: cellWidth + 'px'};
|
||||
|
||||
if(!row) {
|
||||
cellClass = 'core dow';
|
||||
cell.html(dowNames[col]);
|
||||
cellDate = null;
|
||||
// Assign other properties to the cell
|
||||
cell.addClass(cellClass)
|
||||
.css(cellCSS);
|
||||
if(col == maxCol-2){
|
||||
cell.addClass("sat");
|
||||
}else if(col == maxCol-1){
|
||||
cell.addClass("sun");
|
||||
}
|
||||
} else {
|
||||
// Get the new date for this cell
|
||||
cellDate._add(col + ((row - 1) * maxCol));
|
||||
|
||||
// Get value for this date
|
||||
var cellDateVal = cellDate._val();
|
||||
var cellDateTime = cellDateVal.time/1000;
|
||||
|
||||
// Assign date for the cell
|
||||
var daySpan = $("<span/>");
|
||||
daySpan.addClass("day").html(cellDateVal.date + "日");
|
||||
cell.append(daySpan);
|
||||
|
||||
// 房源配置信息
|
||||
var spaceDiv = $("<div/>");
|
||||
if(options.spaceData.length == 0){
|
||||
if(todayTime <= cellDateTime){
|
||||
spaceDiv.addClass("opening countDiv").html("等待开放预约");
|
||||
}else{
|
||||
spaceDiv.addClass("unopened countDiv").html("未开放预约");
|
||||
}
|
||||
}else{
|
||||
var isFind = false;
|
||||
for(var i = 0, len = options.spaceData.length; i < len; i++){
|
||||
var spaceData = options.spaceData[i];
|
||||
if(spaceData.useDate == cellDateTime){
|
||||
var slashSpan = $('<span/>').html(" / ");
|
||||
var useSpan = $('<span/>');
|
||||
useSpan.addClass("useCount").html(spaceData.useCount);
|
||||
var totalSpan = $('<span/>');
|
||||
totalSpan.addClass("totalCount").html(spaceData.totalCount);
|
||||
|
||||
spaceDiv
|
||||
.addClass("opened countDiv")
|
||||
.append(useSpan)
|
||||
.append(slashSpan)
|
||||
.append(totalSpan);
|
||||
|
||||
cell.data('spaceData', spaceData);
|
||||
isFind = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!isFind){
|
||||
if(todayTime <= cellDateTime){
|
||||
spaceDiv.addClass("opening countDiv").html("等待开放预约");
|
||||
}else{
|
||||
spaceDiv.addClass("unopened countDiv").html("未开放预约");
|
||||
}
|
||||
}
|
||||
}
|
||||
cell.append(spaceDiv);
|
||||
|
||||
// Handle active dates and weekends
|
||||
cellClass = ([ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ])[cellDateVal.day];
|
||||
|
||||
// Handle today or selected dates
|
||||
if(cellDateVal.month != firstDateMonth) { cellClass += ' outMonth'; }
|
||||
if(cellDateTime < todayTime) { cellClass += ' prevDay'; }
|
||||
if(cellDateTime == todayTime) { cellClass = 'today';}
|
||||
|
||||
// Update the css for the cell
|
||||
if(col == 0){
|
||||
$.extend(cellCSS,
|
||||
{
|
||||
borderLeftWidth: 0
|
||||
});
|
||||
}else if(col == 6){
|
||||
$.extend(cellCSS,
|
||||
{
|
||||
borderRightWidth: 0
|
||||
});
|
||||
}
|
||||
|
||||
// Assign other properties to the cell
|
||||
cell
|
||||
.data('useDate', cellDateTime)
|
||||
.addClass(coreClass + cellClass)
|
||||
.css(cellCSS);
|
||||
|
||||
// 加入popover
|
||||
if(options.isEditable){
|
||||
if(cellDateTime >= todayTime) {
|
||||
cell.spacepopover("init", {id: cellDateTime, idName: "spacePopover"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add cell to spacecalendar
|
||||
spacecalendar.append(cell);
|
||||
}
|
||||
}
|
||||
|
||||
// Render the month / year title
|
||||
// Build month label
|
||||
var monthText = $('<span/>')
|
||||
.html(monthNames[firstDateMonth]);
|
||||
|
||||
// Build year label
|
||||
var yearText = $('<span/>')
|
||||
.html(firstDateYear + " 年 ");
|
||||
|
||||
var titleYearMonth = $('<div/>')
|
||||
.append(yearText)
|
||||
.append(monthText);
|
||||
|
||||
// Add to title
|
||||
titleCell.children().remove();
|
||||
titleCell.append(titleYearMonth);
|
||||
|
||||
// Run the callback signaling end of the render
|
||||
renderCalback = renderCalback || (function() {});
|
||||
renderCalback();
|
||||
}
|
||||
};
|
||||
|
||||
// Return the plugin
|
||||
return spacecalendar;
|
||||
})();
|
||||
|
||||
// One time initialization of useful prototypes
|
||||
(function() {
|
||||
Date.prototype._clear = function() {
|
||||
this.setHours(8);
|
||||
this.setMinutes(0);
|
||||
this.setSeconds(0);
|
||||
this.setMilliseconds(0);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Date.prototype._add = function(days) {
|
||||
return this.setDate(this.getDate() + days);
|
||||
};
|
||||
|
||||
Date.prototype._val = function() {
|
||||
return {
|
||||
year: this.getFullYear(),
|
||||
month: this.getMonth(),
|
||||
date: this.getDate(),
|
||||
time: this.getTime(),
|
||||
day: this.getDay()
|
||||
};
|
||||
};
|
||||
})();
|
||||
})();
|
269
frontend/static/js/common/spacepopover.js
Normal file
269
frontend/static/js/common/spacepopover.js
Normal file
@@ -0,0 +1,269 @@
|
||||
(function( $ ){
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.spacepopover.options, options );
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
var spaceEntity = $this.data("spaceData")||{};
|
||||
var idName = options.idName;
|
||||
var id = options.id;
|
||||
var shownFunc = options.shownFunc;
|
||||
var changeFollowFunc = options.changeFollowFunc;
|
||||
|
||||
$this.data("data-id", id);
|
||||
$this.data("data-idName", idName);
|
||||
|
||||
$this.popover({
|
||||
placement: 'left',
|
||||
trigger:"manual",
|
||||
html : true,
|
||||
animation:false,
|
||||
container:"body",
|
||||
content: (function(arg){
|
||||
return function(){
|
||||
return $this.spacepopover("getPopoverHtml", spaceEntity, idName, id);
|
||||
}
|
||||
})(id)
|
||||
});
|
||||
|
||||
$this.on("click", function(){
|
||||
var $activePop = $(".popover.in");
|
||||
if($activePop.length > 0){
|
||||
$activePop.spacepopover("hidePopover");
|
||||
}else{
|
||||
$this.spacepopover("showPopover");
|
||||
}
|
||||
});
|
||||
|
||||
$this.on('shown.bs.popover', function(){
|
||||
if(shownFunc != null){
|
||||
return shownFunc;
|
||||
}else{
|
||||
$("#saveButton").on("click", function(e){
|
||||
$(this).attr('disabled', "true");
|
||||
|
||||
var spaceEntity = $this.data("spaceData") || {};
|
||||
var $popContainer = $(this).parent();
|
||||
var totalCount = $popContainer.find(".totalCount").val();
|
||||
totalCount = $.trim(totalCount);
|
||||
|
||||
if($.isEmptyObject(spaceEntity)){
|
||||
if(totalCount == ""){
|
||||
$("#drTipbar").drtipbar("showMsg", "开放工位不能为空");
|
||||
$(this).removeAttr('disabled');
|
||||
return false;
|
||||
}
|
||||
if(totalCount == 0){
|
||||
$("#drTipbar").drtipbar("showMsg", "开放工位必须大于0");
|
||||
$(this).removeAttr('disabled');
|
||||
return false;
|
||||
}
|
||||
$this.spacepopover("createAction", totalCount, $(this));
|
||||
} else {
|
||||
var spaceId = spaceEntity.id,
|
||||
useCount = spaceEntity.useCount;
|
||||
if(totalCount < useCount){
|
||||
$("#drTipbar").drtipbar("showMsg", "开放工位不能小于已售出工位");
|
||||
$(this).removeAttr('disabled');
|
||||
return false;
|
||||
}
|
||||
if(useCount > 0 && totalCount == spaceEntity.totalCount){
|
||||
return false;
|
||||
}
|
||||
if(totalCount == 0 || totalCount == ""){
|
||||
$this.spacepopover("deleteAction", spaceId, $(this));
|
||||
}else{
|
||||
$this.spacepopover("updateAction", spaceId, totalCount, $(this));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
createAction: function(totalCount, $ele){
|
||||
var $this = $(this);
|
||||
var useDate = $this.data("useDate");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/spaces/create",
|
||||
data : "house_id=" + g_houseId + "&useDate=" + useDate + "&totalCount=" + totalCount,
|
||||
beforeSend:function(){
|
||||
var currentReq = $this.data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
complete:function(){
|
||||
$this.data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
var countDiv = $this.find(".countDiv");
|
||||
var slashSpan = $('<span/>').html("/");
|
||||
var useSpan = $('<span/>');
|
||||
useSpan.addClass("useCount").html(data.useCount);
|
||||
var totalSpan = $('<span/>');
|
||||
totalSpan.addClass("totalCount").html(data.totalCount);
|
||||
|
||||
countDiv
|
||||
.empty()
|
||||
.attr("class", "opened countDiv")
|
||||
.append(useSpan)
|
||||
.append(slashSpan)
|
||||
.append(totalSpan);
|
||||
|
||||
$this.data('spaceData', data);
|
||||
|
||||
$this.spacepopover("hidePopover");
|
||||
},
|
||||
error : function(data){
|
||||
$ele.removeAttr('disabled');
|
||||
$("#drTipbar").drtipbar("showMsg", data.responseJSON.errMessage);
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
$this.data("jRequest", jRequest);
|
||||
},
|
||||
deleteAction: function(spaceId, $ele){
|
||||
var $this = $(this);
|
||||
var useDate = $this.data("useDate");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/spaces/delete",
|
||||
data : "space_id=" + spaceId,
|
||||
beforeSend:function(){
|
||||
var currentReq = $this.data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
complete:function(){
|
||||
$this.data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
var countDiv = $this.find(".countDiv");
|
||||
countDiv
|
||||
.empty()
|
||||
.attr("class", "opening countDiv")
|
||||
.html("等待开放预约")
|
||||
|
||||
$this.data('spaceData', data);
|
||||
|
||||
$this.spacepopover("hidePopover");
|
||||
},
|
||||
error : function(data){
|
||||
$ele.removeAttr('disabled');
|
||||
$("#drTipbar").drtipbar("showMsg", data.responseJSON.errMessage);
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
$this.data("jRequest", jRequest);
|
||||
},
|
||||
updateAction: function(spaceId, totalCount, $ele){
|
||||
var $this = $(this);
|
||||
var useDate = $this.data("useDate");
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/spaces/update",
|
||||
data : "totalCount=" + totalCount + "&space_id=" + spaceId,
|
||||
beforeSend:function(){
|
||||
var currentReq = $this.data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
complete:function(){
|
||||
$this.data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
|
||||
$this.find(".useCount").html(data.useCount);
|
||||
$this.find(".totalCount").html(data.totalCount);
|
||||
|
||||
$this.data('spaceData', data);
|
||||
|
||||
$this.spacepopover("hidePopover");
|
||||
},
|
||||
error : function(data){
|
||||
$ele.removeAttr('disabled');
|
||||
$("#drTipbar").drtipbar("showMsg", data.responseJSON.errMessage);
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
$this.data("jRequest", jRequest);
|
||||
},
|
||||
showPopover:function(){
|
||||
var $this = $(this),
|
||||
spaceEntity = $this.data("spaceData") || {},
|
||||
id = $this.data("data-id"),
|
||||
idName = $this.data("data-idName");
|
||||
|
||||
$this.popover("show");
|
||||
|
||||
var popDiv = $("#"+idName+id);
|
||||
popDiv.find(".totalCount").val(spaceEntity.totalCount || 0);
|
||||
popDiv.find(".useCount").html(spaceEntity.useCount || 0);
|
||||
popDiv.find(".availableCount").html(spaceEntity.availableCount || 0);
|
||||
},
|
||||
hidePopover:function(){
|
||||
var $this = $(this);
|
||||
$this.popover("hide");
|
||||
},
|
||||
getPopoverHtml:function(spaceEntity, idName, id){
|
||||
var totalCount = spaceEntity.totalCount || 0,
|
||||
useCount = spaceEntity.useCount || 0,
|
||||
availableCount = spaceEntity.availableCount || 0;
|
||||
|
||||
return '<div id="' + idName + id + '" class="spacePopoverContentContainer">\
|
||||
<p class="total">\
|
||||
<span class="totalTitle">开放工位</span>\
|
||||
<input class="totalCount rightPos" value="' + totalCount + '" onpaste="return false;" onkeypress="numberLimit()" />\
|
||||
<div class="clear"></div>\
|
||||
</p>\
|
||||
<p class="use">\
|
||||
<span class="useTitle">已售出工位</span>\
|
||||
<span class="useCount rightPos">' + useCount + '</span>\
|
||||
<div class="clear"></div>\
|
||||
</p>\
|
||||
<p class="available">\
|
||||
<span class="availableTitle">剩余工位</span>\
|
||||
<span class="availableCount rightPos">' + availableCount + '</span>\
|
||||
<div class="clear"></div>\
|
||||
</p>\
|
||||
<button class="btnBlue" id="saveButton">保存</button>\
|
||||
</div>';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.spacepopover = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.spacepopover' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.spacepopover.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
265
frontend/static/js/common/teampopover.js
Normal file
265
frontend/static/js/common/teampopover.js
Normal file
@@ -0,0 +1,265 @@
|
||||
(function($) {
|
||||
var methods = {
|
||||
init: function(options) {
|
||||
var $this = this;
|
||||
options = $.extend($.fn.teampopover.options, options);
|
||||
return this.each(function() {
|
||||
var $this = $(this);
|
||||
var teamEntity = options.teamEntity;
|
||||
var idName = options.idName;
|
||||
var id = options.id;
|
||||
var shownFunc = options.shownFunc;
|
||||
var changeFollowFunc = options.changeFollowFunc;
|
||||
var hasLogin = options.hasLogin;
|
||||
var redirectLoginUrl = options.redirectLoginUrl;
|
||||
if (teamEntity == null) {
|
||||
return;
|
||||
}
|
||||
$this.data("teamEntity", teamEntity);
|
||||
$this.data("idName", idName);
|
||||
$this.data("id", id);
|
||||
$this.data("hasLogin", hasLogin);
|
||||
$this.data("redirectLoginUrl", redirectLoginUrl);
|
||||
//加上对应data标记
|
||||
$this.attr("data-teampopover", id);
|
||||
|
||||
$this.popover({
|
||||
trigger: "manual",
|
||||
html: true,
|
||||
animation: false,
|
||||
container: "body",
|
||||
content: (function(arg) {
|
||||
return function() {
|
||||
return $this.teampopover("getPopoverHtml", teamEntity, idName, id);
|
||||
}
|
||||
})(id)
|
||||
});
|
||||
|
||||
$this.on("mouseenter", (function(arg) {
|
||||
return function(e) {
|
||||
var appearTimeOut = setTimeout(function() {
|
||||
appearTimeOut = null;
|
||||
$this.off("mouseleave");
|
||||
if ($this.data('bs.popover').tip().hasClass('in')) {
|
||||
return;
|
||||
}
|
||||
$this.teampopover("showPopover");
|
||||
|
||||
var timeout = null;
|
||||
$this.on("mouseleave", function(e) {
|
||||
timeout = setTimeout(function() {
|
||||
$this.teampopover("hidePopover");
|
||||
}, 500);
|
||||
});
|
||||
|
||||
$("#" + idName + arg).parent().parent().off("mouseenter");
|
||||
$("#" + idName + arg).parent().parent().on("mouseenter", function() {
|
||||
if (timeout != null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
$("#" + idName + arg).parent().parent().off("mouseleave");
|
||||
$("#" + idName + arg).parent().parent().on("mouseleave", function() {
|
||||
$this.teampopover("hidePopover");
|
||||
});
|
||||
});
|
||||
}, 500);
|
||||
|
||||
$this.on("mouseleave", function() {
|
||||
if (appearTimeOut != null) {
|
||||
clearTimeout(appearTimeOut);
|
||||
appearTimeOut = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
})(id));
|
||||
|
||||
$this.on('shown.bs.popover', (function(arg) {
|
||||
if (shownFunc != null) {
|
||||
return shownFunc;
|
||||
} else {
|
||||
return function(e) {
|
||||
var hasLogin = $this.data("hasLogin");
|
||||
var redirectLoginUrl = $this.data("redirectLoginUrl");
|
||||
var dataplacement = $this.data("placement");
|
||||
|
||||
//调整位置
|
||||
var oldTop = $('.popover').css('top');
|
||||
oldTop = parseInt(oldTop.substr(0, oldTop.length - 2));
|
||||
var newTop = 0;
|
||||
if (dataplacement == "top") {
|
||||
newTop = oldTop - 5;
|
||||
} else {
|
||||
newTop = oldTop + 5;
|
||||
}
|
||||
$('.popover').css('top', newTop + "px");
|
||||
|
||||
var newLeft = $(e.target).offset().left - 50,
|
||||
contentWidth = e.target.offsetWidth;
|
||||
$('.popover').css('left', newLeft + "px");
|
||||
$('.arrow').css('left', contentWidth / 2 + 50 + 'px');
|
||||
|
||||
$("[data-popoverfollowteamid]").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
if (!hasLogin) {
|
||||
window.location.href = redirectLoginUrl;
|
||||
return;
|
||||
}
|
||||
var followTeamId = $("[data-popoverfollowteamid]").data("popoverfollowteamid");
|
||||
var isYourFollow = $("[data-popoverfollowteamid]").data("popoverisfollowteam");
|
||||
if (isYourFollow == 0) {
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").addClass("active");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").text("已关注");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").data("popoverisfollowteam", 1);
|
||||
if (changeFollowFunc != null) {
|
||||
changeFollowFunc(followTeamId, 1);
|
||||
}
|
||||
var jRequest = jQuery.ajax({
|
||||
type: "POST",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
url: "/teams/followteam",
|
||||
data: "team_id=" + followTeamId,
|
||||
beforeSend: function() {
|
||||
var currentReq = $("[data-popoverfollowteamid]").data("jRequest");
|
||||
if (currentReq != null) {
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$("[data-popoverFollowTeamId]").data("jRequest", null);
|
||||
},
|
||||
success: function(data) {
|
||||
},
|
||||
error: function(data) {
|
||||
if (data.statusText == "abort") {
|
||||
return;
|
||||
}
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").removeClass("active");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").text("关注");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").data("popoverisfollowteam", 0);
|
||||
if (changeFollowFunc != null) {
|
||||
changeFollowFunc(followTeamId, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("[data-popoverfollowteamid]").data("jRequest", jRequest);
|
||||
} else {
|
||||
//取消关注
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").removeClass("active");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").text("关注");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").data("popoverisfollowteam", 0);
|
||||
if (changeFollowFunc != null) {
|
||||
changeFollowFunc(followTeamId, 0);
|
||||
}
|
||||
var jRequest = jQuery.ajax({
|
||||
type: "POST",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
url: "/teams/unfollowteam",
|
||||
data: "team_id=" + followTeamId,
|
||||
beforeSend: function() {
|
||||
var currentReq = $("[data-popoverfollowteamid]").data("jRequest");
|
||||
if (currentReq != null) {
|
||||
currentReq.abort();
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$("[data-popoverfollowteamid]").data("jRequest", null);
|
||||
},
|
||||
success: function(data) {
|
||||
},
|
||||
error: function(data) {
|
||||
if (data.statusText == "abort") {
|
||||
return;
|
||||
}
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").addClass("active");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").text("已关注");
|
||||
$("[data-popoverfollowteamid=" + followTeamId + "]").data("popoverisfollowteam", 1);
|
||||
|
||||
if (changeFollowFunc != null) {
|
||||
changeFollowFunc(followTeamId, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
$("[data-popoverfollowteamid]").data("jRequest", jRequest);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})(id));
|
||||
});
|
||||
},
|
||||
showPopover: function() {
|
||||
var $this = this;
|
||||
return this.each(function() {
|
||||
//hide掉其他所有的
|
||||
$("[data-teampopover]").popover("hide");
|
||||
$this.popover("show");
|
||||
});
|
||||
},
|
||||
hidePopover: function() {
|
||||
var $this = this;
|
||||
return this.each(function() {
|
||||
$this.popover("hide");
|
||||
});
|
||||
},
|
||||
getPopoverHtml: function(teamEntity, idName, id) {
|
||||
if (teamEntity == null) {
|
||||
return null;
|
||||
}
|
||||
var fromTeamIconUrl = teamEntity.iconThumbUrl,
|
||||
fromTeamName = teamEntity.name,
|
||||
fromTeamWord = teamEntity.content,
|
||||
fromTeamArticleCount = teamEntity.articleCount,
|
||||
fromTeamFanCount = teamEntity.followCount,
|
||||
teamPopoverFollowStr = "",
|
||||
teamPopoverFollowStrClass = "",
|
||||
fromTeamId = teamEntity.id;
|
||||
|
||||
if (teamEntity.hasFollow == 1) {
|
||||
teamPopoverFollowStr = "已关注";
|
||||
teamPopoverFollowStrClass = "btnBlue active ";
|
||||
|
||||
} else {
|
||||
teamPopoverFollowStr = "关注";
|
||||
teamPopoverFollowStrClass = "btnBlue ";
|
||||
}
|
||||
|
||||
return '<div id="' + idName + id + '" class="teamPopoverContentContainer">\
|
||||
<div>\
|
||||
<a target="_blank" href="/teams/get?id=' + fromTeamId + '"><img class="teamPopoverTeamIcon img-circle" src="' + fromTeamIconUrl + '"/></a>\
|
||||
<div class="teamPopoverTeamInfoContainer">\
|
||||
<p class="teamPopoverTeamName"><a target="_blank" href="/teams/get?id=' + fromTeamId + '">' + $.htmlspecialchars(fromTeamName) + '</a></p>\
|
||||
<p class="teamPopoverTeamWord">' + $.htmlspecialchars(fromTeamWord) + '</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
<div class="divider"></div>\
|
||||
</div>\
|
||||
<div class="teamPopoverContentCountInfoContainer">\
|
||||
<div class="teamPopoverContentCountInfo">\
|
||||
<div class="teamPopoverContentArticleCountContainer"><span>' + fromTeamArticleCount + '</span><span>文章</span></div>\
|
||||
<div class="teamPopoverContentFanCountContainer"><span>' + fromTeamFanCount + '</span><span>粉丝</span></div>\
|
||||
</div>\
|
||||
<button class="' + teamPopoverFollowStrClass + ' teamPopoverFollowButton" data-popoverisfollowteam=' + teamEntity.hasFollow + ' data-popoverfollowteamid="' + teamEntity.id + '" id="teamPopoverFollowButton' + id + '">' + teamPopoverFollowStr + '</button>\
|
||||
<div class="clear"></div>\
|
||||
</div>\
|
||||
</div>';
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.teampopover = function(method) {
|
||||
|
||||
// Method calling logic
|
||||
if (methods[method]) {
|
||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
} else if (typeof method === 'object' || !method) {
|
||||
return methods.init.apply(this, arguments);
|
||||
} else {
|
||||
$.error('Method ' + method + ' does not exist on jQuery.teampopover');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.teampopover.options = {};
|
||||
|
||||
})(jQuery);
|
81
frontend/static/js/common/tipbar.js
Normal file
81
frontend/static/js/common/tipbar.js
Normal file
@@ -0,0 +1,81 @@
|
||||
(function( $ ){
|
||||
|
||||
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.drtipbar.options, options );
|
||||
return this.each(function(){
|
||||
// this.isShow = false;
|
||||
var $this = $(this);
|
||||
$this.data("isShow", false);
|
||||
$this.data("disappearTimer" , null);
|
||||
// this.disappearTimer = null;
|
||||
});
|
||||
|
||||
},
|
||||
showMsg:function(msg){
|
||||
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
if($this.data("isShow")){
|
||||
//直接显示msg
|
||||
$("#drTipbarContent").text(msg);
|
||||
$this.data("isShow", true);
|
||||
if($this.data("disappearTimer") != null){
|
||||
clearTimeout($this.data("disappearTimer") );
|
||||
var disappearTimer=setTimeout(function(){
|
||||
//消失动画
|
||||
$this.removeClass("drTipShow").addClass("drTipHide");
|
||||
$this.one(($.getTransitionEnd()).end, function() {
|
||||
$this.data("disappearTimer",null)
|
||||
$this.data("isShow",false)
|
||||
});
|
||||
|
||||
|
||||
},3000);
|
||||
$this.data("disappearTimer",disappearTimer)
|
||||
}
|
||||
|
||||
}else{
|
||||
$this.data("isShow", true);
|
||||
$("#drTipbarContent").text(msg);
|
||||
$this.removeClass("drTipHide").addClass("drTipShow");
|
||||
var disappearTimer=setTimeout(function(){
|
||||
//消失动画
|
||||
$this.removeClass("drTipShow").addClass("drTipHide");
|
||||
$this.one(($.getTransitionEnd()).end, function() {
|
||||
$this.data("disappearTimer",null)
|
||||
$this.data("isShow",false)
|
||||
});
|
||||
},3000);
|
||||
$this.data("disappearTimer",disappearTimer)
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.drtipbar = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.drtipbar' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.drtipbar.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
332
frontend/static/js/common/userpopover.js
Normal file
332
frontend/static/js/common/userpopover.js
Normal file
@@ -0,0 +1,332 @@
|
||||
(function( $ ){
|
||||
|
||||
|
||||
|
||||
var methods = {
|
||||
init : function( options ){
|
||||
var $this = this;
|
||||
options = $.extend( $.fn.userpopover.options, options );
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
var userEntity = options.userEntity;
|
||||
var idName = options.idName;
|
||||
var id = options.id;
|
||||
var shownFunc = options.shownFunc;
|
||||
var currentUserId = options.currentUserId;
|
||||
var changeFollowFunc = options.changeFollowFunc;
|
||||
var hasLogin = options.hasLogin;
|
||||
var redirectLoginUrl = options.redirectLoginUrl;
|
||||
if(userEntity == null){
|
||||
return;
|
||||
}
|
||||
$this.data("userEntity",userEntity);
|
||||
$this.data("idName",idName);
|
||||
$this.data("id",id);
|
||||
$this.data("currentUserId",currentUserId);
|
||||
$this.data("hasLogin",hasLogin);
|
||||
$this.data("redirectLoginUrl",redirectLoginUrl);
|
||||
//加上对应data标记
|
||||
$this.attr("data-userpopover",id);
|
||||
|
||||
$this.popover({
|
||||
trigger:"manual",
|
||||
html : true,
|
||||
animation:false,
|
||||
container:"body",
|
||||
content: (function(arg){
|
||||
|
||||
return function(){
|
||||
return $this.userpopover("getPopoverHtml",userEntity,idName,id);
|
||||
}
|
||||
|
||||
})(id)
|
||||
});
|
||||
|
||||
$this.on("mouseenter",(function(arg){
|
||||
|
||||
return function(e){
|
||||
var appearTimeOut = setTimeout(function(){
|
||||
appearTimeOut = null;
|
||||
$this.off("mouseleave");
|
||||
if($this.data('bs.popover').tip().hasClass('in')){
|
||||
return;
|
||||
}
|
||||
$this.userpopover("showPopover");
|
||||
|
||||
|
||||
|
||||
var timeout = null;
|
||||
$this.on("mouseleave",function(e){
|
||||
timeout = setTimeout(function(){
|
||||
$this.userpopover("hidePopover");
|
||||
|
||||
},500);
|
||||
});
|
||||
$("#"+idName + arg ).parent().parent().off("mouseenter");
|
||||
|
||||
$("#"+idName + arg ).parent().parent().on("mouseenter",function(){
|
||||
|
||||
if(timeout != null){
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
|
||||
$("#"+idName + arg ).parent().parent().off("mouseleave");
|
||||
$("#"+idName + arg ).parent().parent().on("mouseleave",function(){
|
||||
$this.userpopover("hidePopover");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
},500);
|
||||
|
||||
$this.on("mouseleave",function(){
|
||||
|
||||
if(appearTimeOut != null){
|
||||
clearTimeout(appearTimeOut);
|
||||
appearTimeOut = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
})(id));
|
||||
|
||||
|
||||
$this.on('shown.bs.popover',(function(arg){
|
||||
|
||||
if(shownFunc != null){
|
||||
return shownFunc;
|
||||
}else{
|
||||
return function(e){
|
||||
var currentUserId = $this.data("currentUserId");
|
||||
var hasLogin = $this.data("hasLogin");
|
||||
var redirectLoginUrl = $this.data("redirectLoginUrl");
|
||||
var dataplacement = $this.data("placement");
|
||||
|
||||
//调整位置
|
||||
var oldTop = $('.popover').css('top');
|
||||
oldTop = parseInt(oldTop.substr(0,oldTop.length - 2));
|
||||
var newTop = 0;
|
||||
if(dataplacement == "top"){
|
||||
newTop = oldTop - 5;
|
||||
}else{
|
||||
newTop = oldTop + 5;
|
||||
}
|
||||
|
||||
$('.popover').css('top', newTop + "px");
|
||||
var oldLeft = $('.popover').css('left');
|
||||
oldLeft = parseInt(oldLeft.substr(0,oldLeft.length - 2));
|
||||
var newLeft = oldLeft;
|
||||
var outerWidth = $('.popover').outerWidth();
|
||||
newLeft = $(e.target).offset().left - 50;
|
||||
var contentWidth = e.target.offsetWidth;
|
||||
$('.popover').css('left', newLeft + "px");
|
||||
$('.arrow').css('left',contentWidth/2 + 50 + 'px');
|
||||
|
||||
var role = $("[data-popoverfollowuserid]").data("popoveruserrole");
|
||||
var popUserId = $("[data-popoverfollowuserid]").data("popoverfollowuserid");
|
||||
if(role == "超级管理员" || currentUserId == popUserId ){
|
||||
$("[data-popoverfollowuserid]").hide();
|
||||
}
|
||||
|
||||
$("[data-popoverfollowuserid]").on("click",function(e){
|
||||
e.preventDefault();
|
||||
if(!hasLogin){
|
||||
window.location.href=redirectLoginUrl;
|
||||
return;
|
||||
}
|
||||
var followUserId = $("[data-popoverfollowuserid]").data("popoverfollowuserid");
|
||||
var isYourFollow = $("[data-popoverfollowuserid]").data("popoverisfollowuser");
|
||||
if(isYourFollow == 0){
|
||||
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").addClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("已关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",1);
|
||||
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,1);
|
||||
}
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/users/follow",
|
||||
data : "follow_id=" + followUserId,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("[data-popoverfollowuserid]").data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("[data-popoverFollowUserId]").data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
//刷新ui
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").addClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("已关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",1);
|
||||
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,1);
|
||||
}
|
||||
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").removeClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",0);
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,0);
|
||||
}
|
||||
|
||||
}});
|
||||
|
||||
$("[data-popoverfollowuserid]").data("jRequest",jRequest);
|
||||
}else{
|
||||
//取消关注
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").removeClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",0);
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,0);
|
||||
}
|
||||
var jRequest = jQuery.ajax({
|
||||
type : "POST",
|
||||
contentType : "application/x-www-form-urlencoded",
|
||||
url : "/users/unfollow",
|
||||
data : "follow_id=" + followUserId,
|
||||
beforeSend:function(){
|
||||
var currentReq = $("[data-popoverfollowuserid]").data("jRequest");
|
||||
if(currentReq != null){
|
||||
currentReq.abort();
|
||||
}
|
||||
|
||||
},
|
||||
complete:function(){
|
||||
$("[data-popoverfollowuserid]").data("jRequest",null);
|
||||
},
|
||||
success : function(data){
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").removeClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",0);
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,0);
|
||||
}
|
||||
},
|
||||
error : function(data){
|
||||
if(data.statusText=="abort"){
|
||||
return;
|
||||
}
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").addClass("active");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").text("已关注");
|
||||
$("[data-popoverfollowuserid="+followUserId+"]").data("popoverisfollowuser",1);
|
||||
|
||||
if(changeFollowFunc != null){
|
||||
changeFollowFunc(followUserId,1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("[data-popoverfollowuserid]").data("jRequest",jRequest);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})(id));
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
showPopover:function(){
|
||||
var $this = this;
|
||||
return this.each(function(){
|
||||
//hide掉其他所有的
|
||||
$("[data-userpopover]").popover("hide");
|
||||
$this.popover("show");
|
||||
});
|
||||
},
|
||||
hidePopover:function(){
|
||||
var $this = this;
|
||||
return this.each(function(){
|
||||
$this.popover("hide");
|
||||
});
|
||||
},
|
||||
getPopoverHtml:function(userEntity,idName,id){
|
||||
|
||||
if(userEntity == null){
|
||||
return null;
|
||||
}
|
||||
var fromUserAvatarUrl = userEntity.avatarThumbUrl;
|
||||
var fromUserName = userEntity.userName;
|
||||
var fromUserWord = userEntity.word;
|
||||
var fromUserArticleCount = userEntity.articleCount;
|
||||
var fromUserFanCount = userEntity.fanCount;
|
||||
var userPopoverFollowStr = "";
|
||||
var userPopoverFollowStrClass = "";
|
||||
var fromUserGuid = userEntity.guid;
|
||||
if(userEntity.isYourFollow == 1){
|
||||
userPopoverFollowStr = "已关注";
|
||||
userPopoverFollowStrClass = "btnBlue active ";
|
||||
|
||||
}else{
|
||||
userPopoverFollowStr = "关注";
|
||||
userPopoverFollowStrClass = "btnBlue ";
|
||||
}
|
||||
|
||||
return '<div id="' + idName + id + '" class="userPopoverContentContainer">\
|
||||
<div>\
|
||||
<a target="_blank" href="/users/get?guid='+fromUserGuid+'"><img class="userPopoverUserAvatar img-circle" src="'+fromUserAvatarUrl+'"/></a>\
|
||||
<div class="userPopoverUserInfoContainer">\
|
||||
<p class="userPopoverUserName"><a target="_blank" href="/users/get?guid='+fromUserGuid+'">'+$.htmlspecialchars(fromUserName)+'</a></p>\
|
||||
<p class="userPopoverUserWord">'+$.htmlspecialchars(fromUserWord)+'</p>\
|
||||
</div>\
|
||||
<div class="clear"></div>\
|
||||
<div class="divider"></div>\
|
||||
</div>\
|
||||
<div class="userPopoverContentCountInfoContainer">\
|
||||
<div class="userPopoverContentCountInfo">\
|
||||
<div class="userPopoverContentArticleCountContainer"><span>'+fromUserArticleCount+'</span><span>文章</span></div>\
|
||||
<div class="userPopoverContentFanCountContainer"><span>'+fromUserFanCount+'</span><span>粉丝</span></div>\
|
||||
</div>\
|
||||
<button class="'+userPopoverFollowStrClass+' userPopoverFollowButton" data-popoveruserrole="'+userEntity.role+'" data-popoverisfollowuser='+userEntity.isYourFollow+' data-popoverfollowuserid="'+userEntity.id+'" id="userPopoverFollowButton'+id+'">'+userPopoverFollowStr+'</button>\
|
||||
<div class="clear"></div>\
|
||||
</div>\
|
||||
</div>';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.fn.userpopover = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.userpopover' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.userpopover.options = {};
|
||||
|
||||
|
||||
})( jQuery );
|
Reference in New Issue
Block a user