From de18b3dc63824cde7ba1bb82604129e1bffa1029 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Fri, 13 Feb 2015 14:32:17 -0800 Subject: [PATCH 1/3] Refactoring (m2) --- test/demo/m2/js/main.js | 78 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/test/demo/m2/js/main.js b/test/demo/m2/js/main.js index e14dcb45..73a2da41 100644 --- a/test/demo/m2/js/main.js +++ b/test/demo/m2/js/main.js @@ -11,7 +11,7 @@ this.mode = 'none'; this.pageBuffer = 0.05; this.bigBuffer = 0.2; - this.page = 0; + this.pageIndex = 0; this.modeNames = [ 'thumbs', 'scroll', @@ -50,7 +50,7 @@ if (self.mode === 'scroll') { var result = self.hitTest(self.viewer.viewport.getCenter()); if (result) { - self.page = result.index; + self.pageIndex = result.index; self.update(); } } @@ -116,7 +116,7 @@ if (result) { self.setMode({ mode: 'page', - page: result.index + pageIndex: result.index }); } }); @@ -155,35 +155,35 @@ // ---------- next: function() { - var page = this.page + (this.mode === 'book' ? 2 : 1); - if (this.mode === 'book' && page % 2 === 0 && page !== 0) { - page --; + var pageIndex = this.pageIndex + (this.mode === 'book' ? 2 : 1); + if (this.mode === 'book' && pageIndex % 2 === 0 && pageIndex !== 0) { + pageIndex --; } this.goToPage({ - page: page + pageIndex: pageIndex }); }, // ---------- previous: function() { - var page = this.page - (this.mode === 'book' ? 2 : 1); - if (this.mode === 'book' && page % 2 === 0 && page !== 0) { - page --; + var pageIndex = this.pageIndex - (this.mode === 'book' ? 2 : 1); + if (this.mode === 'book' && pageIndex % 2 === 0 && pageIndex !== 0) { + pageIndex --; } this.goToPage({ - page: page + pageIndex: pageIndex }); }, // ---------- hitTest: function(pos) { - var count = this.viewer.world.getItemCount(); + var count = this.pages.length; var item, box; for (var i = 0; i < count; i++) { - item = this.viewer.world.getItemAt(i); + item = this.pages[i].tiledImage; box = item.getBounds(); if (pos.x > box.x && pos.y > box.y && pos.x < box.x + box.width && pos.y < box.y + box.height) { @@ -222,8 +222,8 @@ var self = this; $('.nav').toggle(this.mode === 'scroll' || this.mode === 'book' || this.mode === 'page'); - $('.previous').toggleClass('hidden', this.page <= 0); - $('.next').toggleClass('hidden', this.page >= this.viewer.world.getItemCount() - 1); + $('.previous').toggleClass('hidden', this.pageIndex <= 0); + $('.next').toggleClass('hidden', this.pageIndex >= this.pages.length - 1); $.each(this.modeNames, function(i, v) { $('.' + v).toggleClass('active', v === self.mode); @@ -235,7 +235,7 @@ this.$alternates = null; } - var page = this.pages[this.page]; + var page = this.pages[this.pageIndex]; if (page && page.alternates && page.alternates.length) { this.$alternates = $('