Passed
Pull Request — development (#3766)
by Elk
06:51
created

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

Complexity

Total Complexity 10
Complexity/F 2

Size

Lines of Code 48
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 27
mnd 5
bc 5
fnc 5
dl 0
loc 48
rs 10
bpm 1
cpm 2
noi 3
c 0
b 0
f 0
1
/*!
2
 * @package   ElkArte Forum
3
 * @copyright ElkArte Forum contributors
4
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
5
 *
6
 * @version 2.0 dev
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
{
14
	let ElkDesktop = (function (opt)
15
	{
16
		'use strict';
17
		opt = (opt) ? opt : {};
18
19
		let send = function (request)
20
		{
21
			if (request.desktop_notifications.new_from_last > 0)
22
			{
23
				if (hasPermissions(request))
24
				{
25
					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...
26
						body: request.desktop_notifications.message,
27
						icon: opt.icon,
28
						link: request.desktop_notifications.link, // Used by mobile devices
29
						onClick: function() {
30
							window.focus();
31
							this.close();
32
						}
33
					});
34
				}
35
			}
36
		};
37
38
		let hasPermissions = function ()
0 ignored issues
show
Unused Code introduced by
The variable hasPermissions seems to be never used. Consider removing it.
Loading history...
39
		{
40
			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...
41
			{
42
				return true;
43
			}
44
45
			if (Push.Permission.get() === "default")
46
			{
47
				return Push.Permission.request();
48
			}
49
50
			return false;
51
		};
52
53
		return {
54
			send: send
55
		};
56
	});
57
58
	this.ElkDesktop = ElkDesktop;
59
})();
60