Issues (263)

js/gallerybutton.js (2 issues)

1
/**
2
 * Nextcloud - Gallery
3
 *
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Olivier Paroz <[email protected]>
9
 *
10
 * @copyright Olivier Paroz 2017
11
 */
12
/* global OC, OCA, FileList, $, t */
13
var GalleryButton = {};
14
GalleryButton.isPublic = false;
15
GalleryButton.button = {};
16
GalleryButton.url = null;
17
18
/**
19
 * Rebuilds the Gallery URL every time the files list has changed
20
 */
21
GalleryButton.onFileListUpdated = function () {
22
	"use strict";
23
	var fileList;
24
25
	if (GalleryButton.isPublic) {
26
		fileList = OCA.Sharing.PublicApp.fileList;
27
	} else {
28
		fileList = FileList;
29
	}
30
31
	GalleryButton.buildGalleryUrl(fileList.getCurrentDirectory().replace(/^\//, ''));
32
};
33
34
/**
35
 * Builds the URL which will load the exact same folder in Gallery
36
 *
37
 * @param dir
38
 */
39
GalleryButton.buildGalleryUrl = function (dir) {
40
	"use strict";
41
	var params = {};
42
	var tokenPath = '';
43
	var sharingTokenElement = $('#sharingToken');
44
	var token = (sharingTokenElement.val()) ? sharingTokenElement.val() : false;
45
	if (token) {
46
		params.token = token;
47
		tokenPath = 's/{token}';
48
	}
49
	GalleryButton.url =
50
		OC.generateUrl('apps/gallery/' + tokenPath, params) + '#' + encodeURIComponent(dir);
51
};
52
53
$(document).ready(function () {
54
		"use strict";
55
		if ($('#body-login').length > 0) {
56
			return true; //deactivate on login page
57
		}
58
59
		if ($('html').is('.ie8')) {
60
			return true; //deactivate in IE8
61
		}
62
63
		if ($('#isPublic').val()) {
64
			GalleryButton.isPublic = true;
65
		}
66
67
		if ($('#filesApp').val()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if $("#filesApp").val() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
68
69
			$('#fileList').on('updated', GalleryButton.onFileListUpdated);
70
71
			// Button for opening files list as gallery view
72
			GalleryButton.button =
73
				$('<div id="gallery-button" class="button view-switcher">' +
74
						'<div id="button-loading" class="hidden"></div>' +
75
					'<span class="icon-toggle-pictures"></span>' +
76
					'</div>');
77
78
			GalleryButton.button.click(function () {
79
				$(this).children('span').addClass('hidden');
80
				$(this).children('#button-loading').removeClass('hidden').addClass('icon-loading-small');
81
				window.location.href = GalleryButton.url;
82
			});
83
84
			$('#controls').append(GalleryButton.button);
0 ignored issues
show
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
85
		}
86
	}
87
);
88