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:
authorOlivier Paroz <github@oparoz.com>2015-04-16 04:23:10 +0300
committerOlivier Paroz <github@oparoz.com>2015-04-16 04:23:10 +0300
commit764c47189a4017e4f1c83b3fc15fe2218eb2bbab (patch)
tree95afc746b74b9d999a2194b368ce19c976658882 /js/galleryfileaction.js
parent5a6128cd544d1065f271562b46d6212f33c6ee02 (diff)
More JS class separations
Diffstat (limited to 'js/galleryfileaction.js')
-rw-r--r--js/galleryfileaction.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/js/galleryfileaction.js b/js/galleryfileaction.js
new file mode 100644
index 00000000..604ccf25
--- /dev/null
+++ b/js/galleryfileaction.js
@@ -0,0 +1,82 @@
+/* global jQuery, OC ,OCA, $, t, oc_requesttoken, SlideShow */
+$(document).ready(function () {
+ // This is still required in OC8
+ var requestToken;
+ if ($('#filesApp').val() && $('#isPublic').val()) {
+ // That's the only way to get one with the broken template
+ requestToken = $('#publicUploadRequestToken').val();
+ } else if ($('#gallery').data('requesttoken')) {
+ requestToken = $('#gallery').data('requesttoken');
+ } else {
+ requestToken = oc_requesttoken;
+ }
+ $(document).on('ajaxSend', function (elm, xhr) {
+ xhr.setRequestHeader('requesttoken', requestToken);
+ });
+
+ var prepareFileActions = function (mime) {
+ return OCA.Files.fileActions.register(mime, 'View', OC.PERMISSION_READ, '',
+ function (filename, context) {
+ var imageUrl, downloadUrl;
+ var fileList = context.fileList;
+ var files = fileList.files;
+ var start = 0;
+ var images = [];
+ var dir = context.dir + '/';
+ var width = Math.floor($(window).width() * window.devicePixelRatio);
+ var height = Math.floor($(window).height() * window.devicePixelRatio);
+
+ for (var i = 0; i < files.length; i++) {
+ var file = files[i];
+ // 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,
+ x: width,
+ y: height,
+ requesttoken: requestToken
+ };
+ imageUrl = SlideShow.buildGalleryUrl('preview', '', params);
+ downloadUrl = SlideShow.buildGalleryUrl('download', '', params);
+
+ images.push({
+ name: file.name,
+ path: dir + file.name,
+ mimeType: file.mimetype,
+ url: imageUrl,
+ downloadUrl: downloadUrl
+ });
+ }
+ }
+ for (i = 0; i < images.length; i++) {
+ //console.log("Images in the slideshow : ", images[i]);
+ if (images[i].name === filename) {
+ start = i;
+ }
+ }
+ var slideShow = new SlideShow($('#slideshow'), images);
+ slideShow.onStop = function () {
+ location.hash = '';
+ };
+ slideShow.init();
+ slideShow.show(start);
+ });
+ };
+
+ 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) {
+ //console.log("enabledPreviewProviders: ", mediaTypes);
+ SlideShow.mediaTypes = mediaTypes;
+
+ // We only want to create slideshows for supported media types
+ for (var i = 0, keys = Object.keys(mediaTypes); i < keys.length; i++) {
+ // Each click handler gets the same function and images array and
+ // is responsible to load the slideshow
+ prepareFileActions(keys[i]);
+ OCA.Files.fileActions.setDefault(keys[i], 'View');
+ }
+ });
+}); \ No newline at end of file