forked from mozilla-b2g/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
90 lines (78 loc) · 2.45 KB
/
Copy pathutils.js
File metadata and controls
90 lines (78 loc) · 2.45 KB
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
function debug(...args) {
if (!DEBUG)
return;
if (!debug.startTime)
debug.startTime = Date.now();
args.unshift('[Locked Content]', Date.now() - debug.startTime);
console.log.apply(console, args);
}
function $(id) { return document.getElementById(id); }
function _(id, args) {
return navigator.mozL10n.get(id, args);
}
// Show a dialog with one or two buttons
function showDialog(options) {
var dialog = document.createElement('form');
dialog.setAttribute('role', 'dialog');
dialog.dataset.type = 'confirm';
var section = document.createElement('section');
dialog.appendChild(section);
// Display an optional title
if (options.title) {
var title = document.createElement('h1');
title.textContent = options.title;
section.appendChild(title);
}
// Display the dialog message
var msg = document.createElement('p');
msg.textContent = options.message;
section.appendChild(msg);
// If there are details, display those in a separate, smaller paragraph
if (options.details) {
var details = document.createElement('p');
var small = document.createElement('small');
small.textContent = options.details;
details.appendChild(small);
section.appendChild(details);
}
// Now the buttons
var menu = document.createElement('menu');
dialog.appendChild(menu);
// Add the cancel button if there is one
if (options.cancelCallback) {
var cancelButton = document.createElement('button');
menu.appendChild(cancelButton);
cancelButton.textContent = options.cancelText || _('cancel');
cancelButton.onclick = function(e) {
close(e);
options.cancelCallback();
};
}
if (options.okCallback) {
var okButton = document.createElement('button');
menu.appendChild(okButton);
okButton.textContent = options.okText || _('ok');
if (options.danger) {
okButton.classList.add('danger'); // scary red color
}
else if (!options.cancelCallback) {
okButton.classList.add('recommend'); // default safe color
}
okButton.onclick = function(e) {
close(e);
options.okCallback();
};
}
// If there is only one button, make it full-size
if (okButton && !cancelButton)
okButton.classList.add('full');
if (cancelButton && !okButton)
cancelButton.classList.add('full');
// show the dialog
document.body.appendChild(dialog);
function close(e) {
document.body.removeChild(dialog);
e.preventDefault();
e.stopPropagation();
}
}