Skip to content

Commit

Permalink
Displaying filesizes in Mebibyte, gibibyte, etc... now.
Browse files Browse the repository at this point in the history
#changelog #364 #234 #132
  • Loading branch information
enyo committed Dec 7, 2013
1 parent d7f6c41 commit ac6e8f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/dropzone.coffee
Expand Up @@ -654,18 +654,18 @@ class Dropzone extends Em

# Returns a nicely formatted filesize
filesize: (size) ->
if size >= 100000000000
size = size / 100000000000
string = "TB"
else if size >= 100000000
size = size / 100000000
string = "GB"
else if size >= 100000
size = size / 100000
string = "MB"
else if size >= 100
size = size / 100
string = "KB"
if size >= 1024 * 1024 * 1024 * 1024 / 10
size = size / (1024 * 1024 * 1024 * 1024 / 10)
string = "TiB"
else if size >= 1024 * 1024 * 1024 / 10
size = size / (1024 * 1024 * 1024 / 10)
string = "GiB"
else if size >= 1024 * 1024 / 10
size = size / (1024 * 1024 / 10)
string = "MiB"
else if size >= 1024 / 10
size = size / (1024 / 10)
string = "KiB"
else
size = size * 10
string = "b"
Expand Down
12 changes: 6 additions & 6 deletions test/test.coffee
Expand Up @@ -425,15 +425,15 @@ describe "Dropzone", ->
beforeEach ->
file =
name: "test name"
size: 2 * 1000 * 1000
size: 2 * 1024 * 1024
dropzone.options.addedfile.call dropzone, file

describe ".addedFile()", ->
it "should properly create the previewElement", ->
file.previewElement.should.be.instanceof Element

file.previewElement.querySelector("[data-dz-name]").innerHTML.should.eql "test name"
file.previewElement.querySelector("[data-dz-size]").innerHTML.should.eql "<strong>2</strong> MB"
file.previewElement.querySelector("[data-dz-size]").innerHTML.should.eql "<strong>2</strong> MiB"

describe ".error()", ->
it "should properly insert the error", ->
Expand Down Expand Up @@ -720,10 +720,10 @@ describe "Dropzone", ->

it "should convert to KiloBytes, etc.. not KibiBytes", ->

dropzone.filesize(2 * 1024 * 1024).should.eql "<strong>2.1</strong> MB"
dropzone.filesize(2 * 1000 * 1000).should.eql "<strong>2</strong> MB"
dropzone.filesize(2 * 1024 * 1024 * 1024).should.eql "<strong>2.1</strong> GB"
dropzone.filesize(2 * 1000 * 1000 * 1000).should.eql "<strong>2</strong> GB"
# dropzone.filesize(2 * 1000 * 1000).should.eql "<strong>1.9</strong> MiB"
dropzone.filesize(2 * 1024 * 1024).should.eql "<strong>2</strong> MiB"
dropzone.filesize(2 * 1000 * 1000 * 1000).should.eql "<strong>1.9</strong> GiB"
dropzone.filesize(2 * 1024 * 1024 * 1024).should.eql "<strong>2</strong> GiB"

describe "._updateMaxFilesReachedClass()", ->
it "should properly add the dz-max-files-reached class", ->
Expand Down

0 comments on commit ac6e8f8

Please sign in to comment.