開發一個適合Ajax+JSON+jQuery環境使用的多功能頁碼欄——jPagerBar-1.1.1
阿新 • • 發佈:2019-01-23
{
var style = (attr["style"] ==null)?"technorati" : attr["style"];//class樣式
var totalCount =( attr["totalCount"]==null|| attr["totalCount"] ==0) ?0 : attr["totalCount"];;//parseInt()//總記錄條數
var pageCount = (attr["pageCount"] ==null|| attr["pageCount"] ==0) ?20 : attr["pageCount"];//attr["pageCount"];//每頁記錄數
var showPageNumber = (attr["showPageNumber"] ==null|| attr["showPageNumber"] ==0) ?20 : attr["showPageNumber"];//attr["showPageNumber"];//顯示頁碼數量
var currentPageIndex = attr["currentPageIndex"];//當前頁
var onclick = attr["onclick"];//onclick引數,如果包含“return false”,則連線轉為跳到barMark(暫留介面,其實return false後一般情況下href將失效。)
var barMark = attr["mark"];//onclick後跳轉到的<a name="barMark"></a>標籤
var noRecordTip = attr["noRecordTip"];//沒有記錄提示(支援HTML)
var preWord = (attr["preWord"] ==null)?" < " : attr["preWord"];//上一條記錄文字,預設為“ < ”
var nextWord = (attr["nextWord"] ==null)?" > " : attr["nextWord"];//下一條記錄文字,預設為“ > ”
//輸出設定
var barID = containerId +"_pageBar";
//var barDiv = $("#"+barID);
//新增PageBar層
$("#"+containerId).html("<div id=/"" + barID + "/" class=/"" + style + "/"></div>");
//輸出設定 結束
//如果沒有記錄,返回空記錄提示
if(totalCount==0)
{
$("#"+barID).html(noRecordTip);
returnfalse;
}
pageCount = (pageCount ==null|| pageCount ==0) ?20 : pageCount;//每頁顯示記錄數
var totalPage = parseInt((totalCount-1) / pageCount) +1;//總頁數
showPageNumber = (showPageNumber ==null|| showPageNumber ==0) ?3 : showPageNumber;
currentPageIndex = (currentPageIndex ==null|| currentPageIndex <=0|| currentPageIndex > totalPage) ?1 : currentPageIndex;
var backPageStyle = (currentPageIndex <=1) ?"disabled" : "";
var nextPageStyle = (currentPageIndex >= totalPage) ?"disabled" : "";
var firstDisplayPageEnd =0;//從第1頁顯示到xx頁
var bodyDisplayPageStart =0;//當前頁臨近最左頁碼
var bodyDisplayPageEnd =0;//當前頁臨近最右頁碼
var endDisplayPageStart =0;//從第xx頁顯示到最後一頁
//設定 bodyDisplayPageStart
bodyDisplayPageStart = (currentPageIndex - showPageNumber <=1) ?1 : currentPageIndex - showPageNumber; // (ViewData.pageIndex - ViewData.showPageNumber <= ViewData.showPageNumber) ? ViewData.showPageNumber + 1 : ViewData.pageIndex - ViewData.showPageNumber;
//設定 bodyDisplayPageEnd
bodyDisplayPageEnd = (currentPageIndex + showPageNumber >= totalPage) ? totalPage : currentPageIndex + showPageNumber;
//設定 firstDisplayPageEnd
if(bodyDisplayPageStart >1)
{
if(bodyDisplayPageStart - showPageNumber <=1)
firstDisplayPageEnd = bodyDisplayPageStart -1;
else
firstDisplayPageEnd = showPageNumber;
}
else
{
firstDisplayPageEnd =0;
}
//設定 endDisplayPageStart
if(bodyDisplayPageEnd < totalPage)
{
if(bodyDisplayPageEnd + showPageNumber >= totalPage)
endDisplayPageStart = bodyDisplayPageEnd +1;
else
endDisplayPageStart = totalPage - showPageNumber +1;
}
else
{
endDisplayPageStart = totalPage +1;
}
/******** 備用演算法 Start ********/
// //設定 firstDisplayPageEnd
// if (currentPageIndex - showPageNumber > 0 && bodyDisplayPageStart > currentPageIndex - showPageNumber)
// firstDisplayPageEnd = (showPageNumber >= totalPage) ? 0 : showPageNumber;
// else
// firstDisplayPageEnd = 0;
// //設定 endDisplayPageStart
// if (bodyDisplayPageEnd < totalPage)
// endDisplayPageStart = (bodyDisplayPageEnd + showPageNumber < totalPage) ? totalPage- showPageNumber + 1 : totalPage+1;
// else
// endDisplayPageStart = totalPage+1;
//
// //alert(bodyDisplayPageEnd +"<" +totalCount +"- "+showPageNumber);
// ////設定補充首尾
// if(bodyDisplayPageStart > 1 && firstDisplayPageEnd == 0)
// firstDisplayPageEnd = (bodyDisplayPageStart > showPageNumber)? showPageNumber : bodyDisplayPageStart - 1;
// if(bodyDisplayPageEnd < totalPage && endDisplayPageStart > totalPage)
// endDisplayPageStart = (bodyDisplayPageEnd < totalPage - showPageNumber)? totalCount - showPageNumber + 1 : bodyDisplayPageEnd + 1;//MS第一個判斷有點多餘 TNT2
/******** 備用演算法 End ********/
//頁面引數設定結束
//開始輸出
//alert($("#"+barID).html());
// 上一條
if(currentPageIndex <=1)
$("<span class=/"" + backPageStyle + "/">"+ preWord +"</span>").appendTo($("#"+barID));
else
$(GetPageLink(currentPageIndex-1,currentPageIndex,preWord,onclick,url,barMark)).appendTo($("#"+barID));
//first
for (var i =1; i <= firstDisplayPageEnd; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
//省略號
if (firstDisplayPageEnd +1< bodyDisplayPageStart)
$("<span> </span>").appendTo($("#"+barID));
//body
for (var i = bodyDisplayPageStart; i <= bodyDisplayPageEnd; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
//省略號
if (bodyDisplayPageEnd +1< endDisplayPageStart)
$("<span> </span>").appendTo($("#"+barID));
//end
for (var i = endDisplayPageStart; i <= totalPage; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
// >
if(currentPageIndex >= totalPage)
$("<span class=/"" + nextPageStyle + "/">"+ nextWord +"</span>").appendTo($("#"+barID));
else
$(GetPageLink(currentPageIndex +1 ,currentPageIndex,nextWord,onclick,url,barMark)).appendTo($("#"+barID));
//alert($("#"+barID).html());
}
var style = (attr["style"] ==null)?"technorati" : attr["style"];//class樣式
var totalCount =( attr["totalCount"]==null|| attr["totalCount"] ==0) ?0 : attr["totalCount"];;//parseInt()//總記錄條數
var pageCount = (attr["pageCount"] ==null|| attr["pageCount"] ==0) ?20 : attr["pageCount"];//attr["pageCount"];//每頁記錄數
var
var currentPageIndex = attr["currentPageIndex"];//當前頁
var onclick = attr["onclick"];//onclick引數,如果包含“return false”,則連線轉為跳到barMark(暫留介面,其實return false後一般情況下href將失效。)
var barMark
var noRecordTip = attr["noRecordTip"];//沒有記錄提示(支援HTML)
var preWord = (attr["preWord"] ==null)?" < " : attr["preWord"];//上一條記錄文字,預設為“ < ”
var nextWord = (attr["nextWord"] ==null)?" > " : attr["nextWord"];//下一條記錄文字,預設為“ > ”
//輸出設定
var
//var barDiv = $("#"+barID);
//新增PageBar層
$("#"+containerId).html("<div id=/"" + barID + "/" class=/"" + style + "/"></div>");
//輸出設定 結束
//如果沒有記錄,返回空記錄提示
if(totalCount==0)
{
$("#"+barID).html(noRecordTip);
returnfalse;
}
pageCount = (pageCount ==null|| pageCount ==0) ?20 : pageCount;//每頁顯示記錄數
var totalPage = parseInt((totalCount-1) / pageCount) +1;//總頁數
showPageNumber = (showPageNumber ==null|| showPageNumber ==0) ?3 : showPageNumber;
currentPageIndex = (currentPageIndex ==null|| currentPageIndex <=0|| currentPageIndex > totalPage) ?1 : currentPageIndex;
var backPageStyle = (currentPageIndex <=1) ?"disabled" : "";
var nextPageStyle = (currentPageIndex >= totalPage) ?"disabled" : "";
var firstDisplayPageEnd =0;//從第1頁顯示到xx頁
var bodyDisplayPageStart =0;//當前頁臨近最左頁碼
var bodyDisplayPageEnd =0;//當前頁臨近最右頁碼
var endDisplayPageStart =0;//從第xx頁顯示到最後一頁
//設定 bodyDisplayPageStart
bodyDisplayPageStart = (currentPageIndex - showPageNumber <=1) ?1 : currentPageIndex - showPageNumber; // (ViewData.pageIndex - ViewData.showPageNumber <= ViewData.showPageNumber) ? ViewData.showPageNumber + 1 : ViewData.pageIndex - ViewData.showPageNumber;
//設定 bodyDisplayPageEnd
bodyDisplayPageEnd = (currentPageIndex + showPageNumber >= totalPage) ? totalPage : currentPageIndex + showPageNumber;
//設定 firstDisplayPageEnd
if(bodyDisplayPageStart >1)
{
if(bodyDisplayPageStart - showPageNumber <=1)
firstDisplayPageEnd = bodyDisplayPageStart -1;
else
firstDisplayPageEnd = showPageNumber;
}
else
{
firstDisplayPageEnd =0;
}
//設定 endDisplayPageStart
if(bodyDisplayPageEnd < totalPage)
{
if(bodyDisplayPageEnd + showPageNumber >= totalPage)
endDisplayPageStart = bodyDisplayPageEnd +1;
else
endDisplayPageStart = totalPage - showPageNumber +1;
}
else
{
endDisplayPageStart = totalPage +1;
}
/******** 備用演算法 Start ********/
// //設定 firstDisplayPageEnd
// if (currentPageIndex - showPageNumber > 0 && bodyDisplayPageStart > currentPageIndex - showPageNumber)
// firstDisplayPageEnd = (showPageNumber >= totalPage) ? 0 : showPageNumber;
// else
// firstDisplayPageEnd = 0;
// //設定 endDisplayPageStart
// if (bodyDisplayPageEnd < totalPage)
// endDisplayPageStart = (bodyDisplayPageEnd + showPageNumber < totalPage) ? totalPage- showPageNumber + 1 : totalPage+1;
// else
// endDisplayPageStart = totalPage+1;
//
// //alert(bodyDisplayPageEnd +"<" +totalCount +"- "+showPageNumber);
// ////設定補充首尾
// if(bodyDisplayPageStart > 1 && firstDisplayPageEnd == 0)
// firstDisplayPageEnd = (bodyDisplayPageStart > showPageNumber)? showPageNumber : bodyDisplayPageStart - 1;
// if(bodyDisplayPageEnd < totalPage && endDisplayPageStart > totalPage)
// endDisplayPageStart = (bodyDisplayPageEnd < totalPage - showPageNumber)? totalCount - showPageNumber + 1 : bodyDisplayPageEnd + 1;//MS第一個判斷有點多餘 TNT2
/******** 備用演算法 End ********/
//頁面引數設定結束
//開始輸出
//alert($("#"+barID).html());
// 上一條
if(currentPageIndex <=1)
$("<span class=/"" + backPageStyle + "/">"+ preWord +"</span>").appendTo($("#"+barID));
else
$(GetPageLink(currentPageIndex-1,currentPageIndex,preWord,onclick,url,barMark)).appendTo($("#"+barID));
//first
for (var i =1; i <= firstDisplayPageEnd; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
//省略號
if (firstDisplayPageEnd +1< bodyDisplayPageStart)
$("<span> </span>").appendTo($("#"+barID));
//body
for (var i = bodyDisplayPageStart; i <= bodyDisplayPageEnd; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
//省略號
if (bodyDisplayPageEnd +1< endDisplayPageStart)
$("<span> </span>").appendTo($("#"+barID));
//end
for (var i = endDisplayPageStart; i <= totalPage; i++)
$(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
// >
if(currentPageIndex >= totalPage)
$("<span class=/"" + nextPageStyle + "/">"+ nextWord +"</span>").appendTo($("#"+barID));
else
$(GetPageLink(currentPageIndex +1 ,currentPageIndex,nextWord,onclick,url,barMark)).appendTo($("#"+barID));
//alert($("#"+barID).html());
}