aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/app.js32
-rw-r--r--apps/files/js/filelist.js13
2 files changed, 43 insertions, 2 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index 09468205279..8015f395b74 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -56,13 +56,18 @@
var showHidden = $('#showHiddenFiles').val() === "1";
this.$showHiddenFiles.prop('checked', showHidden);
+ // crop image previews
+ this.$cropImagePreviews = $('input#cropimagepreviewsToggle');
+ var cropImagePreviews = $('#cropImagePreviews').val() === "1";
+ this.$cropImagePreviews.prop('checked', cropImagePreviews);
if ($('#fileNotFound').val() === "1") {
OC.Notification.show(t('files', 'File could not be found'), {type: 'error'});
}
this._filesConfig = new OC.Backbone.Model({
- showhidden: showHidden
+ showhidden: showHidden,
+ cropimagepreviews: cropImagePreviews,
});
var urlParams = OC.Util.History.parseUrlQuery();
@@ -132,6 +137,7 @@
});
this._debouncedPersistShowHiddenFilesState = _.debounce(this._persistShowHiddenFilesState, 1200);
+ this._debouncedPersistCropImagePreviewsState = _.debounce(this._persistCropImagePreviewsState, 1200);
if (sessionStorage.getItem('WhatsNewServerCheck') < (Date.now() - 3600*1000)) {
OCP.WhatsNew.query(); // for Nextcloud server
@@ -231,6 +237,7 @@
$('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this));
this.$showHiddenFiles.on('change', _.bind(this._onShowHiddenFilesChange, this));
+ this.$cropImagePreviews.on('change', _.bind(this._onCropImagePreviewsChange, this));
},
/**
@@ -257,6 +264,29 @@
},
/**
+ * Toggle cropping image previews according to the settings checkbox
+ *
+ * @returns void
+ */
+ _onCropImagePreviewsChange: function() {
+ var crop = this.$cropImagePreviews.is(':checked');
+ this._filesConfig.set('cropimagepreviews', crop);
+ this._debouncedPersistCropImagePreviewsState();
+ },
+
+ /**
+ * Persist crop image previews preference on the server
+ *
+ * @returns void
+ */
+ _persistCropImagePreviewsState: function() {
+ var crop = this._filesConfig.get('cropimagepreviews');
+ $.post(OC.generateUrl('/apps/files/api/v1/cropimagepreviews'), {
+ crop: crop
+ });
+ },
+
+ /**
* Event handler for when the current navigation item has changed
*/
_onNavigationChanged: function(e) {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 30bc35551d6..11d0bc4511d 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -252,7 +252,8 @@
this._filesConfig = OCA.Files.App.getFilesConfig();
} else {
this._filesConfig = new OC.Backbone.Model({
- 'showhidden': false
+ 'showhidden': false,
+ 'cropimagepreviews': true
});
}
@@ -291,6 +292,10 @@
}
});
+ this._filesConfig.on('change:cropimagepreviews', function() {
+ self.reload();
+ });
+
this.$el.toggleClass('hide-hidden-files', !this._filesConfig.get('showhidden'));
}
@@ -2215,6 +2220,12 @@
urlSpec.y = Math.ceil(urlSpec.y);
urlSpec.forceIcon = 0;
+ /**
+ * Images are cropped to a square by default. Append a=1 to the URL
+ * if the user wants to see images with original aspect ratio.
+ */
+ urlSpec.a = this._filesConfig.get('cropimagepreviews') ? 0 : 1;
+
if (typeof urlSpec.fileId !== 'undefined') {
delete urlSpec.file;
return OC.generateUrl('/core/preview?') + $.param(urlSpec);