18
var _prevIndicators = [];
19
* WARNING: this is only kept here for backward compatibility reasons.
20
* This needs to be as soon as the individual scripts are SRUed and
21
* updated to use the latest mechanism
23
var _previousIndicators = [];
19
24
function showIndicators(list) {
20
if (list.length == _prevIndicators.length) {
22
for (var i = 0; i < list.length; i++) {
23
if (list[i].name != _prevIndicators[i].name)
25
if (list[i].count != _prevIndicators[i].count)
25
if (list.length == _previousIndicators.length) {
27
for (var i = 0; i < list.length; i++) {
28
if (list[i].name != _previousIndicators[i].name)
30
if (list[i].count != _previousIndicators[i].count)
31
_prevIndicators = list;
36
_previousIndicators = list;
32
37
Unity.MessagingIndicator.clearIndicators();
33
38
for (var i = 0; i < list.length; i++) {
34
Unity.MessagingIndicator.showIndicator(list[i].name, { count: list[i].count,
35
callback: list[i].callback });
39
Unity.MessagingIndicator.showIndicator(list[i].name, { count: list[i].count,
40
callback: list[i].callback });
45
return str.replace(/^\s+|\s+$/g, "");
48
var KEY_NAME = '____unity_indicators_sync';
49
function Indicators(getCounters, combineFromMultipleTabs) {
50
this._init(getCounters, combineFromMultipleTabs);
53
Indicators.prototype = {
54
_prevIndicators: null,
58
_init: function(getCounters, combineFromMultipleTabs) {
60
this._timestamp = new Date();
61
this._prevIndicators = [];
62
this._getCountersCb = getCounters;
63
this._combineFromMultipleTabs = combineFromMultipleTabs;
65
window.addEventListener('blur', this._onBlur.bind(this));
66
window.addEventListener('focus', this._onFocus.bind(this));
68
setInterval(this._updateIndicators.bind(this), 8000);
69
this._updateIndicators(true);
75
_onFocus: function() {
76
this._timestamp = new Date();
77
this.visited(this._currentLabel);
80
_updateTotal: function(total) {
81
if (this._combineFromMultipleTabs) {
85
Unity.Launcher.setCount(Number(total));
87
Unity.Launcher.clearCount();
91
_updateIndicators: function(firstRun) {
92
var state = localStorage.getItem(KEY_NAME);
93
var updateState = false;
96
var list = this._getCountersCb();
102
if (!this._combineFromMultipleTabs) {
103
state = JSON.parse(state);
105
if (state.timestamp > this._timestamp) {
106
this._timestamp = state.timestamp;
107
this._prevIndicators = state.prevIndicators;
108
this._last = state.lastValue;
116
if (!firstRun && !this._forceUpdate && list.length == this._prevIndicators.length) {
118
for (var i = 0; i < list.length; i++) {
119
if (list[i].name != this._prevIndicators[i].name)
121
if (list[i].count != this._prevIndicators[i].count)
128
this._forceUpdate = false;
131
if (!this._combineFromMultipleTabs) {
132
Unity.MessagingIndicator.clearIndicators();
134
for (var i = 0; i < list.length; i++) {
136
if (!this._last[list[i].name]) {
137
this._last[list[i].name] = 0;
139
if (this._last[list[i].name]) {
140
if (this._last[list[i].name] < Number(list[i].count)) {
141
count = Number(list[i].count) - this._last[list[i].name];
146
this._last[list[i].name] = list[i].count;
149
if (this._combineFromMultipleTabs) {
150
Unity.MessagingIndicator.clearIndicator(list[i].name);
157
Unity.MessagingIndicator.showIndicator(list[i].name, { count: count,
158
callback: list[i].callback });
160
this._last[list[i].name] = Number(list[i].count);
164
this._updateTotal(total);
166
this._prevIndicators = list;
171
localStorage.setItem(KEY_NAME, JSON.stringify(state));
174
setTimeout((function () {this._updateIndicators(firstRun)}).bind(this), 500);
178
_saveState: function() {
179
localStorage.setItem(KEY_NAME, JSON.stringify({
180
timestamp: new Date(),
181
prevIndicators: this._prevIndicators,
182
lastValue: this._last
186
visited: function(labelName) {
187
this._currentLabel = labelName;
189
for (var i = 0; i < this._prevIndicators.length; i++) {
190
if (this._prevIndicators[i].name == labelName) {
191
count = this._prevIndicators[i].count;
194
this._forceUpdate = true;
195
this._last[labelName] = count;
197
this._updateIndicators(false);
40
202
* On Chrommium v18 (and maybe earlier versions) the click() function