blob: fe662a6e7e7d0d741ddc3da64e94339766e64971 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/base/units/size_in_bytes.html">
<polymer-element name="tr-b-u-size-in-bytes-span">
<template>
<style>
:host {
display: flex;
flex-direction: row;
align-items: center;
}
</style>
<span id="content"></span>
</template>
<script>
'use strict';
Polymer({
ready: function() {
this.$.content.textContent = String.fromCharCode(9888);
this.numBytes_ = undefined;
},
get numBytes() {
return this.numBytes_;
},
set numBytes(numBytesOrSizeInBytes) {
if (numBytesOrSizeInBytes instanceof tr.b.units.SizeInBytes)
this.numBytes_ = numBytesOrSizeInBytes.numBytes;
else
this.numBytes_ = numBytesOrSizeInBytes;
var numBytes = this.numBytes;
var signPrefix = '';
if (numBytes < 0) {
signPrefix = '-';
numBytes = -numBytes;
}
var unitPrefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti'];
var i = 0;
while (numBytes >= 1024 && i < unitPrefixes.length - 1) {
numBytes /= 1024;
i++;
}
var sizeString =
signPrefix + numBytes.toFixed(1) + ' ' + unitPrefixes[i] + 'B';
this.$.content.textContent = sizeString;
},
get stringContent() {
return this.$.content.textContent;
}
});
</script>
</polymer-element>