This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
icon.js
155 lines (127 loc) · 3.09 KB
/
icon.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
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
/* global ConfirmDialog */
/* global GridItem */
/* global LazyLoader */
/* global UrlHelper */
(function(exports) {
var _ = navigator.mozL10n.get;
/**
* Represents a single app icon on the homepage.
*/
function Icon(app, entryPoint) {
this.app = app;
this.entryPoint = entryPoint;
this.detail = {
type: 'app',
manifestURL: app.manifestURL,
entryPoint: entryPoint,
index: 0
};
app.ondownloadapplied = function(event) {
this.displayIcon();
}.bind(this);
}
Icon.prototype = {
__proto__: GridItem.prototype,
/**
* Returns the height in pixels of each icon.
*/
get pixelHeight() {
return app.zoom.gridItemHeight;
},
/**
* Width in grid units for each icon.
*/
gridWidth: 1,
get name() {
var name = this.descriptor.name;
var userLang = document.documentElement.lang;
if (name[userLang]) {
return name[userLang];
}
return name;
},
get icon() {
if (!this.descriptor.icons) {
return '';
}
var lastIcon = 0;
for (var i in this.descriptor.icons) {
if (i > lastIcon) {
lastIcon = i;
}
}
var icon = this.descriptor.icons[lastIcon];
// Handle relative URLs
if (!UrlHelper.hasScheme(icon)) {
var a = document.createElement('a');
a.href = this.app.origin;
icon = a.protocol + '//' + a.host + icon;
}
return icon;
},
get descriptor() {
var manifest = this.app.manifest || this.app.updateManifest;
if (this.entryPoint) {
return manifest.entry_points[this.entryPoint];
}
return manifest;
},
get identifier() {
var identifier = [this.app.manifestURL];
if (this.entryPoint) {
identifier.push(this.entryPoint);
}
return identifier.join('-');
},
/**
* Returns true if this app is removable.
*/
isRemovable: function() {
return this.app.removable;
},
/**
* Launches the application for this icon.
*/
launch: function() {
if (this.entryPoint) {
this.app.launch(this.entryPoint);
} else {
this.app.launch();
}
},
/**
* Uninstalls the application.
*/
remove: function() {
var nameObj = {
name: this.name
};
LazyLoader.load([
'/shared/js/confirm.js',
'/shared/style/animations.css',
'/shared/style/confirm.css',
document.getElementById('confirmation-message')
],
function() {
ConfirmDialog.show(_('delete-title', nameObj),
_('delete-body', nameObj),
{
title: _('cancel'),
callback: function _cancel() {
ConfirmDialog.hide();
}
},
{
title: _('delete'),
isDanger: true,
callback: function _confirm() {
ConfirmDialog.hide();
navigator.mozApps.mgmt.uninstall(this.app);
}.bind(this)
});
}.bind(this));
}
};
exports.Icon = Icon;
}(window));