root/trunk/paginationview.js

Revision 38, 1.4 kB (checked in by mischa, 4 years ago)

Move some of my nifty javascript libraries into wcmtools to share between lj and fb

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1// a view to provide pagination controls for a paginated datasource
2PaginationView = new Class(View, {
3
4  init: function () {
5    PaginationView.superClass.init.apply(this, arguments);
6  },
7
8  render: function (data) {
9    var datasource = this.datasource;
10
11    if (!datasource || !datasource.isPaginated)
12      return;
13
14    var view = this.view;
15    view.innerHTML = "";
16
17    var paginationControls = document.createElement("div");
18
19      paginationControls.innerHTML = "Page: " + (datasource.getCurrentPage() + 1) + " out of " + (datasource.getPageCount()) + " ";
20
21      for (var i=0; i < datasource.getPageCount(); i++) {
22        var choosePageLink = document.createElement("a");
23
24        paginationControls.appendChild(choosePageLink);
25
26        choosePageLink.innerHTML = (i + 1) + " ";
27        choosePageLink.page = i;
28
29        if (i != datasource.getCurrentPage()) {
30          choosePageLink.href = "javascript: null";
31          choosePageLink.onClick = function () { return false; };
32
33          DOM.addEventListener(choosePageLink, "click", function (evt) {
34            Event.prep(evt);
35            var page = evt.target.page;
36            datasource.setCurrentPage(page);
37
38            // if changing pages, then clear the current selection
39            FB.galSelected.empty();
40
41            return false;
42          });
43        }
44      }
45
46      view.appendChild(paginationControls);
47  }
48});
Note: See TracBrowser for help on using the browser.