diff options
author | Olivier Paroz <github@oparoz.com> | 2015-04-10 21:52:47 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-04-10 21:52:47 +0300 |
commit | 73fefeb4b2138d4e79112192692901dcfa895997 (patch) | |
tree | 28d040f7c0eeff2a9de24d8fcfd1f8d25f0f3ff6 | |
parent | ebdb5004dade24cfd7af914d525f3c46302fc955 (diff) |
Update URL building methods
-rw-r--r-- | js/gallery.js | 48 | ||||
-rw-r--r-- | js/gallerybutton.js | 4 | ||||
-rw-r--r-- | js/galleryinfobox.js | 22 | ||||
-rw-r--r-- | js/slideshow.js | 36 | ||||
-rw-r--r-- | js/thumbnail.js | 2 |
5 files changed, 64 insertions, 48 deletions
diff --git a/js/gallery.js b/js/gallery.js index 06105c69..48426809 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -84,7 +84,7 @@ Gallery.getFiles = function () { mediatypes: Gallery.getMediaTypes() }; // Only use the folder as a GET parameter and not as part of the URL - var url = Gallery.buildUrl('files', '', params); + var url = Gallery.buildGalleryUrl('files', '', params); return $.getJSON(url).then(function (data) { var path = null; var fileId = null; @@ -239,7 +239,7 @@ Gallery.getPreviewUrl = function (image) { y: height, requesttoken: oc_requesttoken }; - return Gallery.buildUrl('preview', '', params); + return Gallery.buildGalleryUrl('preview', '', params); }; /** @@ -277,7 +277,7 @@ Gallery.share = function (event) { }; /** - * Builds a URL pointing to one of our PHP controllers + * Builds a URL pointing to one of the app's controllers * * @param {string} endPoint * @param {undefined|string} path @@ -285,7 +285,7 @@ Gallery.share = function (event) { * * @returns {string} */ -Gallery.buildUrl = function (endPoint, path, params) { +Gallery.buildGalleryUrl = function (endPoint, path, params) { if (path === undefined) { path = ''; } @@ -301,17 +301,43 @@ Gallery.buildUrl = function (endPoint, path, params) { }; /** + * Builds a URL pointing to one of the files' controllers + * + * @param {string} path + * @param {string} files + * + * @returns {string} + */ +Gallery.buildFilesUrl = function (path, files) { + var subUrl = ''; + var params = { + path: path, + files: files + }; + + if (Gallery.token) { + params.token = Gallery.token; + subUrl = 's/{token}/download?dir={path}&files={files}'; + } else { + subUrl = 'apps/files/ajax/download.php?dir={path}&files={files}'; + } + + return OC.generateUrl(subUrl, params); +}; + +/** * Sends an archive of the current folder to the browser * * @param event */ Gallery.download = function (event) { event.preventDefault(); - OC.redirect(OC.generateUrl('s/{token}/download?path={path}&files={files}', { - token: Gallery.token, - path: $('#content').data('albumname'), - files: Gallery.currentAlbum - })); + + var path = $('#content').data('albumname'); + var files = Gallery.currentAlbum; + var downloadUrl = Gallery.buildFilesUrl(path, files); + + OC.redirect(downloadUrl); }; /** @@ -426,7 +452,7 @@ Gallery.slideShow = function (images, startImage, autoPlay) { file: image.src, requesttoken: oc_requesttoken }; - var downloadUrl = Gallery.buildUrl('download', '', params); + var downloadUrl = Gallery.buildGalleryUrl('download', '', params); return { name: name, @@ -477,7 +503,7 @@ $(document).ready(function () { Gallery.view = new Gallery.View(); Gallery.token = Gallery.view.getRequestToken(); - $.getJSON(Gallery.buildUrl('mediatypes', '', {})) + $.getJSON(Gallery.buildGalleryUrl('mediatypes', '', {})) .then(function (mediaTypes) { //console.log('mediaTypes', mediaTypes); Gallery.mediaTypes = mediaTypes; diff --git a/js/gallerybutton.js b/js/gallerybutton.js index e6d7dd90..966cb602 100644 --- a/js/gallerybutton.js +++ b/js/gallerybutton.js @@ -17,7 +17,7 @@ GalleryButton.onFileListUpdated = function () { } files = fileList.files; - GalleryButton.buildUrl(fileList.getCurrentDirectory().replace(/^\//, '')); + GalleryButton.buildGalleryUrl(fileList.getCurrentDirectory().replace(/^\//, '')); for (var i = 0; i < files.length; i++) { var file = files[i]; @@ -32,7 +32,7 @@ GalleryButton.onFileListUpdated = function () { } }; -GalleryButton.buildUrl = function (dir) { +GalleryButton.buildGalleryUrl = function (dir) { var params = {}; var tokenPath = ''; var token = ($('#sharingToken').val()) ? $('#sharingToken').val() : false; diff --git a/js/galleryinfobox.js b/js/galleryinfobox.js index 46130d17..5cde9060 100644 --- a/js/galleryinfobox.js +++ b/js/galleryinfobox.js @@ -23,10 +23,9 @@ this.infoContentElement.height(100); this.infoContentElement.slideDown(); if (!$.isEmptyObject(this.albumInfo.descriptionLink)) { - var params = { - file: this.albumInfo.filePath + '/' + this.albumInfo.descriptionLink - }; - var descriptionUrl = Gallery.buildUrl('download', '', params); + var path = '/' + this.albumInfo.filePath; + var file = this.albumInfo.descriptionLink; + var descriptionUrl = Gallery.buildFilesUrl(path, file); var thisInfoBox = this; $.get(descriptionUrl).done(function (data) { thisInfoBox._addContent(data); @@ -117,18 +116,9 @@ * @private */ _addCopyrightLink: function (copyright) { - var subUrl = ''; - var params = { - path: '/' + this.albumInfo.filePath, - files: this.albumInfo.copyrightLink - }; - if (Gallery.token) { - params.token = Gallery.token; - subUrl = 's/{token}/download?dir={path}&files={files}'; - } else { - subUrl = 'apps/files/ajax/download.php?dir={path}&files={files}'; - } - var copyrightUrl = OC.generateUrl(subUrl, params); + var path = '/' + this.albumInfo.filePath; + var file = this.albumInfo.copyrightLink; + var copyrightUrl = Gallery.buildFilesUrl(path, file); var copyrightElement = $(copyright); copyrightElement.find('a').removeAttr("href"); copyright = copyrightElement.html(); diff --git a/js/slideshow.js b/js/slideshow.js index 6fa23d98..f3003241 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -140,31 +140,32 @@ SlideShow.prototype = { this.container.css('background-position', 'center'); this.hideImage(); var currentImageId = index; - return this.loadImage(this.images[index]).then(function (image) { + return this.loadImage(this.images[index]).then(function (img) { this.container.css('background-position', '-10000px 0'); this.container.find('.changeBackground').show(); // check if we moved along while we were loading if (currentImageId === index) { + var image = this.images[index]; this.errorLoadingImage = false; - this.currentImage = image; - this.currentImage.mimeType = this.images[index].mimeType; - this.container.append(image); + this.currentImage = img; + this.currentImage.mimeType = image.mimeType; + this.container.append(img); var backgroundColour = '#fff'; if (this.currentImage.mimeType === 'image/jpeg' || this.currentImage.mimeType === 'image/x-dcraw') { backgroundColour = '#000'; } - image.setAttribute('alt', this.images[index].name); - $(image).css('position', 'absolute'); - $(image).css('background-color', backgroundColour); + img.setAttribute('alt', image.name); + $(img).css('position', 'absolute'); + $(img).css('background-color', backgroundColour); var $border = 30 / window.devicePixelRatio; - $(image).css('outline', $border + 'px solid ' + backgroundColour); + $(img).css('outline', $border + 'px solid ' + backgroundColour); - this.startBigshot(image); + this.startBigshot(img); - this.setUrl(this.images[index].path); + this.setUrl(image.path); this.controls.show(currentImageId); } }.bind(this), function () { @@ -177,7 +178,6 @@ SlideShow.prototype = { this.images.splice(index, 1); this.controls.updateControls(this.images, this.errorLoadingImage); } - }.bind(this)); }, @@ -374,7 +374,7 @@ SlideShow.prototype = { * * @returns {string} */ -SlideShow.buildUrl = function (endPoint, params) { +SlideShow.buildGalleryUrl = function (endPoint, path, params) { var extension = ''; var token = ($('#sharingToken').val()) ? $('#sharingToken').val() : false; if (token) { @@ -382,7 +382,7 @@ SlideShow.buildUrl = function (endPoint, params) { extension = '.public'; } var query = OC.buildQueryString(params); - return OC.generateUrl('apps/galleryplus/' + endPoint + extension, null) + '?' + query; + return OC.generateUrl('apps/galleryplus/' + endPoint + extension + path, null) + '?' + query; }; /** @@ -515,8 +515,8 @@ $(document).ready(function () { for (var i = 0; i < files.length; i++) { var file = files[i]; - // We only add images to the slideshow if we can generate previews for this - // media type + // We only add images to the slideshow if we think we'll be able + // to generate previews for this media type if (file.isPreviewAvailable || file.mimetype === 'image/svg+xml') { var params = { file: dir + file.name, @@ -524,8 +524,8 @@ $(document).ready(function () { y: height, requesttoken: requestToken }; - imageUrl = SlideShow.buildUrl('preview', params); - downloadUrl = SlideShow.buildUrl('download', params); + imageUrl = SlideShow.buildGalleryUrl('preview', '', params); + downloadUrl = SlideShow.buildGalleryUrl('download', '', params); images.push({ name: file.name, @@ -551,7 +551,7 @@ $(document).ready(function () { }); }; - var url = SlideShow.buildUrl('mediatypes', {slideshow: 1}); + var url = SlideShow.buildGalleryUrl('mediatypes', '', {slideshow: 1}); // We're asking for a list of supported media types. Media files are retrieved through the // context $.getJSON(url).then(function (mediaTypes) { diff --git a/js/thumbnail.js b/js/thumbnail.js index 25957838..64e1f5fa 100644 --- a/js/thumbnail.js +++ b/js/thumbnail.js @@ -72,7 +72,7 @@ Thumbnails.loadBatch = function (paths, square) { scale: window.devicePixelRatio, square: (square) ? 1 : 0 }; - var url = Gallery.buildUrl('thumbnails', '', params); + var url = Gallery.buildGalleryUrl('thumbnails', '', params); var eventSource = new Gallery.EventSource(url); eventSource.listen('preview', function (preview) { |