Skip to content

Commit 19f0bbd

Browse files
committed
Extracted a pager control from slideshow and menugrid
1 parent c19c453 commit 19f0bbd

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

grid-spf/menugrid.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<script src="../ui/jquery.ui.position.js"></script>
1515
<script src="datasource.js"></script>
1616
<script src="grid.js"></script>
17+
<script src="pager.js"></script>
1718

1819
<script>
1920
$(function() {
@@ -91,6 +92,10 @@
9192
movies.option("filter", filters).refresh();
9293
});
9394

95+
$("#pager").pager({
96+
source: movies
97+
});
98+
return;
9499
var buttons = $("#pager").buttonset().find("button").click(function() {
95100
var method = $(this).data("page");
96101
movies[method]();

grid-spf/pager.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$.widget( "spf.pager", {
2+
options: {
3+
source: null,
4+
pageSize: 2
5+
},
6+
_create: function() {
7+
var that = this;
8+
9+
// TODO add a datasource method for this
10+
$( this.options.source ).bind( "datasourcerefresh", function() {
11+
that.refresh();
12+
});
13+
14+
this.buttons = this.element.delegate("button", "click", function() {
15+
var method = $(this).data("page");
16+
var source = that.options.source;
17+
source[method]();
18+
source.refresh();
19+
}).buttonset().find("button");
20+
},
21+
refresh: function() {
22+
this.buttons.button("enable");
23+
24+
var source = this.options.source;
25+
if (!source._skip) {
26+
this.buttons.slice(0, 2).button("disable")
27+
}
28+
if (source._skip + source._take >= source.totalCount) {
29+
this.buttons.slice(2, 4).button("disable")
30+
}
31+
}
32+
});

grid-spf/photoslideshow.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
<script src="../ui/jquery.ui.position.js"></script>
1313
<script src="../ui/jquery.ui.button.js"></script>
1414
<script src="datasource.js"></script>
15+
<script src="pager.js"></script>
1516
<script src="slideshow.js"></script>
16-
<script type="text/x-kite" id="controls-tmpl">
17+
<script type="text/x-kite" id="pager-tmpl">
1718
<div class="controls">
1819
<button data-page="first">First</button>
1920
<button data-page="prev">Prev</button>
@@ -52,6 +53,11 @@
5253
$( "#slideshow" ).slideshow({
5354
source: datasource
5455
});
56+
57+
$( kite( "#pager-tmpl" )() ).insertBefore( "#slideshow" ).pager({
58+
source: datasource
59+
})
60+
5561

5662
$( "#page-size" ).change(function() {
5763
datasource.option("paging", {
@@ -60,6 +66,8 @@
6066
skip: datasource._skip
6167
}).refresh();
6268
});
69+
70+
datasource.refresh();
6371
});
6472

6573
</script>

grid-spf/photoslideshow_remote.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<script src="../ui/jquery.ui.button.js"></script>
1414
<script src="datasource.js"></script>
1515
<script src="slideshow.js"></script>
16-
<script type="text/x-kite" id="controls-tmpl">
16+
<script src="pager.js"></script>
17+
<script type="text/x-kite" id="pager-tmpl">
1718
<div class="controls">
1819
<button data-page="first">First</button>
1920
<button data-page="prev">Prev</button>
2021
<button data-page="next">Next</button>
21-
<button data-page="last">Last</button>
2222
</div>
2323
</script>
2424
<script type="text/x-kite" id="photo-tmpl">
@@ -65,6 +65,10 @@
6565
$( "#slideshow" ).slideshow({
6666
source: datasource
6767
});
68+
69+
$( kite( "#pager-tmpl" )() ).insertBefore( "#slideshow" ).pager({
70+
source: datasource
71+
});
6872

6973
$( "#filter" ).change(function() {
7074
datasource.option("filter", {
@@ -79,6 +83,8 @@
7983
skip: datasource._skip
8084
}).refresh();
8185
});
86+
87+
datasource.refresh();
8288
});
8389

8490
</script>

grid-spf/slideshow.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ $.widget( "spf.slideshow", {
1010
$( this.options.source ).bind( "datasourcerefresh", function() {
1111
that.refresh();
1212
});
13-
14-
this.buttons = $( kite( "#controls-tmpl" )() ).insertBefore( this.element ).delegate("button", "click", function() {
15-
var method = $(this).data("page");
16-
var source = that.options.source;
17-
source[method]();
18-
source.refresh();
19-
}).buttonset().find("button");
20-
21-
this.options.source.refresh();
2213
},
2314
refresh: function() {
2415
var photosHtml = [];
@@ -30,15 +21,5 @@ $.widget( "spf.slideshow", {
3021

3122
this.element.empty();
3223
this.element.html( photosHtml.join("") );
33-
34-
this.buttons.button("enable");
35-
36-
var source = this.options.source;
37-
if (!source._skip) {
38-
this.buttons.slice(0, 2).button("disable")
39-
}
40-
if (source._skip + source._take >= source.totalCount) {
41-
this.buttons.slice(2, 4).button("disable")
42-
}
4324
}
4425
});

0 commit comments

Comments
 (0)