Passed
Pull Request — master (#3805)
by
unknown
17:20
created

themes/default/scripts/desktop-notify.js   A

Complexity

Total Complexity 9
Complexity/F 2.25

Size

Lines of Code 36
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 9
mnd 5
bc 5
fnc 4
bpm 1.25
cpm 2.25
noi 3
1
/*!
2
 * @name      ElkArte Forum
3
 * @copyright ElkArte Forum contributors
4
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
5
 *
6
 * @version 1.1.7
7
 *
8
 * This bits acts as middle-man between the notify (above) and the ElkNotifications
9
 * providing the interface required by the latter.
10
 */
11
12
(function () {
13
	var ElkDesktop = (function (opt) {
14
		'use strict';
15
		opt = (opt) ? opt : {};
16
17
		var send = function (request) {
18
			if (request.desktop_notifications.new_from_last > 0) {
19
				if (hasPermissions(request))
20
				{
21
					Push.create(request.desktop_notifications.title, {
0 ignored issues
show
Bug introduced by
The variable Push seems to be never declared. If this is a global, consider adding a /** global: Push */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
22
						body: request.desktop_notifications.message,
23
						icon: opt.icon,
24
						link: request.desktop_notifications.link
25
					});
26
				}
27
			}
28
		};
29
30
		var hasPermissions = function () {
31
			if (Push.Permission.has())
0 ignored issues
show
Bug introduced by
The variable Push seems to be never declared. If this is a global, consider adding a /** global: Push */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
				return true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
33
34
			if (Push.Permission.get() === "default") {
35
				return Push.Permission.request();
36
			}
37
38
			return false;
39
		};
40
41
		return {
42
			send: send
43
		};
44
	});
45
46
	this.ElkDesktop = ElkDesktop;
47
})();
48