提交 9713ccdc 编写于 作者: 街头小贩's avatar 街头小贩

js更新

上级 8042a35b
jForum.pagination = (function () {
jForum.pagination = (function ($) {
class Page {
constructor(option) {
this.config = $.extend({ pageSize: 20, totalRecords: 0, page: 1, range: 10, url: '', dataType: 'json' }, option);
option.page = getCurrentPageNumber();
this.config = $.extend({ pageSize: 20, totalRecords: 0, range: 10, url: '', dataType: 'json' }, option);
}
getPage(){
return this.config.page;
}
/**
* 计算有多少页
* @param {number} totalRecords - 总记录数
* @param {number} pageSize - 每页显示的记录数
* @returns {Object}
* @returns 总页数
*/
getTotalPage(totalRecords, pageSize) {
var tp = (totalRecords == 0) ? -1 : 1;
if (totalRecords > pageSize) {
var tp = Math.floor(totalRecords / pageSize);
if (totalRecords % pageSize !== 0) {
_getTotalPage(totalRecords, pageSize) {
var tr = totalRecords;
var ps = pageSize;
var tp = (tr == 0) ? -1 : 1;
if (tr > ps) {
var tp = Math.floor(tr / ps);
if (tr % ps !== 0) {
tp += 1;
}
}
return {
pageSize: pageSize,
pages: tp,
records: totalRecords
};
return tp;
}
/**
* 获取数据
* @param {string} requestURI - 异步请求的地址
* @param {string} dataType - 请求的数据类型, json|jsonp
* @param {number} pageSize - 每页显示的记录数
* @param {number} page - 当前页码值
* @param {Object} jqEle - 当前的jQuery元素
*/
getData(requestURI, dataType, pageSize, page, jqEle) {
var self = this; //self.disable();
getData(page, jqEle) {
var curi = this.config.url;
var dt = this.config.dataType;
//
var formatAjaxParams = {
type: 'get',
cache: false,
data: {},
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
dataType: dataType,
dataType: dt,
async: true,
timeout: 3000
};
formatAjaxParams.url = requestURI;
var postData = {};
postData.pageSize = pageSize;
formatAjaxParams.url = curi;
var postData = {}; var _curIns = this;
postData.pageSize = this.config.pageSize;
postData.pageNumber = page;
$.extend(formatAjaxParams.data || {}, postData);
formatAjaxParams.success = function (response) {
var a = self.getTotalPage(response.total, pageSize);
// gtx.range=页码范围
// a.pages=总页数
var b = self.calc(page, 10, a.pages);
self.render(b.start, b.end, page, a.pages, jqEle);
if ($.isFunction(self.jsonCallbackHandler)) {
self.jsonCallbackHandler(response.result);
var a = _curIns._getTotalPage(response.total, response.size);
// 当前页
// a=总页数
var b = _curIns._calc(response.page, a);
_curIns.render(b.start, b.end, response.page, a, jqEle);
if ($.isFunction(_curIns.config.jsonCallback)) {
_curIns.config.jsonCallback(response.result);
}
//滚动到顶部
$('html, body').animate({ scrollTop: 0 }, 500);
......@@ -62,40 +64,41 @@ jForum.pagination = (function () {
};
formatAjaxParams.error = function (jqXHR, textStatus, errorThrown) {
};
formatAjaxParams.beforeSend = function (xhr) {
if ($.isFunction(self.ajaxBeforeHandler)) {
self.ajaxBeforeHandler(xhr);
if ($.isFunction(_curIns.config.ajaxBefore)) {
_curIns.config.ajaxBefore(xhr);
}
console.log('[pagination] ajax before send exec');
};
formatAjaxParams.complete = function (xhr, textStatus) {
if ($.isFunction(self.ajaxCompleteHandler)) {
self.ajaxCompleteHandler(xhr, textStatus);
if ($.isFunction(_curIns.config.ajaxComplete)) {
_curIns.config.ajaxComplete(xhr, textStatus);
}
//记入历史
recordHistory(page, pageSize);
//recordHistory(page, pageSize);
console.log('[pagination] ajax is complete');
};
$.ajax(formatAjaxParams);
}
/**
* 绑定翻页事件
* @param {Object} page - 所有的配置参数
* @param {Object} jqEle - 当前的jQuery元素
*/
bindEvent(finalConfig, jqEle) {
var self = this;
bindEvent(jqEle) {
var _curIns = this;
$('body').on('click', 'a.previous-btn,a.next-btn', function (e) {
e.stopPropagation();
e.stopPropagation();
var _ele = $(e.target);
//
var _pageNumber = $(this).parent().attr('data-num');
self.getData(finalConfig.url, finalConfig.dataType, finalConfig.pageSize, parseInt(_pageNumber), jqEle);
var _pageNumber = _ele.parent().attr('data-num');
_curIns.getData(parseInt(_pageNumber), jqEle);
return false;
});
$('body').on('click', 'li[data-num]', function (e) {
//
var _pageNumber = $(this).attr('data-num');
self.getData(finalConfig.url, finalConfig.dataType, finalConfig.pageSize, parseInt(_pageNumber), jqEle);
$('body').on('click', 'li[data-num]>a.page-link', function (e) {
var _ele = $(this);
var _pageNumber = _ele.parent().attr('data-num');
_curIns.getData(parseInt(_pageNumber), jqEle);
});
}
/**
......@@ -143,41 +146,32 @@ jForum.pagination = (function () {
jqEle.find('.page-navigation').remove();
jqEle.append(T);
//
if ($.isFunction(this.renderCompleteHandler)) {
this.renderCompleteHandler(T, pnSelector);
if ($.isFunction(this.config.randerPageStruct)) {
this.config.randerPageStruct(T, pnSelector);
}
}
/**
* 计算显示页码值显示的上下界
* @param {number} currentPage - 当前页码值
* @param {number} pageRange - 页码显示的范围值
* @param {number} totalPage - 总页数
* @returns {Object}
*/
calc(currentPage, pageRange, totalPage) {
var nR = Math.floor(currentPage / pageRange);
if (currentPage % pageRange > 0) {
_calc(currentPage, totalPage) {
var cp = this.config.range;
var nR = Math.floor(currentPage / cp);
if (currentPage % cp > 0) {
nR += 1;
}
var rangeEnd = nR * pageRange;
var rangeEnd = nR * cp;
if (rangeEnd > totalPage) {
rangeEnd = totalPage;
}
var rangeStart = nR * pageRange - pageRange + 1;
var rangeStart = nR * cp - cp + 1;
return {
start: rangeStart,
end: rangeEnd
};
}
/**
* 合成配置参数
* @param {Object} option - 配置参数
* @returns {Object}
*/
init(option) {
var config = $.extend({ pageSize: 20, totalRecords: 0, page: 1, range: 10, url: '', dataType: 'json' }, option);
return config;
}
}
//无分页查询字符串返回1,有的返回其值
function getCurrentPageNumber() {
......@@ -187,7 +181,7 @@ jForum.pagination = (function () {
var cuQueryString = window.location.search;
if (cuQueryString) {
var pn = getQueryString(pnParam, cuQueryString);
return (isBlank(pn)) ? 1 : pn;
return (jForum.utils.isBlank(pn)) ? 1 : pn;
}
return 1;
};
......@@ -220,7 +214,7 @@ jForum.pagination = (function () {
if (cuQueryString) {
cuLocation = cuLocation.substring(0, cuLocation.indexOf('?'));
cuQueryString = cuQueryString.replace(/[?&]p=\d+/g, '').substring(1);
if (!isBlank(cuQueryString)) {
if (!jForum.utils.isBlank(cuQueryString)) {
cuLocation += '?' + cuQueryString;
}
}
......@@ -239,4 +233,4 @@ jForum.pagination = (function () {
return string ? string[1] : null;
};
return Page;
})();
\ No newline at end of file
})(jQuery);
\ No newline at end of file
......@@ -328,6 +328,384 @@ jForum.template = (function ($) {
var rs = $.extend(obj, {"APP":BASE});
targetEleSelector.append(Mustache.render(T, rs));
};
//首页话题列表加载像册的回调
tmp.packAlbumHoldSection = function(json){
if(jQuery.isEmptyObject(json)){
return;
}
$('div[data-album]').each(function(){
var tmpBody = $(this);
var aid = tmpBody.attr('data-album');
var rs = {};
rs.result = json[aid];
var T='<ul class="list-inline album-thumb">'
+'{#result}'
+' <li class="list-inline-item"><a href="{link}" data-toggle="lightbox" data-title="{caption}" data-gallery="threads-{album}-gallery" data-type="image"><img class="lazyload" src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-original="{thumbnail}"/></a></li>'
+'{/result}'
+' </ul>';
Mustache.parse(T, ['{', '}']);
tmpBody.append(Mustache.render(T, rs)).find('img.lazyload').lazyload();
});
};
//版块首页加载版块的统计
tmp.loadBoardStatsResult = function(json, element){
if(jQuery.isEmptyObject(json.result)){
return;
}
$.each(json.result, function(index, item){
var tb = $('[data-board="'+item.board+'"]');
tb.find('.threads').html(item.topices);
tb.find('.replies').html(item.postses);
tb.find('.today-counter').html('('+item.todayTopics+')');
//游客操作的不显示
if(parseInt(item.recentAuthor)>0){
var T = ''
+'<dfn>Last posts</dfn>'
+'<a href="{APP}{recentLink}" title="{recentTitle}" class="lastsubject">{recentTitle}</a> '
+'<a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a> &#187; {recentDate}';
Mustache.parse(T, ['{', '}']);
var rs = $.extend(item, {"APP":BASE});
tb.find('.latest').append(Mustache.render(T, rs));
}
});
};
//话题|版块的工具菜单
tmp.buildMenuList = function(json){
var jqEle = $('#'+json.element);
var T=''; var tmpSize=1; var kt = Object.keys(json.result).length;
$.each(json.result, function(key, value){ //公共|私有
$.each(value, function(index, item){ //连接
var tmp;
if(item.ajax){
tmp='<a href="javascript:;" class="dropdown-item action-cmd" data-handler="%URL%">%UA%</a>';
}else{
tmp='<a class="dropdown-item" href="%URL%" target="_blank">%UA%</a>';
}
T+=tmp.replace('%URL%', BASE+item.uri).replace('%UA%', item.anchor);
});
if(kt > tmpSize){
T+='<div class="dropdown-divider"></div>';
}
tmpSize += 1;
});
jqEle.append(T);
};
//底部的版块导航
tmp.buildBoardNavigateSelect = function(json){
//生成select
var selectEleWrox = $('#'+json.element);
var selectEle = $('<select class="form-control" aria-hidden="true"></select>').appendTo(selectEleWrox);
//
var selectData=new Array();
$.each(json.result, function(key,value){
var dataItem ={};
dataItem.text = key;
dataItem.children = new Array();
$.each(value, function(innerIndex,innerObj){
$.each(innerObj, function (attrName, attrValue) {
dataItem.children.push({id: attrName, text: attrValue});
});
});
selectData.push(dataItem);
});
var sob = selectEle.select2({
theme: 'bootstrap4',
data: selectData
});
sob.on("select2:select", function (e) {
//选中的值是?
var selectBoard = e.params.data.id;
if(selectBoard && !jForum.utils.isBlank(selectBoard)){
window.location.href = BASE+'/board/'+selectBoard+'.xhtml';
}
});
//显示
selectEleWrox.find('p.board-navigator-select').remove();
sob.select2("open");
};
//版块话题的动态加载回调函数
tmp.drawThreads = function(jsonArray){
var targetEleSelector = $('#board_topic_collect');
targetEleSelector.find('.dynamic-topic-record').remove();
var obj = {};
obj.result = jsonArray;
var T='{#result}'
+'<li class="board_item dynamic-topic-record">'
+' <dl class="icon topic_{status}">'
+' <dt>'
+' <div class="board_item_title">'
+' <article class="forum-article-header">'
+' {#oneDay}<span class="label" title="新鲜的">&#x1F31F</span> {/oneDay}'
+' {#top}<span class="label" title="置顶话题">&#x1F4CC</span> {/top}'
+' {#best}<span class="label" title="精华话题">&#x1F48E</span> {/best}'
+' {#image}<span class="label" title="图片话题">&#x1F304</span> {/image}'
+' {#hot}<span class="label" title="很火噢">&#x1F525</span> {/hot}'
+' <a href="{APP}{boardLink}?category={categoryKey}">[{category}]</a> '
+' <a href="{APP}{link}" class="forumtitle">{title}</a>'
+' </article>'
+' <a class="txtline" href="{APP}/member/{author}.xhtml">{authorNames}</a> &#187; {date}'
+' </div>'
+' </dt>'
+' <dd class="replies wp10 stats-item">{replies}<dfn>Replies</dfn></dd>'
+' <dd class="views wp10 stats-item">{views}<dfn>Views</dfn></dd>'
+' <dd class="latest">{#recent}'
+' <span class="last-posts-avatar">'
+' <img src ="{APP}/member/avatar/{recentAuthor}.png" width="32px" height="32px"/>'
+' </span>'
+' <span class="last-posts">'
+' <a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a>'
+' <br/>'
+' {recentDate}'
+' </span>{/recent}'
+' </dd>'
+' </dl>'
+'</li>{/result}';
var extRS={
recent : function(){
return parseInt(this.recentAuthor) > 0;
},
APP : BASE
};
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, extRS);
targetEleSelector.append(Mustache.render(T, rs));
};
//话题回复的动态加载回调函数
tmp.drawReplier = function(jsonArray){
var targetEleSelector = $('#topic_posts_collect');
targetEleSelector.find('.dynamic-posts-record').remove();
var obj = {};
obj.result = jsonArray;
var T='{#result}'
+'<div class="topic_posts dynamic-posts-record">'
+' <div class="topic_posts_item">'
+' <dl class="topic_posts_item_left" data-handler="{APP}/member/profile.json?id={author}">'
+' <dt style="padding-top: 20px;padding-left: 20px;width:180px">'
+' <div class="posts-member-avatar">'
+' <a href="javascript:;" class="avatar poper-member-menu">'
+' <img class="avatar" src="{APP}/member/avatar/{author}.png" alt="User avatar" />'
+' </a>'
+' </div>'
+' <a href="{APP}/member/{author}.xhtml" class="member-info"> <span class="member-{author}-label member-{authorStyle}">{authorNames}</span></a>'
+' </dt>'
+' <dd>{authorGroup}</dd>'
+' {#master}<dd><small class="badge badge-dark">楼主</small></dd>{/master}'
+' </dl>'
+' <div class="topic_posts_item_right">'
+' <div id="posts-{id}" class="posts-body">'
+' <ul class="posts-buttons">'
+' <li><a href="javascript:;" class="action-cmd delete-post" data-handler="{APP}/posts/delete" data-query="id:{id}"><i class="ico-sm mdi mdi-delete" aria-hidden="true"></i><span>删除</span></a></li>'
+' <li><a href="javascript:;" class="post-action-quote" data-handler="{APP}/posts/quote/data.json" data-query="id:{id}"><i class="ico-sm mdi mdi-quote"></i><span>回复</span></a></li>'
+' <li><a href="javascript:;" class="post-action-report" data-handler="{APP}/posts/report" data-query="id:{id}"><i class="ico-sm mdi mdi-flag"></i><span>举报</span></a></li>'
+' <li><a name="#posts-{id}">{floor}<sup>#</sup></a></li>'
+' </ul>'
+' <p class="posts-member">'
+' <a href="{APP}/member/{author}.xhtml">{authorNames} @u{author}</a>&nbsp;&nbsp;&#187;&nbsp;&nbsp; '
+' <i class="ico-sm mdi mdi-time" aria-hidden="true"></i> {date}'
+' </p>'
+' <div class="posts-body-content">'
+' {#block}<p class="alert alert-danger"><strong>提示:</strong> 作者被禁止发言或内容自动屏蔽</p>{/block}'
+' {^block}'
+' {&content}{&modify}'
+' {/block}'
+' <div class="mood-section" data-mood="{id}">'
+' <a href="javascript:;" title="支持" role="button" class="btn-light btn-sm mood-action" data-action="1" id="{id}-likes"><i class="mdi mdi-thumb-up" aria-hidden="true"></i></a>'
+' <a href="javascript:;" title="不赞同" role="button" class="btn-light btn-sm mood-action" data-action="2" id="{id}-hates"><i class="mdi mdi-thumb-down" aria-hidden="true"></i></a>'
+' </div>'
+' </div>'
+' <div class="posts-member-signature member-{author}-signature">{authorSignature}</div>'
+' </div>'
+' </div>'
+' </div>'
+'</div>{/result}';
var extRS={
modify : function(){
return this.modifyDate.length == 0?'':'<p class="alert alert-warning">回复最近由 '+this.modifyer+''+this.modifyDate+' 编辑</p>';
},
APP : BASE
};
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, extRS);
targetEleSelector.append(Mustache.render(T, rs));
//图片的懒加载
targetEleSelector.find('img.lazyload').lazyload();
};
//会员中心的历史记录
tmp.drawActionHistory = function(jsonArray){
var targetEleSelector = $('#member-home-actions');
targetEleSelector.find('.home-record-item').remove();
var obj = {};
obj.result = jsonArray;
var T ='{#result}'
+' <div class="home-record-item">'
+' <div class="record-item-body">'
+' <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
+' <span>{actionTitle}&nbsp;&#187;&nbsp;{actionDate}</span>'
+' </div>'
+' </div>{/result}';
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, {"APP":BASE});
targetEleSelector.append(Mustache.render(T, rs));
};
//个人中心消息收件箱回调
tmp.memberInboxTemplate = function(jsonArray){
var targetEleSelector = $('#member-message-records');
var obj = {};
obj.result = jsonArray;
var T ='<ul class="media-list" style="padding: 10px 20px;">{#result}'
+' <li class="media letter-item">'
+' <div class="media-left mr-3">'
+' {#robot}<img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/0.png" title="message robot">{/robot}'
+' {^robot}<a href="{APP}{senderURI}"><img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/{sender}.png" title="{senderNickname}"></a>{/robot}'
+' </div>'
+' <div class="media-body">'
+' <h6 class="media-heading">{senderNickname} &nbsp;<span id="notice_{sender}" class="badge">0</span><span class="float-right"><i class="ico-sm mdi mdi-time"></i>&nbsp;{datetime}</span></h6>'
+' <div><a href="{APP}/message/view?sender={sender}" target="_blank">{subject}</a></div>'
+' </div>'
+' </li>{/result}</ul>';
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, {"APP":BASE});
targetEleSelector.append(Mustache.render(T, rs));
};
//个人中心消息发件箱回调
tmp.memberOutboxTemplate = function(jsonArray){
var targetEleSelector = $('#member-message-records');
var obj = {};
obj.result = jsonArray;
var T ='<ul class="media-list" style="padding: 10px 20px;">{#result}'
+' <li class="media letter-item">'
+' <div class="media-left mr-3">'
+' {#everyone}<img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/0.png" title="message robot">{/everyone}'
+' {^everyone}<a href="{APP}{receiverURI}"><img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/{receiver}.png" title="{receiverNickname}"></a>{/everyone}'
+' </div>'
+' <div class="media-body">'
+' <h6 class="media-heading">{&reces} &nbsp;<small>[{category}]</small><span class="float-right"><i class="ico-sm mdi mdi-time"></i>&nbsp;{datetime}</span></h6>'
+' <div class="letter-item-content">'
+' <p>{&content}</p>'
+' </div>'
+' </div>'
+' </li>{/result}</ul>';
var extRS={
reces : function(){
var tmp=''; var rs = this.receives;
for (var i = 0, len = rs.length; i < len; ++i) {
var rmid = rs[i].id;
var rmnm = rs[i].nickname;
tmp += '<a href="'+BASE+'/member/'+rmid+'.xhtml">'+rmnm+'</a>';
if(i< len -1){
tmp +'&nbsp;,&nbsp;';
}
}
return tmp;
},
APP : BASE
};
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, extRS);
targetEleSelector.append(Mustache.render(T, rs));
};
//会员中心的话题|回复
tmp.drawMHomeRecord = function(jsonArray){
var targetEleSelector = $('#member-home-records');
targetEleSelector.find('.home-record-item').remove();
var obj = {};
obj.result = jsonArray;
var T ='{#result}'
+' <div class="home-record-item">'
+' <div class="record-item-body">'
+' <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
+' <span>楼主: <a href="{APP}{publisherURI}">{publisher}</a></span>'
+' <span>发布日期: {publishDate}</span>'
+' {#reply}'
+' <span>最近回复: <a href="{APP}{replierURI}">{replier}</a></span>'
+' <span>&#187; {replyDate}</span>'
+' {/reply}'
+' </div>'
+' </div>{/result}';
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, {"APP":BASE});
targetEleSelector.append(Mustache.render(T, rs));
};
//会员中心的点赞|收藏
tmp.drawMHomeAction = function(jsonArray){
var targetEleSelector = $('#member-home-actions');
targetEleSelector.find('.home-record-item').remove();
var cancelURI = targetEleSelector.attr('data-action') || '#';
var cancelCategory = targetEleSelector.attr('data-action-category')+'-topic' || null;
var obj = {};
obj.result = jsonArray;
var T ='{#result}'
+' <div class="home-record-item">'
+' <div class="record-item-body">'
+' <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
+' <span>操作日期: {actionDate}</span>'
+' </div>'
+' <div class="record-item-menu">'
+' <a class="action-cmd" role="button" href="javascript::" data-acctip="false" data-handler="{CU}" data-query="id:{id}" data-function="removeHomeCallbackFun" data-action="{MA}" data-action-key={AK}><i class="mdi mdi-delete"></i>&nbsp;删除</a>'
+' </div>'
+' </div>{/result}';
var extRS={
AK : function(){
var rs = this.link; // /topic/%s.xhtml | javascript:;
if(rs.indexOf('/') !== -1) {
return rs.substring(7, rs.length-6);
}
return null;
},
APP : BASE,
CU : cancelURI,
MA : cancelCategory
};
Mustache.parse(T, ['{', '}']);
var rs = $.extend(obj, extRS);
targetEleSelector.append(Mustache.render(T, rs));
};
//显示回复的点赞汇总结果
tmp.drawMoodResult = function(json){
if(jQuery.isEmptyObject(json.result)){
return;
}
$.each(json.result, function(index,item){
var pid = item.posts;
if(item.likes !== '0'){
$('#'+pid+'-likes').append('<span>'+item.likes+'</span>');
}
if(item.hates !== '0'){
$('#'+pid+'-hates').append('<span>'+item.hates+'</span>');
}
});
};
// 聊天页中的历史记录[NW][8]
tmp.drawLetterHistoryMessage = function(json, jqEle){
var T=''
+'<div class="media{#master} media-master{/master}" id="letter-{id}">'
+' <div class="media-avatar media-left">'
+' <a href="javascript:;">'
+' <img class="media-object img-circle" src="{APP}/member/avatar/{sender}.png" style="height:64px;width:64px;">'