Sha256: ab73e741fc5b63fa21da5463e7d043c615321ed526b509e63d7b3f6948094867

Contents?: true

Size: 1.6 KB

Versions: 40

Compression:

Stored size: 1.6 KB

Contents

<p>
  <div class="uikit-fileupload">
    <input id="{{ include.id }}" type="file" role="button" multiple/>
    <label class="uikit-btn" for="{{ include.id }}"><span>{{ include.label }}</span></label>
  </div>
</p>

<script>
  function formatBytes(bytes,decimals) {
     if (bytes == 0) return '0 Bytes';
     var k = 1000,
         dm = decimals || 2,
         sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
         i = Math.floor(Math.log(bytes) / Math.log(k));
     return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
  }

  function saveFileData(files) {
    var fileData = Array.prototype.map.call(files, function(file) {
      var [name, ext] = file.name.split('.');

      return {
        name: name,
        ext: ext,
        size: formatBytes(file.size)
      };
    });

    localStorage.setItem('form.files', JSON.stringify(fileData));
  }

  Array.prototype.forEach.call(document.querySelectorAll('.uikit-fileupload input'), function(input) {
    var label	= input.nextElementSibling;
    var labelVal = label.innerHTML;

    input.addEventListener('change', function(e) {
      var fileName = '';

      if(this.files && this.files.length > 1)
        fileName = (this.files.length + ' files selected');
      else
        fileName = e.target.value.split('\\').pop();

      if(fileName)
        label.querySelector('span').innerHTML = fileName;
      else
        label.innerHTML = labelVal;

      label.classList.add("uikit-btn--tertiary")

      saveFileData(this.files);
      document.getElementById('nextButton').classList.remove("uikit-btn--tertiary");
    });
  });
</script>

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
dta_rapid-1.6.2 _includes/buttons/upload-button.html
dta_rapid-1.6.1 _includes/buttons/upload-button.html
dta_rapid-1.6.0 _includes/buttons/upload-button.html
dta_rapid-1.5.12 _includes/buttons/upload-button.html
dta_rapid-1.4.12 _includes/buttons/upload-button.html
dta_rapid-1.4.11 _includes/buttons/upload-button.html
dta_rapid-1.4.10 _includes/buttons/upload-button.html
dta_rapid-1.4.9 _includes/buttons/upload-button.html
dta_rapid-1.4.8 _includes/buttons/upload-button.html
dta_rapid-1.4.7 _includes/buttons/upload-button.html
dta_rapid-1.4.6 _includes/buttons/upload-button.html
dta_rapid-1.4.5 _includes/buttons/upload-button.html
dta_rapid-1.4.4 _includes/buttons/upload-button.html
dta_rapid-1.4.3 _includes/buttons/upload-button.html
dta_rapid-1.4.2 _includes/buttons/upload-button.html
dta_rapid-1.4.1 _includes/buttons/upload-button.html
dta_rapid-1.4.0 _includes/buttons/upload-button.html
dta_rapid-1.3.11 _includes/buttons/upload-button.html
dta_rapid-1.3.10 _includes/buttons/upload-button.html
dta_rapid-1.3.9 _includes/buttons/upload-button.html