This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
exceptions.js
143 lines (119 loc) · 3.31 KB
/
exceptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* ALA exceptions panel.
*
* @module ExceptionsPanel
* @return {Object}
*/
define([
'panels',
'ala/blur_slider',
'shared/settings_listener',
'shared/settings_helper'
],
function(panels, BlurSlider, SettingsListener, SettingsHelper) {
'use strict';
function ExceptionsPanel() {
this.apps = [];
this.exceptionsList = {};
}
ExceptionsPanel.prototype = {
/**
* Initialize ALA exceptions panel.
*
* @method init
* @constructor
*/
init: function(apps) {
this.panel = document.getElementById('ala-exceptions');
this.apps = apps;
this.appListElement = this.panel.querySelector('#app-list');
// get exception list from settings
SettingsHelper('geolocation.app_settings', {}).get(function(value){
this.exceptionsList = value;
}.bind(this));
this.events();
},
/**
* Register events.
*/
events: function() {
this.panel.addEventListener('pagerendered', this.onBeforeShow.bind(this));
},
/**
* Actions before displaying panel.
* @param event
*/
onBeforeShow: function(event) {
// remove existing entries from application list
var apps = this.appListElement.querySelectorAll('.app-element');
for (var el of apps) {
this.appListElement.removeChild(el);
}
// render app list
this.apps.forEach(function(item, index) {
// remove Privacy Panel application from list
if (item.origin.indexOf('privacy-panel') !== -1) {
return;
}
var type;
var appSettings = this.exceptionsList[item.origin];
if (appSettings) {
switch (appSettings.type) {
case 'user-defined':
type = 'User defined';
break;
case 'blur':
type = BlurSlider.getLabel(appSettings.slider) +' blur';
break;
case 'precise':
type = 'Precise';
break;
case 'no-location':
type = 'No location';
break;
default:
type = appSettings.type;
break;
}
}
var li = this.renderAppItem({
origin: item.origin,
name: item.name,
index: index,
iconSrc: item.iconURL,
type: type
});
this.appListElement.appendChild(li);
}.bind(this));
},
/**
* Render App item.
* @param itemData
* @returns {HTMLElement}
*/
renderAppItem: function(itemData) {
var icon = document.createElement('img');
var item = document.createElement('li');
var link = document.createElement('a');
var name = document.createElement('span');
icon.src = itemData.iconSrc;
name.textContent = itemData.name;
link.classList.add('menu-item');
link.appendChild(icon);
link.appendChild(name);
if (itemData.type) {
var type = document.createElement('small');
type.textContent = itemData.type;
link.appendChild(type);
}
link.addEventListener('click',
function() {
panels.show({ id: 'ala-exception', options: itemData });
});
item.classList.add('app-element');
item.appendChild(link);
return item;
}
};
return new ExceptionsPanel();
});