diff options
author | Olivier Paroz <github@oparoz.com> | 2015-01-28 00:56:09 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-01-28 00:56:09 +0300 |
commit | 9ffac93a1609705daede7be9b98c6c82f6d6893e (patch) | |
tree | eb7ff3adc1ab2bba659f9fae826697258a7093c3 /js/gallerybutton.js | |
parent | 25af5a16f34ff244225c2fd53e56cd68d28ed96f (diff) |
The Gallery button is now available to logged in users
The button which allows users to switch back and forth between the Files and Gallery app without losing the current folder/album was only available in public shares.
Not anymore.
### Fixes
https://github.com/interfasys/galleryplus/issues/15
https://github.com/owncloud/gallery/issues/116
Diffstat (limited to 'js/gallerybutton.js')
-rw-r--r-- | js/gallerybutton.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/js/gallerybutton.js b/js/gallerybutton.js new file mode 100644 index 00000000..351facb6 --- /dev/null +++ b/js/gallerybutton.js @@ -0,0 +1,76 @@ +/* global OC, OCA, FileList, $, t */ +var GalleryButton = {}; +GalleryButton.isPublic = false; +GalleryButton.button = {}; +GalleryButton.url = null; + + +GalleryButton.onFileListUpdated = function () { + var hasImages = false; + var fileList; + var files; + + if (GalleryButton.isPublic) { + fileList = OCA.Sharing.PublicApp.fileList; + files = fileList.files; + } else { + fileList = FileList; + files = fileList.files; + } + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + if (file.isPreviewAvailable) { + hasImages = true; + break; + } + } + + if (hasImages) { + GalleryButton.button.toggleClass('hidden', false); + GalleryButton.buildUrl(fileList.getCurrentDirectory().replace(/^\//, '')); + } else { + GalleryButton.button.toggleClass('hidden', true); + } +}; + +GalleryButton.buildUrl = function (dir) { + var params = {}; + var tokenPath = ''; + var token = ($('#sharingToken').val()) ? $('#sharingToken').val() : false; + if (token) { + params.token = token; + tokenPath = 's/{token}'; + } + GalleryButton.url = OC.generateUrl('apps/galleryplus/' + tokenPath, params) + '#' + dir; +}; + + +$(document).ready(function () { + + if ($('#body-login').length > 0) { + return true; //deactivate on login page + } + + if ($('#isPublic').val()) { + GalleryButton.isPublic = true; + } + + if ($('#filesApp').val()) { + + $('#fileList').on('updated', GalleryButton.onFileListUpdated); + + // toggle for opening shared file list as picture view + GalleryButton.button = $('<div id="openAsFileListButton" class="button hidden">' + + '<img class="svg" src="' + OC.imagePath('core', 'actions/toggle-pictures.svg') + '"' + + 'alt="' + t('gallery', 'Picture view') + '"/>' + + '</div>'); + + GalleryButton.button.click(function () { + window.location.href = GalleryButton.url; + }); + + $('#controls').prepend(GalleryButton.button); + } + } +); |