From 589d167777337335919f24e559fc721166940444 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Fri, 10 Apr 2015 13:28:36 +0200 Subject: Lowered complexity of Gallery.View --- js/galleryview.js | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'js/galleryview.js') diff --git a/js/galleryview.js b/js/galleryview.js index e1950c1b..e768b427 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -90,21 +90,11 @@ } this.clear(); + if (albumPath !== Gallery.currentAlbum) { this.loadVisibleRows.loading = false; Gallery.currentAlbum = albumPath; - this.shareButtonSetup(albumPath); - this.infoButtonSetup(); - - this.breadcrumb = new Gallery.Breadcrumb(albumPath); - this.breadcrumb.setMaxWidth($(window).width() - 320); - - var currentSort = Gallery.albumConfig.getAlbumSorting(); - this.sortControlsSetup(currentSort.type, currentSort.order); - Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.sortBy(currentSort.type, - currentSort.order)); - Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.sortBy('name', - currentSort.albumOrder)); + this.setupButtons(albumPath); } Gallery.albumMap[albumPath].viewedItems = 0; @@ -122,6 +112,26 @@ }.bind(this), 0); }, + /** + * Sets up all the buttons of the interface + * + * @param {string} albumPath + */ + setupButtons: function (albumPath) { + this.shareButtonSetup(albumPath); + this.infoButtonSetup(); + + this.breadcrumb = new Gallery.Breadcrumb(albumPath); + this.breadcrumb.setMaxWidth($(window).width() - 320); + + var currentSort = Gallery.albumConfig.getAlbumSorting(); + this.sortControlsSetup(currentSort.type, currentSort.order); + Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.sortBy(currentSort.type, + currentSort.order)); + Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.sortBy('name', + currentSort.albumOrder)); + }, + /** * Shows or hides the share button depending on if we're in a public gallery or not * @@ -145,10 +155,7 @@ infoContentElement.slideUp(); infoContentElement.css('max-height', $(window).height() - 150); var albumInfo = Gallery.albumConfig.getAlbumInfo(); - if ($.isEmptyObject(albumInfo.description) && - $.isEmptyObject(albumInfo.descriptionLink) && - $.isEmptyObject(albumInfo.copyright) && - $.isEmptyObject(albumInfo.copyrightLink)) { + if (this.isAlbumInfoEmtpy(albumInfo)) { infoButton.hide(); } else { infoButton.show(); @@ -160,6 +167,20 @@ } }, + /** + * Determines if we have received a description and a copyright statement for the current + * album + * + * @param {object} albumInfo + * @returns {bool} + */ + isAlbumInfoEmtpy: function (albumInfo) { + return $.isEmptyObject(albumInfo.description) && + $.isEmptyObject(albumInfo.descriptionLink) && + $.isEmptyObject(albumInfo.copyright) && + $.isEmptyObject(albumInfo.copyrightLink); + }, + /** * Manages the sorting interface * -- cgit v1.2.3