1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* global OC, OCA, FileList, $, t */
var GalleryButton = {};
GalleryButton.isPublic = false;
GalleryButton.button = {};
GalleryButton.url = null;
GalleryButton.appName = 'galleryplus';
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(/^\//, ''));
GalleryButton.hijackShare();
} 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;
};
GalleryButton.hijackShare = function () {
var target = OC.Share.showLink;
OC.Share.showLink = function () {
var r = target.apply(this, arguments);
if (!$('#linkSwitchButton').length) {
var linkSwitchButton = '<a class="button" id="linkSwitchButton">' +
t(GalleryButton.appName, 'Show Gallery link') + '</a>';
$('#linkCheckbox+label').after(linkSwitchButton);
}
$("#linkSwitchButton").toggle(function () {
$(this).text("Show Files link");
$('#linkText').val($('#linkText').val().replace('index.php/s/', 'index.php/apps/' +
GalleryButton.appName + '/s/'));
}, function () {
$(this).text("Show Gallery link");
$('#linkText').val($('#linkText').val().replace('index.php/apps/' +
GalleryButton.appName + '/s/', 'index.php/s/'));
});
$('#linkCheckbox').change(function () {
if (this.checked) {
$('#linkSwitchButton').show();
} else {
$('#linkSwitchButton').hide();
}
});
return r;
};
};
$(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);
}
}
);
|