From ab8432a1bbdb779ae374fe273dca069184486cc6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 9 Aug 2014 09:27:56 -0400 Subject: Move controller methods to prototype. * js/guix-packages.js: Move functions defined on each instance of guix.controller to guix.controller's prototype. --- js/guix-packages.js | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/js/guix-packages.js b/js/guix-packages.js index 7ab30a0..c9a61ca 100644 --- a/js/guix-packages.js +++ b/js/guix-packages.js @@ -52,37 +52,37 @@ guix.controller = function() { this.packages.then(function(packages) { self.pages(guix.paginate(packages, self.pageSize)); }); +}; - this.currentPage = function() { - return self.pages()[self.currentPageIndex] || []; - }; +guix.controller.prototype.currentPage = function() { + return this.pages()[this.currentPageIndex] || []; +}; - this.isFirstPage = function() { - return self.currentPageIndex === 0; - }; +guix.controller.prototype.isFirstPage = function() { + return this.currentPageIndex === 0; +}; - this.isLastPage = function() { - return self.currentPageIndex === self.pages().length - 1; - }; +guix.controller.prototype.isLastPage = function() { + return this.currentPageIndex === this.pages().length - 1; +}; - this.isCurrentPage = function(i) { - return self.currentPageIndex === i; - }; +guix.controller.prototype.isCurrentPage = function(i) { + return this.currentPageIndex === i; +}; - this.packageCount = function() { - return self.pages().reduce(function(memo, page) { - return memo + page.length; - }, 0); - }; +guix.controller.prototype.packageCount = function() { + return this.pages().reduce(function(memo, page) { + return memo + page.length; + }, 0); +}; - this.doSearch = function() { - var regexp = new RegExp(this.searchTerm(), "i"); +guix.controller.prototype.doSearch = function() { + var regexp = new RegExp(this.searchTerm(), "i"); - this.pages(guix.paginate(this.packages().filter(function(package) { - return regexp.test(package.name) || - regexp.test(package.synopsis); - }), self.pageSize)); - }; + this.pages(guix.paginate(this.packages().filter(function(package) { + return regexp.test(package.name) || + regexp.test(package.synopsis); + }), this.pageSize)); }; guix.view = function(ctrl) { -- cgit v1.2.3