|
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 Favico and the ElkNotifications providing the interface |
|
9
|
|
|
* required by the latter. It also handles the menu badge indicators. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
(function() { |
|
13
|
|
|
const ElkFavicon = (function(opt) { |
|
14
|
|
|
|
|
15
|
|
|
opt = (opt) ? opt : {}; |
|
16
|
|
|
|
|
17
|
|
|
// Holds the favico class |
|
18
|
|
|
let favico = new Favico(opt); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
// Set the favicon count indicator on startup |
|
21
|
|
|
const init = function(opt) { |
|
22
|
|
|
if (opt.number > 0) |
|
23
|
|
|
{ |
|
24
|
|
|
// Set the favicon count indicator on startup |
|
25
|
|
|
favico.badge(opt.number); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if (opt.mentions > 0) |
|
29
|
|
|
{ |
|
30
|
|
|
// Set the mentions menu badge indicator on startup |
|
31
|
|
|
document.querySelector('#button_mentions .pm_indicator').innerHTML = opt.mentions; |
|
32
|
|
|
document.querySelector('#button_mentions .pm_indicator').style.display = 'block'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if (opt.pm_unread > 0) |
|
36
|
|
|
{ |
|
37
|
|
|
// Set the personal messages menu badge indicator on startup |
|
38
|
|
|
document.querySelector('#button_pm .pm_indicator').innerHTML = opt.pm_unread; |
|
39
|
|
|
document.querySelector('#button_pm .pm_indicator').style.display = 'block'; |
|
40
|
|
|
} |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
// Update the indicator when new items are added or removed. |
|
44
|
|
|
const send = function(request) { |
|
45
|
|
|
// Determine counts for mentions and personal messages |
|
46
|
|
|
let mentionCount = 0, |
|
47
|
|
|
pmCount = 0; |
|
48
|
|
|
|
|
49
|
|
|
if (typeof request.mentions !== 'undefined') |
|
50
|
|
|
{ |
|
51
|
|
|
mentionCount = parseInt(request.mentions, 10) || 0; |
|
52
|
|
|
} |
|
53
|
|
|
if (typeof request.pm_unread !== 'undefined') |
|
54
|
|
|
{ |
|
55
|
|
|
pmCount = parseInt(request.pm_unread, 10) || 0; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
const total = mentionCount + pmCount; |
|
59
|
|
|
|
|
60
|
|
|
if (total > 0) |
|
61
|
|
|
{ |
|
62
|
|
|
// Update the favicon with the aggregate total |
|
63
|
|
|
favico.badge(total); |
|
64
|
|
|
|
|
65
|
|
|
// Update the mentions menu indicator if present |
|
66
|
|
|
let mentionEl = document.querySelector('#button_mentions .pm_indicator'); |
|
67
|
|
|
if (mentionEl && typeof request.mentions !== 'undefined') |
|
68
|
|
|
{ |
|
69
|
|
|
mentionEl.innerHTML = mentionCount; |
|
70
|
|
|
mentionEl.style.display = mentionCount > 0 ? 'block' : 'none'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
// Update the personal messages menu indicator if present |
|
74
|
|
|
let pmEl = document.querySelector('#button_pm .pm_indicator'); |
|
75
|
|
|
if (pmEl && typeof request.pm_unread !== 'undefined') |
|
76
|
|
|
{ |
|
77
|
|
|
pmEl.innerHTML = pmCount; |
|
78
|
|
|
pmEl.style.display = pmCount > 0 ? 'block' : 'none'; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
else |
|
82
|
|
|
{ |
|
83
|
|
|
favico.reset(); |
|
84
|
|
|
let mentionElement = document.querySelector('#button_mentions .pm_indicator'); |
|
85
|
|
|
if (mentionElement) |
|
86
|
|
|
{ |
|
87
|
|
|
mentionElement.style.display = 'none'; |
|
88
|
|
|
} |
|
89
|
|
|
let pmElement = document.querySelector('#button_pm .pm_indicator'); |
|
90
|
|
|
if (pmElement) |
|
91
|
|
|
{ |
|
92
|
|
|
pmElement.style.display = 'none'; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
}; |
|
96
|
|
|
|
|
97
|
|
|
init(opt); |
|
98
|
|
|
return { |
|
99
|
|
|
send: send |
|
100
|
|
|
}; |
|
101
|
|
|
}); |
|
102
|
|
|
|
|
103
|
|
|
this.ElkFavicon = ElkFavicon; |
|
104
|
|
|
})(); |
|
105
|
|
|
|
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.