如果你只想下載現成的用,可以到這個頁面上去找。
許可證是“WTFPL”,也就是“Do What The Fuck You Want To Public License”。
源代碼如下(因為有注釋,就不另外說明了):
復制代碼 代碼如下:
public static class PageNumExt
{
/// <summary>
/// 使用傳入的委托計算並產生友好的頁碼。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
public static void PageNumView(this object o,
long currentPage, PageNumAction actionPageNum, Action actionFolding,
long maxSiblings = 2, long preventFolding = 1)
{
o.PageNumView(currentPage, actionPageNum, actionPageNum, actionFolding, maxSiblings, preventFolding);
}
/// <summary>
/// 使用傳入的委托計算並產生友好的頁碼。當前頁碼將會被特別對待。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
public static void PageNumView(this object o,
long currentPage, PageNumAction actionCurrent,
PageNumAction actionPageNum, Action actionFolding,
long maxSiblings = 2, long preventFolding = 1)
{
o.PageNumView(
currentPage, actionCurrent,
1, long.MaxValue,
actionPageNum, i => { },
maxSiblings, actionPageNum,
preventFolding, actionFolding,
maxSiblings, 0,
actionPageNum, i => { }
);
}
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。當前頁碼將會被特別對待。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
public static void PageNumView(this object o,
long currentPage, PageNumAction actionCurrent,
long beginPage, long endPage,
PageNumAction actionPageNum, Action actionFolding,
long maxSiblings = 2, long preventFolding = 1)
{
o.PageNumView(currentPage, actionCurrent, beginPage, endPage, actionPageNum, actionPageNum, actionPageNum, actionFolding, maxSiblings, preventFolding);
}
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。當前頁碼、起始頁碼和終止頁碼都指定了專用的委托來處理。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionBegin">處理起始頁碼的方式</param>
/// <param name="actionEnd">處理結束頁碼的方式</param>
/// <param name="actionSebling">處理臨近頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
public static void PageNumView(this object o,
long currentPage, PageNumAction actionCurrent,
long beginPage, long endPage,
PageNumAction actionBegin, PageNumAction actionEnd,
PageNumAction actionSebling, Action actionFolding,
long maxSiblings = 2, long preventFolding = 1)
{
o.PageNumView(
currentPage, actionCurrent,
beginPage, endPage,
actionBegin, actionEnd,
maxSiblings, actionSebling,
preventFolding, actionFolding,
maxSiblings, maxSiblings,
actionSebling, actionSebling
);
}
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。每一種頁碼的具體處理方式都需要由調用方指派委托。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionBegin">處理起始頁碼的方式</param>
/// <param name="actionEnd">處理結束頁碼的方式</param>
/// <param name="currentSiblings">當前頁碼的臨近頁碼數量</param>
/// <param name="actionCurrentSibling">處理臨近頁碼的方式</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="endOfBegin">起始頁臨近頁碼的數量</param>
/// <param name="beginOfEnd">結束頁臨近頁碼的數量</param>
/// <param name="actionBeginSibling">處理起始頁臨近頁碼的方式</param>
/// <param name="actionEndSibling">處理結束頁臨近頁碼的方式</param>
public static void PageNumView(this object o,
long currentPage, PageNumAction actionCurrent,
long beginPage, long endPage,
PageNumAction actionBegin, PageNumAction actionEnd,
long currentSiblings, PageNumAction actionCurrentSibling,
long preventFolding, Action actionFolding,
long endOfBegin, long beginOfEnd,
PageNumAction actionBeginSibling, PageNumAction actionEndSibling
)
{
long i = beginPage;
// 如果起始頁小於當前頁,就開始處理起始頁
if (beginPage < currentPage)
#region
{
actionBegin(beginPage);
i++;
endOfBegin += i; // 解決靠近起始頁的頁碼之後
var siblingBegin = currentPage - currentSiblings; // 當前頁的臨近頁從何處開始
var foldingStart = siblingBegin - preventFolding; // 頁碼折疊的底線
if (endOfBegin > siblingBegin)
endOfBegin = siblingBegin; // 保證當前頁的臨近頁,犧牲起始頁的臨近頁
for (; i < endOfBegin; i++)
actionBeginSibling(i);
if (i < foldingStart) // 如果還沒到達折疊底線,就馬上開始折疊
{
actionFolding();
i = foldingStart + 1; // 跳到折疊之後的頁碼
}
}
#endregion
// 處理當前頁之前的臨近頁
for (; i < currentPage; i++)
actionCurrentSibling(i);
// 處理當前頁
actionCurrent(currentPage);
i = currentPage + 1; // 表示當前頁已經處理完成。
// 由於不能保證當前頁和期望的起始頁的關系,所以在此從當前頁開始計算。
var goal = i + currentSiblings; // 設定一個目標
if (goal > endPage) // 目標不要超過結束頁
goal = endPage;
// 處理當前頁之後的臨近頁,直到到達目標頁為止
for (; i < goal; i++)
actionCurrentSibling(i);
// 如果結束頁大於當前頁,就開始處理結束頁
if (endPage > currentPage)
#region
{
beginOfEnd = endPage - beginOfEnd; // 計算出結束頁的臨近頁從何處開始
var foldingStart = beginOfEnd - preventFolding;
if (i < foldingStart) // 沒有觸及折疊底線,馬上開始折疊
{
actionFolding();
i = beginOfEnd;
}
else // 全部當作當前頁的臨近頁來處理,但保留結束頁的臨近頁
for (; i < beginOfEnd; i++)
actionCurrentSibling(i);
for (; i < endPage; i++)
actionEndSibling(i);
actionEnd(endPage);
}
#endregion
}
}
JavaScript版的源代碼可以直接在前面提到的頁面下載,不過這裡也列出一下:
復制代碼 代碼如下:
!function () {
var g = this;
var def_maxSiblings = 2;
var def_preventFolding = 1;
function pnView1(
currentPage, actionPageNum, actionFolding,
maxSiblings, preventFolding
) {
/// <summary>
/// 使用傳入的委托計算並產生友好的頁碼。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
pnView2(currentPage, actionPageNum, actionPageNum, actionFolding, maxSiblings || def_maxSiblings, preventFolding || def_preventFolding);
}
function pnView2(
currentPage, actionCurrent,
actionPageNum, actionFolding,
maxSiblings, preventFolding
) {
/// <summary>
/// 使用傳入的委托計算並產生友好的頁碼。當前頁碼將會被特別對待。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
pnView(
currentPage, actionCurrent,
1, Number.POSITIVE_INFINITY,
actionPageNum, null,
maxSiblings || def_maxSiblings, actionPageNum,
preventFolding || def_preventFolding, actionFolding,
maxSiblings || def_maxSiblings, 0,
actionPageNum, null
);
}
function pnView3(
currentPage, actionCurrent,
beginPage, endPage,
actionPageNum, actionFolding,
maxSiblings, preventFolding
) {
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。當前頁碼將會被特別對待。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionPageNum">處理頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
pnView4(currentPage, actionCurrent, beginPage, endPage, actionPageNum, actionPageNum, actionPageNum, actionFolding, maxSiblings || def_maxSiblings, preventFolding || def_preventFolding);
}
function pnView4(
currentPage, actionCurrent,
beginPage, endPage,
actionBegin, actionEnd,
actionSebling, actionFolding,
maxSiblings, preventFolding
) {
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。當前頁碼、起始頁碼和終止頁碼都指定了專用的委托來處理。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionBegin">處理起始頁碼的方式</param>
/// <param name="actionEnd">處理結束頁碼的方式</param>
/// <param name="actionSebling">處理臨近頁碼的方式</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="maxSiblings">臨近頁碼的數量</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
pnView(
currentPage, actionCurrent,
beginPage, endPage,
actionBegin, actionEnd,
maxSiblings || def_maxSiblings, actionSebling,
preventFolding || def_preventFolding, actionFolding,
maxSiblings || def_maxSiblings, maxSiblings || def_maxSiblings,
actionSebling, actionSebling
);
}
function pnView(
currentPage, actionCurrent,
beginPage, endPage,
actionBegin, actionEnd,
currentSiblings, actionCurrentSibling,
preventFolding, actionFolding,
endOfBegin, beginOfEnd,
actionBeginSibling, actionEndSibling
) {
/// <summary>
/// 根據傳入的參數和委托來計算並產生友好的頁碼。每一種頁碼的具體處理方式都需要由調用方指派委托。
/// </summary>
/// <param name="o"></param>
/// <param name="currentPage">當前頁碼</param>
/// <param name="actionCurrent">處理當前頁碼的方式</param>
/// <param name="beginPage">預設的起始頁碼</param>
/// <param name="endPage">預設的結束頁碼</param>
/// <param name="actionBegin">處理起始頁碼的方式</param>
/// <param name="actionEnd">處理結束頁碼的方式</param>
/// <param name="currentSiblings">當前頁碼的臨近頁碼數量</param>
/// <param name="actionCurrentSibling">處理臨近頁碼的方式</param>
/// <param name="preventFolding">阻止折疊頁碼的臨界值,超過這個數目的頁碼將會被折疊</param>
/// <param name="actionFolding">處理被折疊頁碼的方式</param>
/// <param name="endOfBegin">起始頁臨近頁碼的數量</param>
/// <param name="beginOfEnd">結束頁臨近頁碼的數量</param>
/// <param name="actionBeginSibling">處理起始頁臨近頁碼的方式</param>
/// <param name="actionEndSibling">處理結束頁臨近頁碼的方式</param>
var i = beginPage;
// 如果起始頁小於當前頁,就開始處理起始頁
if (beginPage < currentPage) {
actionBegin && actionBegin(beginPage);
i++;
endOfBegin += i; // 解決靠近起始頁的頁碼之後
var siblingBegin = currentPage - currentSiblings; // 當前頁的臨近頁從何處開始
var foldingStart = siblingBegin - preventFolding; // 頁碼折疊的底線
if (endOfBegin > siblingBegin)
endOfBegin = siblingBegin; // 保證當前頁的臨近頁,犧牲起始頁的臨近頁
for (; i < endOfBegin; i++)
actionBeginSibling && actionBeginSibling(i);
if (i < foldingStart) // 如果還沒到達折疊底線,就馬上開始折疊
{
actionFolding && actionFolding();
i = foldingStart + 1; // 跳到折疊之後的頁碼
}
}
// 處理當前頁之前的臨近頁
for (; i < currentPage; i++)
actionCurrentSibling && actionCurrentSibling(i);
// 處理當前頁
actionCurrent && actionCurrent(currentPage);
i = currentPage + 1; // 表示當前頁已經處理完成。
// 由於不能保證當前頁和期望的起始頁的關系,所以在此從當前頁開始計算。
var goal = i + currentSiblings; // 設定一個目標
if (goal > endPage) // 目標不要超過結束頁
goal = endPage;
// 處理當前頁之後的臨近頁,直到到達目標頁為止
for (; i < goal; i++)
actionCurrentSibling && actionCurrentSibling(i);
// 如果結束頁大於當前頁,就開始處理結束頁
if (endPage > currentPage) {
beginOfEnd = endPage - beginOfEnd; // 計算出結束頁的臨近頁從何處開始
var foldingStart = beginOfEnd - preventFolding;
if (i < foldingStart) // 沒有觸及折疊底線,馬上開始折疊
{
actionFolding && actionFolding();
i = beginOfEnd;
}
else // 全部當作當前頁的臨近頁來處理,但保留結束頁的臨近頁
{
for (; i < beginOfEnd; i++)
actionCurrentSibling && actionCurrentSibling(i);
}
for (; i < endPage; i++)
actionEndSibling && actionEndSibling(i);
actionEnd && actionEnd(endPage);
}
}
g.pnView1 = pnView1;
g.pnView2 = pnView2;
g.pnView3 = pnView3;
g.pnView4 = pnView4;
g.pnView5 = pnView;
g.pnView = pnView;
} ();
/201009/yuanma/pnView_NanaView.rar