From 46d74bdc51b60d90c19ad2434863c9b84c523638 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Thu, 17 Oct 2013 23:49:30 +0200 Subject: [PATCH] Decrease dependence of SecondaryToolbar on UI buttons --- web/secondary_toolbar.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js index 242d2decf..df382f2bf 100644 --- a/web/secondary_toolbar.js +++ b/web/secondary_toolbar.js @@ -25,11 +25,10 @@ var SecondaryToolbar = { initialize: function secondaryToolbarInitialize(options) { this.toolbar = options.toolbar; - this.toggleButton = options.toggleButton; - this.buttonContainer = this.toolbar.firstElementChild; // Define the toolbar buttons. + this.toggleButton = options.toggleButton; this.presentationMode = options.presentationMode; this.openFile = options.openFile; this.print = options.print; @@ -40,21 +39,24 @@ var SecondaryToolbar = { this.pageRotateCcw = options.pageRotateCcw; // Attach the event listeners. - this.toggleButton.addEventListener('click', this.toggle.bind(this)); + var elements = [ + { element: this.toggleButton, handler: this.toggle }, + { element: this.presentationMode, handler: this.presentationModeClick }, + { element: this.openFile, handler: this.openFileClick }, + { element: this.print, handler: this.printClick }, + { element: this.download, handler: this.downloadClick }, + { element: this.firstPage, handler: this.firstPageClick }, + { element: this.lastPage, handler: this.lastPageClick }, + { element: this.pageRotateCw, handler: this.pageRotateCwClick }, + { element: this.pageRotateCcw, handler: this.pageRotateCcwClick } + ]; - this.presentationMode.addEventListener('click', - this.presentationModeClick.bind(this)); - this.openFile.addEventListener('click', this.openFileClick.bind(this)); - this.print.addEventListener('click', this.printClick.bind(this)); - this.download.addEventListener('click', this.downloadClick.bind(this)); - - this.firstPage.addEventListener('click', this.firstPageClick.bind(this)); - this.lastPage.addEventListener('click', this.lastPageClick.bind(this)); - - this.pageRotateCw.addEventListener('click', - this.pageRotateCwClick.bind(this)); - this.pageRotateCcw.addEventListener('click', - this.pageRotateCcwClick.bind(this)); + for (var item in elements) { + var element = elements[item].element; + if (element) { + element.addEventListener('click', elements[item].handler.bind(this)); + } + } }, // Event handling functions.