Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/app.js8
-rw-r--r--js/gallery.js151
-rw-r--r--js/galleryinfobox.js4
-rw-r--r--js/galleryutility.js156
-rw-r--r--js/galleryview.js25
-rw-r--r--js/thumbnail.js2
-rw-r--r--templates/part.content.php1
-rw-r--r--templates/public.php1
8 files changed, 185 insertions, 163 deletions
diff --git a/js/app.js b/js/app.js
index 8f2dbe02..ade5acac 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1,6 +1,9 @@
/* global OC, $, _, Gallery */
$(document).ready(function () {
Gallery.hideSearch();
+ Gallery.utility = new Gallery.Utility();
+ Gallery.view = new Gallery.View();
+ Gallery.token = Gallery.utility.getRequestToken();
Gallery.ie11AndAbove =
navigator.userAgent.indexOf('Trident') != -1 && navigator.userAgent.indexOf('MSIE') == -1;
@@ -18,10 +21,7 @@ $(document).ready(function () {
Gallery.resetContentHeight();
Gallery.showLoading();
- Gallery.view = new Gallery.View();
- Gallery.token = Gallery.view.getRequestToken();
-
- $.getJSON(Gallery.buildGalleryUrl('mediatypes', '', {}))
+ $.getJSON(Gallery.utility.buildGalleryUrl('mediatypes', '', {}))
.then(function (mediaTypes) {
//console.log('mediaTypes', mediaTypes);
Gallery.mediaTypes = mediaTypes;
diff --git a/js/gallery.js b/js/gallery.js
index cb1ea808..b94a01b1 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.buildGalleryUrl('files', '', params);
+ var url = Gallery.utility.buildGalleryUrl('files', '', params);
return $.getJSON(url).then(function (data) {
var path = null;
var fileId = null;
@@ -147,42 +147,7 @@ Gallery.fixDir = function (path, dir, currentFolder) {
};
/**
- * Sorts images and albums arrays
- *
- * @param {string} sortType
- * @param {string} sortOrder
- *
- * @returns {Function}
- */
-Gallery.sortBy = function (sortType, sortOrder) {
- if (sortType === 'name') {
- if (sortOrder === 'asc') {
- //sortByNameAsc
- return function (a, b) {
- return a.path.toLowerCase().localeCompare(b.path.toLowerCase());
- };
- }
- //sortByNameDes
- return function (a, b) {
- return b.path.toLowerCase().localeCompare(a.path.toLowerCase());
- };
- }
- if (sortType === 'date') {
- if (sortOrder === 'asc') {
- //sortByDateAsc
- return function (a, b) {
- return b.mTime - a.mTime;
- };
- }
- //sortByDateDes
- return function (a, b) {
- return a.mTime - b.mTime;
- };
- }
-};
-
-/**
- * Sorts thumbnails based on user preferences
+ * Sorts albums and images based on user preferences
*/
Gallery.sorter = function () {
var sortType = 'name';
@@ -212,8 +177,8 @@ Gallery.sorter = function () {
Gallery.view.clear();
// Sort the images
- Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.sortBy(sortType, sortOrder));
- Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.sortBy(albumSortType,
+ Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.utility.sortBy(sortType, sortOrder));
+ Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.utility.sortBy(albumSortType,
albumSortOrder));
// Save the new settings
@@ -224,25 +189,6 @@ Gallery.sorter = function () {
};
/**
- * Builds the URL which will retrieve a large preview of the file
- *
- * @param {string} image
- *
- * @return {string}
- */
-Gallery.getPreviewUrl = function (image) {
- var width = $(window).width() * window.devicePixelRatio;
- var height = $(window).height() * window.devicePixelRatio;
- var params = {
- file: image,
- x: width,
- y: height,
- requesttoken: oc_requesttoken
- };
- return Gallery.buildGalleryUrl('preview', '', params);
-};
-
-/**
* Populates the share dialog with the needed information
*
* @param event
@@ -277,55 +223,6 @@ Gallery.share = function (event) {
};
/**
- * Builds a URL pointing to one of the app's controllers
- *
- * @param {string} endPoint
- * @param {undefined|string} path
- * @param params
- *
- * @returns {string}
- */
-Gallery.buildGalleryUrl = function (endPoint, path, params) {
- if (path === undefined) {
- path = '';
- }
- var extension = '';
- if (Gallery.token) {
- params.token = Gallery.token;
- extension = '.public';
- }
- var query = OC.buildQueryString(params);
- return OC.generateUrl('apps/' + Gallery.appName + '/' + endPoint + extension + path, null) +
- '?' +
- query;
-};
-
-/**
- * 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?path={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
@@ -335,7 +232,7 @@ Gallery.download = function (event) {
var path = $('#content').data('albumname');
var files = Gallery.currentAlbum;
- var downloadUrl = Gallery.buildFilesUrl(path, files);
+ var downloadUrl = Gallery.utility.buildFilesUrl(path, files);
OC.redirect(downloadUrl);
};
@@ -384,16 +281,19 @@ Gallery.showNormal = function () {
$('#content').removeClass('icon-loading');
};
+Gallery.recommendedBrowsers = '</br>' +
+'<a href="http://www.getfirefox.com"><strong>Mozilla Firefox</strong></a> or ' +
+'<a href="https://www.google.com/chrome/"><strong>Google Chrome</strong></a>' +
+'</br>';
+
/**
* Shows a warning to users of old, unsupported version of Internet Explorer
*/
Gallery.showOldIeWarning = function () {
var text = '<strong>' + t('gallery', 'Your browser is not supported!') + '</strong></br>' +
- t('gallery', 'please install one of the following alternatives') + '</br>' +
- '<a href="http://www.getfirefox.com"><strong>Mozilla Firefox</strong></a> or ' +
- '<a href="https://www.google.com/chrome/"><strong>Google Chrome</strong></a>' +
- '</br>';
- Gallery.showHtmlNotification(text, 60);
+ t('gallery', 'please install one of the following alternatives') +
+ Gallery.recommendedBrowsers;
+ Gallery.utility.showHtmlNotification(text, 60);
};
/**
@@ -404,25 +304,8 @@ Gallery.showModernIeWarning = function () {
t('gallery', 'This application may not work properly on your browser.') + '</strong></br>' +
t('gallery',
'For an improved experience, please install one of the following alternatives') +
- '</br>' +
- '<a href="http://www.getfirefox.com"><strong>Mozilla Firefox</strong></a> or ' +
- '<a href="https://www.google.com/chrome/"><strong>Google Chrome</strong></a>' +
- '</br>';
- Gallery.showHtmlNotification(text, 15);
-};
-
-/**
- * Shows a notification at the top of the screen
- *
- * @param {string} text
- * @param {int} timeout
- */
-Gallery.showHtmlNotification = function (text, timeout) {
- var options = {
- timeout: timeout,
- isHTML: true
- };
- OC.Notification.showTemporary(text, options);
+ Gallery.recommendedBrowsers;
+ Gallery.utility.showHtmlNotification(text, 15);
};
/**
@@ -450,12 +333,12 @@ Gallery.slideShow = function (images, startImage, autoPlay) {
var start = images.indexOf(startImage);
images = images.map(function (image) {
var name = OC.basename(image.path);
- var previewUrl = Gallery.getPreviewUrl(image.src);
+ var previewUrl = Gallery.utility.getPreviewUrl(image.src);
var params = {
file: image.src,
requesttoken: oc_requesttoken
};
- var downloadUrl = Gallery.buildGalleryUrl('download', '', params);
+ var downloadUrl = Gallery.utility.buildGalleryUrl('download', '', params);
return {
name: name,
diff --git a/js/galleryinfobox.js b/js/galleryinfobox.js
index 41362e5b..50204852 100644
--- a/js/galleryinfobox.js
+++ b/js/galleryinfobox.js
@@ -25,7 +25,7 @@
if (!$.isEmptyObject(this.albumInfo.descriptionLink)) {
var path = '/' + this.albumInfo.filePath;
var file = this.albumInfo.descriptionLink;
- var descriptionUrl = Gallery.buildFilesUrl(path, file);
+ var descriptionUrl = Gallery.utility.buildFilesUrl(path, file);
var thisInfoBox = this;
$.get(descriptionUrl).done(function (data) {
thisInfoBox._addContent(data);
@@ -118,7 +118,7 @@
_addCopyrightLink: function (copyright) {
var path = '/' + this.albumInfo.filePath;
var file = this.albumInfo.copyrightLink;
- var copyrightUrl = Gallery.buildFilesUrl(path, file);
+ var copyrightUrl = Gallery.utility.buildFilesUrl(path, file);
var copyrightElement = $(copyright);
copyrightElement.find('a').removeAttr("href");
copyright = copyrightElement.html();
diff --git a/js/galleryutility.js b/js/galleryutility.js
new file mode 100644
index 00000000..21d2a162
--- /dev/null
+++ b/js/galleryutility.js
@@ -0,0 +1,156 @@
+/* global OC, $, Gallery, oc_requesttoken */
+(function () {
+ /**
+ * Contains utility methods
+ *
+ * @fixme OC.generateUrl, OC.buildQueryString, OC.Notification are private APIs
+ *
+ * @constructor
+ */
+ var Utility = function () {
+ };
+
+ Utility.prototype = {
+ /**
+ * Shows a notification at the top of the screen
+ *
+ * @param {string} text
+ * @param {int} timeout
+ */
+ showHtmlNotification: function (text, timeout) {
+ var options = {
+ timeout: timeout,
+ isHTML: true
+ };
+ OC.Notification.showTemporary(text, options);
+ },
+
+ /**
+ * Returns the token alowing access to files
+ *
+ * @returns {string}
+ */
+ getRequestToken: function () {
+ var element = $('#gallery');
+ var token;
+
+ if (element.data('token')) {
+ token = element.data('token');
+ }
+
+ if (element.data('requesttoken')) {
+ oc_requesttoken = element.data('requesttoken');
+ }
+
+ return token;
+ },
+
+ /**
+ * Builds the URL which will retrieve a large preview of the file
+ *
+ * @fixme we cannot get rid of oc_requesttoken parameter as it's missing from the headers
+ *
+ * @param {string} image
+ *
+ * @return {string}
+ */
+ getPreviewUrl: function (image) {
+ var width = $(window).width() * window.devicePixelRatio;
+ var height = $(window).height() * window.devicePixelRatio;
+ var params = {
+ file: image,
+ x: width,
+ y: height,
+ requesttoken: oc_requesttoken
+ };
+ return this.buildGalleryUrl('preview', '', params);
+ },
+
+ /**
+ * Builds a URL pointing to one of the app's controllers
+ *
+ * @param {string} endPoint
+ * @param {undefined|string} path
+ * @param params
+ *
+ * @returns {string}
+ */
+ buildGalleryUrl: function (endPoint, path, params) {
+ if (path === undefined) {
+ path = '';
+ }
+ var extension = '';
+ if (Gallery.token) {
+ params.token = Gallery.token;
+ extension = '.public';
+ }
+ var query = OC.buildQueryString(params);
+ return OC.generateUrl('apps/' + Gallery.appName + '/' + endPoint + extension + path,
+ null) +
+ '?' +
+ query;
+ },
+
+ /**
+ * Builds a URL pointing to one of the files' controllers
+ *
+ * @param {string} path
+ * @param {string} files
+ *
+ * @returns {string}
+ */
+ buildFilesUrl: function (path, files) {
+ var subUrl = '';
+ var params = {
+ path: path,
+ files: files
+ };
+
+ if (Gallery.token) {
+ params.token = Gallery.token;
+ subUrl = 's/{token}/download?path={path}&files={files}';
+ } else {
+ subUrl = 'apps/files/ajax/download.php?dir={path}&files={files}';
+ }
+
+ return OC.generateUrl(subUrl, params);
+ },
+
+ /**
+ * Sorts arrays based on name or date
+ *
+ * @param {string} sortType
+ * @param {string} sortOrder
+ *
+ * @returns {Function}
+ */
+ sortBy: function (sortType, sortOrder) {
+ if (sortType === 'name') {
+ if (sortOrder === 'asc') {
+ //sortByNameAsc
+ return function (a, b) {
+ return a.path.toLowerCase().localeCompare(b.path.toLowerCase());
+ };
+ }
+ //sortByNameDes
+ return function (a, b) {
+ return b.path.toLowerCase().localeCompare(a.path.toLowerCase());
+ };
+ }
+ if (sortType === 'date') {
+ if (sortOrder === 'asc') {
+ //sortByDateAsc
+ return function (a, b) {
+ return b.mTime - a.mTime;
+ };
+ }
+ //sortByDateDes
+ return function (a, b) {
+ return a.mTime - b.mTime;
+ };
+ }
+ }
+ };
+
+ Gallery.Utility = Utility;
+})(); \ No newline at end of file
diff --git a/js/galleryview.js b/js/galleryview.js
index 10d42112..789b6c6d 100644
--- a/js/galleryview.js
+++ b/js/galleryview.js
@@ -48,25 +48,6 @@
},
/**
- * Returns the token alowing access to files
- *
- * @returns {string}
- */
- getRequestToken: function () {
- var token;
-
- if (this.element.data('token')) {
- token = this.element.data('token');
- }
-
- if (this.element.data('requesttoken')) {
- oc_requesttoken = this.element.data('requesttoken');
- }
-
- return token;
- },
-
- /**
* Starts the slideshow
*
* @param {string} path
@@ -127,9 +108,9 @@
var currentSort = Gallery.albumConfig.sorting;
this.sortControlsSetup(currentSort.type, currentSort.order);
- Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.sortBy(currentSort.type,
+ Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.utility.sortBy(currentSort.type,
currentSort.order));
- Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.sortBy('name',
+ Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.utility.sortBy('name',
currentSort.albumOrder));
},
@@ -161,7 +142,7 @@
infoButton.hide();
var text = '<strong>' + t('gallery', 'Configuration error') + '</strong></br>' +
Gallery.albumConfig.error.message + '</br></br>';
- Gallery.showHtmlNotification(text, 7);
+ Gallery.utility.showHtmlNotification(text, 7);
} else if ($.isEmptyObject(albumInfo)) {
infoButton.hide();
} else {
diff --git a/js/thumbnail.js b/js/thumbnail.js
index 64e1f5fa..9c3a3020 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.buildGalleryUrl('thumbnails', '', params);
+ var url = Gallery.utility.buildGalleryUrl('thumbnails', '', params);
var eventSource = new Gallery.EventSource(url);
eventSource.listen('preview', function (preview) {
diff --git a/templates/part.content.php b/templates/part.content.php
index b9d6b4dd..989f3274 100644
--- a/templates/part.content.php
+++ b/templates/part.content.php
@@ -10,6 +10,7 @@ script(
[
'app',
'gallery',
+ 'galleryutility',
'galleryconfig',
'galleryinfobox',
'galleryview',
diff --git a/templates/public.php b/templates/public.php
index 04d58fe8..fc6c214b 100644
--- a/templates/public.php
+++ b/templates/public.php
@@ -10,6 +10,7 @@ script(
[
'app',
'gallery',
+ 'galleryutility',
'galleryconfig',
'galleryinfobox',
'galleryview',