Sha256: ef82e261daa7608ff01b3af2850537861ab2f8c97b92f30e66ac1d834bd8b9bd

Contents?: true

Size: 906 Bytes

Versions: 5

Compression:

Stored size: 906 Bytes

Contents

if(window.Resizing === undefined) { window.Resizing = {} }
if(window.Resizing.Rails === undefined) { window.Resizing.Rails = {} }

// Usage
// min = 0
// max = 100
// bar = new Resizing.Rails.ProgressBar(document.querySelector('...'), min, max)
// bar.setCurrent(20)
//

class ProgressBar {
  constructor(element, min, max) {
    this.element = element
    this.current = this.min = min
    this.max = max
  }

  setCurrent(value) {
    this.current = value
    this.applyStyle()
  }

  applyStyle() {
    let percentage = Math.floor(this.current / (this.max - this.min) * 100)
    this.element.style = `width: ${percentage}%;`
    this.element.setAttribute('aria-valuenow', this.current)
    this.element.setAttribute('aria-valuemin', this.min)
    this.element.setAttribute('aria-valuemax', this.max)
    this.element.textContent = `${percentage}%`
  }
}

window.Resizing.Rails.ProgressBar = ProgressBar

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
resizing-rails-0.4.1 app/assets/javascripts/resizing/rails/progressbar.js
resizing-rails-0.4.0 app/assets/javascripts/resizing/rails/progressbar.js
resizing-rails-0.3.0 app/assets/javascripts/resizing/rails/progressbar.js
resizing-rails-0.2.0 app/assets/javascripts/resizing/rails/progressbar.js
resizing-rails-0.1.0.pre2 app/assets/javascripts/resizing/rails/progressbar.js