From d9ac106057c71ff51e5ea9e648efe1735af46db3 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Sat, 26 Sep 2015 22:00:37 +0200 Subject: Better fix for #366 It doesn't matter if we initialise hidden buttons, because the user is either going to navigate away to an album with images or leave the app. The important thing is to not add events every time we enter an album. [ci skip] --- js/galleryview.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'js/galleryview.js') diff --git a/js/galleryview.js b/js/galleryview.js index 572125fc..b77d8240 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -31,11 +31,11 @@ * @param {string} albumPath */ init: function (albumPath) { + // Only do it when the app is initialised + if (this.requestId === -1) { + this._initButtons(); + } if ($.isEmptyObject(Gallery.imageMap)) { - if (this.requestId === -1) { - $('#filelist-button').click(Gallery.switchToFilesView); - this.requestId = Math.random(); - } this.clear(); if (albumPath === '') { Gallery.showEmpty(); @@ -46,18 +46,6 @@ this.breadcrumb.setMaxWidth($(window).width() - Gallery.buttonsWidth); } } else { - // Only do it when the app is initialised - if (this.requestId === -1) { - $('#filelist-button').click(Gallery.switchToFilesView); - $('#download').click(Gallery.download); - $('#share-button').click(Gallery.share); - Gallery.infoBox = new Gallery.InfoBox(); - $('#album-info-button').click(Gallery.showInfo); - $('#sort-name-button').click(Gallery.sorter); - $('#sort-date-button').click(Gallery.sorter); - $('#save #save-button').click(Gallery.showSaveForm); - $('.save-form').submit(Gallery.saveForm); - } this._setBackgroundColour(); this.viewAlbum(albumPath); } @@ -210,6 +198,25 @@ } }, + /** + * Adds all the click handlers to buttons the first time they appear in the interface + * + * @private + */ + _initButtons: function () { + $('#filelist-button').click(Gallery.switchToFilesView); + $('#download').click(Gallery.download); + $('#share-button').click(Gallery.share); + Gallery.infoBox = new Gallery.InfoBox(); + $('#album-info-button').click(Gallery.showInfo); + $('#sort-name-button').click(Gallery.sorter); + $('#sort-date-button').click(Gallery.sorter); + $('#save #save-button').click(Gallery.showSaveForm); + $('.save-form').submit(Gallery.saveForm); + + this.requestId = Math.random(); + }, + /** * Sets up all the buttons of the interface * -- cgit v1.2.3