added progress to tab title when not in focus
This commit is contained in:
parent
c13839a522
commit
c38d91db98
@ -1,10 +1,12 @@
|
|||||||
const { bytes } = require('./utils');
|
const { bytes, percent } = require('./utils');
|
||||||
const $ = require('jquery');
|
const $ = require('jquery');
|
||||||
require('jquery-circle-progress');
|
require('jquery-circle-progress');
|
||||||
|
|
||||||
let $progress = null;
|
let $progress = null;
|
||||||
let $percent = null;
|
let $percent = null;
|
||||||
let $text = null;
|
let $text = null;
|
||||||
|
let title = null;
|
||||||
|
let updateTitle = false;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
$percent = $('.percent-number');
|
$percent = $('.percent-number');
|
||||||
@ -17,12 +19,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
size: 158,
|
size: 158,
|
||||||
animation: { duration: 300 }
|
animation: { duration: 300 }
|
||||||
});
|
});
|
||||||
|
title = document.querySelector('title');
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('blur', function() {
|
||||||
|
updateTitle = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('focus', function() {
|
||||||
|
updateTitle = false;
|
||||||
|
return title && (title.textContent = 'Firefox Send');
|
||||||
});
|
});
|
||||||
|
|
||||||
function setProgress(params) {
|
function setProgress(params) {
|
||||||
const percent = params.complete / params.total;
|
const ratio = params.complete / params.total;
|
||||||
$progress.circleProgress('value', percent);
|
$progress.circleProgress('value', ratio);
|
||||||
$percent.text(`${Math.floor(percent * 100)}`);
|
$percent.text(Math.floor(ratio * 100));
|
||||||
|
if (updateTitle) {
|
||||||
|
title.textContent = percent(ratio);
|
||||||
|
}
|
||||||
document.l10n
|
document.l10n
|
||||||
.formatValue('fileSizeProgress', {
|
.formatValue('fileSizeProgress', {
|
||||||
partialSize: bytes(params.complete),
|
partialSize: bytes(params.complete),
|
||||||
|
@ -123,10 +123,17 @@ function bytes(num) {
|
|||||||
return `${nStr}${UNITS[exponent]}`;
|
return `${nStr}${UNITS[exponent]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function percent(ratio) {
|
||||||
|
return LOCALIZE_NUMBERS
|
||||||
|
? ratio.toLocaleString(navigator.languages, { style: 'percent' })
|
||||||
|
: `${Math.floor(ratio * 100)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
const ONE_DAY_IN_MS = 86400000;
|
const ONE_DAY_IN_MS = 86400000;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bytes,
|
bytes,
|
||||||
|
percent,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
arrayToHex,
|
arrayToHex,
|
||||||
hexToArray,
|
hexToArray,
|
||||||
|
Loading…
Reference in New Issue
Block a user