Allow pagination to be toggled off (#2307)

This commit is contained in:
Steve Purcell 2014-12-31 19:20:50 +00:00
parent a0a4072d6c
commit c27d7f0e92
2 changed files with 21 additions and 4 deletions

View file

@ -47,6 +47,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Cookies.js/1.1.0/cookies.min.js"></script>
<script src="js/melpa.js"></script>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript" async="async"></script>
<script>

View file

@ -1,5 +1,5 @@
/* global window */
(function(m, document, _, moment, jQuery){
(function(m, document, _, moment, jQuery, Cookies){
"use strict";
// TODO Disqus
@ -264,6 +264,18 @@
this.sortBy(field);
}
};
this.wantPagination = function() {
return !Cookies.get("nopagination");
};
this.togglePagination = function() {
console.log("toggle " + this.wantPagination());
if (this.wantPagination()) {
Cookies.set("nopagination", "1");
} else {
Cookies.expire("nopagination");
}
console.log("toggled " + Cookies.get("nopagination"));
};
this.paginatorCtrl = new melpa.paginator.controller(this.sortedPackages);
};
@ -304,7 +316,7 @@
])
]),
m("tbody",
ctrl.paginatorCtrl.paginatedItems().map(function(p) {
(ctrl.wantPagination() ? ctrl.paginatorCtrl.paginatedItems() : ctrl.sortedPackages()).map(function(p) {
return m("tr", { key: p.name }, [
m("td", packageLink(p)),
m("td", packageLink(p, p.description)),
@ -321,7 +333,11 @@
]);
}))
]),
melpa.paginator.view(ctrl.paginatorCtrl)
(ctrl.wantPagination() ? melpa.paginator.view(ctrl.paginatorCtrl) : null),
m("small",
m("a", {onclick: ctrl.togglePagination.bind(ctrl)},
(ctrl.wantPagination() ? "Disable pagination (may slow down display)" : "Enable pagination")
))
]);
};
@ -550,4 +566,4 @@
if (window.twttr && window.twttr.widgets) window.twttr.widgets.load();
}, 100);
})(window.m, window.document, window._, window.moment, window.jQuery);
})(window.m, window.document, window._, window.moment, window.jQuery, window.Cookies);