Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
paginationjs
提交
8dd6a9f4
P
paginationjs
项目概览
爱吃血肠
/
paginationjs
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
paginationjs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8dd6a9f4
编写于
1月 21, 2018
作者:
L
Leon Shi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support to access to the pagination info when formatting navigator/input/button
上级
71e7248c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
42 deletion
+43
-42
src/pagination.js
src/pagination.js
+43
-42
未找到文件。
src/pagination.js
浏览文件 @
8dd6a9f4
...
@@ -56,7 +56,7 @@
...
@@ -56,7 +56,7 @@
// Whether to disable Pagination at the initialization
// Whether to disable Pagination at the initialization
self
.
disabled
=
!!
attributes
.
disabled
;
self
.
disabled
=
!!
attributes
.
disabled
;
//
W
ill be passed to the callback function
//
Model w
ill be passed to the callback function
var
model
=
self
.
model
=
{
var
model
=
self
.
model
=
{
pageRange
:
attributes
.
pageRange
,
pageRange
:
attributes
.
pageRange
,
pageSize
:
attributes
.
pageSize
pageSize
:
attributes
.
pageSize
...
@@ -65,36 +65,36 @@
...
@@ -65,36 +65,36 @@
// dataSource`s type is unknown, parse it to find true data
// dataSource`s type is unknown, parse it to find true data
self
.
parseDataSource
(
attributes
.
dataSource
,
function
(
dataSource
)
{
self
.
parseDataSource
(
attributes
.
dataSource
,
function
(
dataSource
)
{
//
is async
mode
//
Currently in asynchronous
mode
self
.
isAsync
=
Helpers
.
isString
(
dataSource
);
self
.
isAsync
=
Helpers
.
isString
(
dataSource
);
if
(
Helpers
.
isArray
(
dataSource
))
{
if
(
Helpers
.
isArray
(
dataSource
))
{
model
.
totalNumber
=
attributes
.
totalNumber
=
dataSource
.
length
;
model
.
totalNumber
=
attributes
.
totalNumber
=
dataSource
.
length
;
}
}
//
in async mode and specified totalNumber locator
//
Currently in asynchronous mode and a totalNumberLocator is specified
self
.
isDynamicTotalNumber
=
self
.
isAsync
&&
attributes
.
totalNumberLocator
;
self
.
isDynamicTotalNumber
=
self
.
isAsync
&&
attributes
.
totalNumberLocator
;
//
Have
only one page
//
There is
only one page
if
(
attributes
.
hideWhenLessThanOnePage
)
{
if
(
attributes
.
hideWhenLessThanOnePage
)
{
if
(
self
.
getTotalPage
()
<=
1
)
return
;
if
(
self
.
getTotalPage
()
<=
1
)
return
;
}
}
var
el
=
self
.
render
(
true
);
var
el
=
self
.
render
(
true
);
// Add extra className
// Add extra className
to the pagination element
if
(
attributes
.
className
)
{
if
(
attributes
.
className
)
{
el
.
addClass
(
attributes
.
className
);
el
.
addClass
(
attributes
.
className
);
}
}
model
.
el
=
el
;
model
.
el
=
el
;
// Append
pagination element to
container
// Append
/prepend pagination element to the
container
container
[
attributes
.
position
===
'
bottom
'
?
'
append
'
:
'
prepend
'
](
el
);
container
[
attributes
.
position
===
'
bottom
'
?
'
append
'
:
'
prepend
'
](
el
);
// Bind events
// Bind events
self
.
observer
();
self
.
observer
();
//
Add initialization flag
//
Pagination is currently initialized
container
.
data
(
'
pagination
'
).
initialized
=
true
;
container
.
data
(
'
pagination
'
).
initialized
=
true
;
// Will be invoked after initialized
// Will be invoked after initialized
...
@@ -128,7 +128,7 @@
...
@@ -128,7 +128,7 @@
rangeEnd
=
Math
.
min
(
pageRange
*
2
+
1
,
totalPage
);
rangeEnd
=
Math
.
min
(
pageRange
*
2
+
1
,
totalPage
);
}
}
el
.
html
(
self
.
createTemplate
({
el
.
html
(
self
.
generateHTML
({
currentPage
:
currentPage
,
currentPage
:
currentPage
,
pageRange
:
pageRange
,
pageRange
:
pageRange
,
rangeStart
:
rangeStart
,
rangeStart
:
rangeStart
,
...
@@ -140,8 +140,8 @@
...
@@ -140,8 +140,8 @@
return
el
;
return
el
;
},
},
//
Creat
e template
//
Generate HTML content from th
e template
createTemplate
:
function
(
args
)
{
generateHTML
:
function
(
args
)
{
var
self
=
this
;
var
self
=
this
;
var
currentPage
=
args
.
currentPage
;
var
currentPage
=
args
.
currentPage
;
var
totalPage
=
self
.
getTotalPage
();
var
totalPage
=
self
.
getTotalPage
();
...
@@ -168,22 +168,23 @@
...
@@ -168,22 +168,23 @@
var
disableClassName
=
attributes
.
disableClassName
;
var
disableClassName
=
attributes
.
disableClassName
;
var
ulClassName
=
attributes
.
ulClassName
;
var
ulClassName
=
attributes
.
ulClassName
;
var
formatNavigator
=
$
.
isFunction
(
attributes
.
formatNavigator
)
?
attributes
.
formatNavigator
()
:
attributes
.
formatNavigator
;
var
formatGoInput
=
$
.
isFunction
(
attributes
.
formatGoInput
)
?
attributes
.
formatGoInput
()
:
attributes
.
formatGoInput
;
var
formatGoButton
=
$
.
isFunction
(
attributes
.
formatGoButton
)
?
attributes
.
formatGoButton
()
:
attributes
.
formatGoButton
;
var
autoHidePrevious
=
$
.
isFunction
(
attributes
.
autoHidePrevious
)
?
attributes
.
autoHidePrevious
()
:
attributes
.
autoHidePrevious
;
var
autoHideNext
=
$
.
isFunction
(
attributes
.
autoHideNext
)
?
attributes
.
autoHideNext
()
:
attributes
.
autoHideNext
;
var
header
=
$
.
isFunction
(
attributes
.
header
)
?
attributes
.
header
()
:
attributes
.
header
;
var
footer
=
$
.
isFunction
(
attributes
.
footer
)
?
attributes
.
footer
()
:
attributes
.
footer
;
var
html
=
''
;
var
html
=
''
;
var
goInput
=
'
<input type="text" class="J-paginationjs-go-pagenumber">
'
;
var
goInput
=
'
<input type="text" class="J-paginationjs-go-pagenumber">
'
;
var
goButton
=
'
<input type="button" class="J-paginationjs-go-button" value="
'
+
goButtonText
+
'
">
'
;
var
goButton
=
'
<input type="button" class="J-paginationjs-go-button" value="
'
+
goButtonText
+
'
">
'
;
var
formattedString
;
var
formattedString
;
var
i
;
var
i
;
var
formatNavigator
=
$
.
isFunction
(
attributes
.
formatNavigator
)
?
attributes
.
formatNavigator
(
currentPage
,
totalPage
,
totalNumber
)
:
attributes
.
formatNavigator
;
var
formatGoInput
=
$
.
isFunction
(
attributes
.
formatGoInput
)
?
attributes
.
formatGoInput
(
goInput
,
currentPage
,
totalPage
,
totalNumber
)
:
attributes
.
formatGoInput
;
var
formatGoButton
=
$
.
isFunction
(
attributes
.
formatGoButton
)
?
attributes
.
formatGoButton
(
goButton
,
currentPage
,
totalPage
,
totalNumber
)
:
attributes
.
formatGoButton
;
var
autoHidePrevious
=
$
.
isFunction
(
attributes
.
autoHidePrevious
)
?
attributes
.
autoHidePrevious
()
:
attributes
.
autoHidePrevious
;
var
autoHideNext
=
$
.
isFunction
(
attributes
.
autoHideNext
)
?
attributes
.
autoHideNext
()
:
attributes
.
autoHideNext
;
var
header
=
$
.
isFunction
(
attributes
.
header
)
?
attributes
.
header
(
currentPage
,
totalPage
,
totalNumber
)
:
attributes
.
header
;
var
footer
=
$
.
isFunction
(
attributes
.
footer
)
?
attributes
.
footer
(
currentPage
,
totalPage
,
totalNumber
)
:
attributes
.
footer
;
// Whether to display header
if
(
header
)
{
if
(
header
)
{
formattedString
=
self
.
replaceVariables
(
header
,
{
formattedString
=
self
.
replaceVariables
(
header
,
{
currentPage
:
currentPage
,
currentPage
:
currentPage
,
...
@@ -202,7 +203,7 @@
...
@@ -202,7 +203,7 @@
html
+=
'
<ul>
'
;
html
+=
'
<ul>
'
;
}
}
//
Previous page
button
//
Whether to display the Previous
button
if
(
showPrevious
)
{
if
(
showPrevious
)
{
if
(
currentPage
<=
1
)
{
if
(
currentPage
<=
1
)
{
if
(
!
autoHidePrevious
)
{
if
(
!
autoHidePrevious
)
{
...
@@ -213,7 +214,7 @@
...
@@ -213,7 +214,7 @@
}
}
}
}
//
Page number
s
//
Whether to display the page
s
if
(
showPageNumbers
)
{
if
(
showPageNumbers
)
{
if
(
rangeStart
<=
3
)
{
if
(
rangeStart
<=
3
)
{
for
(
i
=
1
;
i
<
rangeStart
;
i
++
)
{
for
(
i
=
1
;
i
<
rangeStart
;
i
++
)
{
...
@@ -230,7 +231,6 @@
...
@@ -230,7 +231,6 @@
html
+=
'
<li class="
'
+
classPrefix
+
'
-ellipsis
'
+
disableClassName
+
'
"><a>
'
+
ellipsisText
+
'
<
\
/a><
\
/li>
'
;
html
+=
'
<li class="
'
+
classPrefix
+
'
-ellipsis
'
+
disableClassName
+
'
"><a>
'
+
ellipsisText
+
'
<
\
/a><
\
/li>
'
;
}
}
// Main loop
for
(
i
=
rangeStart
;
i
<=
rangeEnd
;
i
++
)
{
for
(
i
=
rangeStart
;
i
<=
rangeEnd
;
i
++
)
{
if
(
i
==
currentPage
)
{
if
(
i
==
currentPage
)
{
html
+=
'
<li class="
'
+
classPrefix
+
'
-page J-paginationjs-page
'
+
activeClassName
+
'
" data-num="
'
+
i
+
'
"><a>
'
+
i
+
'
<
\
/a><
\
/li>
'
;
html
+=
'
<li class="
'
+
classPrefix
+
'
-page J-paginationjs-page
'
+
activeClassName
+
'
" data-num="
'
+
i
+
'
"><a>
'
+
i
+
'
<
\
/a><
\
/li>
'
;
...
@@ -252,7 +252,7 @@
...
@@ -252,7 +252,7 @@
}
}
}
}
//
Next page
button
//
Whether to display the Next
button
if
(
showNext
)
{
if
(
showNext
)
{
if
(
currentPage
>=
totalPage
)
{
if
(
currentPage
>=
totalPage
)
{
if
(
!
autoHideNext
)
{
if
(
!
autoHideNext
)
{
...
@@ -265,7 +265,7 @@
...
@@ -265,7 +265,7 @@
html
+=
'
<
\
/ul><
\
/div>
'
;
html
+=
'
<
\
/ul><
\
/div>
'
;
}
}
//
N
avigator
//
Whether to display the n
avigator
if
(
showNavigator
)
{
if
(
showNavigator
)
{
if
(
formatNavigator
)
{
if
(
formatNavigator
)
{
formattedString
=
self
.
replaceVariables
(
formatNavigator
,
{
formattedString
=
self
.
replaceVariables
(
formatNavigator
,
{
...
@@ -277,7 +277,7 @@
...
@@ -277,7 +277,7 @@
}
}
}
}
// Go input
//
Whether to display the
Go input
if
(
showGoInput
)
{
if
(
showGoInput
)
{
if
(
formatGoInput
)
{
if
(
formatGoInput
)
{
formattedString
=
self
.
replaceVariables
(
formatGoInput
,
{
formattedString
=
self
.
replaceVariables
(
formatGoInput
,
{
...
@@ -290,7 +290,7 @@
...
@@ -290,7 +290,7 @@
}
}
}
}
// Go button
//
Whether to display the
Go button
if
(
showGoButton
)
{
if
(
showGoButton
)
{
if
(
formatGoButton
)
{
if
(
formatGoButton
)
{
formattedString
=
self
.
replaceVariables
(
formatGoButton
,
{
formattedString
=
self
.
replaceVariables
(
formatGoButton
,
{
...
@@ -303,6 +303,7 @@
...
@@ -303,6 +303,7 @@
}
}
}
}
// Whether to display footer
if
(
footer
)
{
if
(
footer
)
{
formattedString
=
self
.
replaceVariables
(
footer
,
{
formattedString
=
self
.
replaceVariables
(
footer
,
{
currentPage
:
currentPage
,
currentPage
:
currentPage
,
...
@@ -315,14 +316,14 @@
...
@@ -315,14 +316,14 @@
return
html
;
return
html
;
},
},
// Find t
he totalNumber from
remote response
// Find t
otalNumber from the
remote response
// Only available in async mode
// Only available in async
hronous
mode
findTotalNumberFromRemoteResponse
:
function
(
response
)
{
findTotalNumberFromRemoteResponse
:
function
(
response
)
{
var
self
=
this
;
var
self
=
this
;
self
.
model
.
totalNumber
=
attributes
.
totalNumberLocator
(
response
);
self
.
model
.
totalNumber
=
attributes
.
totalNumberLocator
(
response
);
},
},
// Go to specified page
// Go to
the
specified page
go
:
function
(
number
,
callback
)
{
go
:
function
(
number
,
callback
)
{
var
self
=
this
;
var
self
=
this
;
var
model
=
self
.
model
;
var
model
=
self
.
model
;
...
@@ -347,7 +348,7 @@
...
@@ -347,7 +348,7 @@
// There is no data
// There is no data
if
(
totalNumber
===
0
)
return
;
if
(
totalNumber
===
0
)
return
;
// Pick data fragment in sync mode
// Pick data fragment in sync
hronous
mode
if
(
!
self
.
isAsync
)
{
if
(
!
self
.
isAsync
)
{
render
(
self
.
getDataFragment
(
pageNumber
));
render
(
self
.
getDataFragment
(
pageNumber
));
return
;
return
;
...
@@ -401,14 +402,14 @@
...
@@ -401,14 +402,14 @@
self
.
render
();
self
.
render
();
if
(
self
.
disabled
&&
self
.
isAsync
)
{
if
(
self
.
disabled
&&
self
.
isAsync
)
{
// enable
// enable
pagination
self
.
enable
();
self
.
enable
();
}
}
// cache model data
// cache model data
container
.
data
(
'
pagination
'
).
model
=
model
;
container
.
data
(
'
pagination
'
).
model
=
model
;
// format result data before callback
execut
ed
// format result data before callback
invok
ed
if
(
attributes
.
formatResult
)
{
if
(
attributes
.
formatResult
)
{
var
cloneData
=
$
.
extend
(
true
,
[],
data
);
var
cloneData
=
$
.
extend
(
true
,
[],
data
);
if
(
!
Helpers
.
isArray
(
data
=
attributes
.
formatResult
(
cloneData
)))
{
if
(
!
Helpers
.
isArray
(
data
=
attributes
.
formatResult
(
cloneData
)))
{
...
@@ -418,7 +419,7 @@
...
@@ -418,7 +419,7 @@
container
.
data
(
'
pagination
'
).
currentPageData
=
data
;
container
.
data
(
'
pagination
'
).
currentPageData
=
data
;
// callback
//
invoke
callback
self
.
doCallback
(
data
,
callback
);
self
.
doCallback
(
data
,
callback
);
self
.
callHook
(
'
afterPaging
'
,
pageNumber
);
self
.
callHook
(
'
afterPaging
'
,
pageNumber
);
...
@@ -456,7 +457,7 @@
...
@@ -456,7 +457,7 @@
// Remove style element
// Remove style element
$
(
'
#paginationjs-style
'
).
remove
();
$
(
'
#paginationjs-style
'
).
remove
();
// After destroy
// After destroy
ed
this
.
callHook
(
'
afterDestroy
'
);
this
.
callHook
(
'
afterDestroy
'
);
},
},
...
@@ -472,13 +473,13 @@
...
@@ -472,13 +473,13 @@
var
self
=
this
;
var
self
=
this
;
var
source
=
self
.
isAsync
?
'
async
'
:
'
sync
'
;
var
source
=
self
.
isAsync
?
'
async
'
:
'
sync
'
;
// Before disabl
ing
// Before disabl
ed
if
(
self
.
callHook
(
'
beforeDisable
'
,
source
)
===
false
)
return
;
if
(
self
.
callHook
(
'
beforeDisable
'
,
source
)
===
false
)
return
;
self
.
disabled
=
true
;
self
.
disabled
=
true
;
self
.
model
.
disabled
=
true
;
self
.
model
.
disabled
=
true
;
// After disabl
ing
// After disabl
ed
self
.
callHook
(
'
afterDisable
'
,
source
);
self
.
callHook
(
'
afterDisable
'
,
source
);
},
},
...
@@ -486,13 +487,13 @@
...
@@ -486,13 +487,13 @@
var
self
=
this
;
var
self
=
this
;
var
source
=
self
.
isAsync
?
'
async
'
:
'
sync
'
;
var
source
=
self
.
isAsync
?
'
async
'
:
'
sync
'
;
// Before enabl
ing
// Before enabl
ed
if
(
self
.
callHook
(
'
beforeEnable
'
,
source
)
===
false
)
return
;
if
(
self
.
callHook
(
'
beforeEnable
'
,
source
)
===
false
)
return
;
self
.
disabled
=
false
;
self
.
disabled
=
false
;
self
.
model
.
disabled
=
false
;
self
.
model
.
disabled
=
false
;
// After enabl
ing
// After enabl
ed
self
.
callHook
(
'
afterEnable
'
,
source
);
self
.
callHook
(
'
afterEnable
'
,
source
);
},
},
...
@@ -516,7 +517,7 @@
...
@@ -516,7 +517,7 @@
self
.
model
.
el
.
hide
();
self
.
model
.
el
.
hide
();
},
},
// Parse variables in template
// Parse variables in t
he t
emplate
replaceVariables
:
function
(
template
,
variables
)
{
replaceVariables
:
function
(
template
,
variables
)
{
var
formattedString
;
var
formattedString
;
...
@@ -572,7 +573,7 @@
...
@@ -572,7 +573,7 @@
var
locator
=
this
.
getLocator
(
attributes
.
locator
);
var
locator
=
this
.
getLocator
(
attributes
.
locator
);
var
filteredData
;
var
filteredData
;
// Data
source is an Object, use "locator" to locate the true data
// Datasource is an Object, use "locator" to locate the true data
if
(
Helpers
.
isObject
(
dataSource
))
{
if
(
Helpers
.
isObject
(
dataSource
))
{
try
{
try
{
$
.
each
(
locator
.
split
(
'
.
'
),
function
(
index
,
item
)
{
$
.
each
(
locator
.
split
(
'
.
'
),
function
(
index
,
item
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录