Sha256: 16465380db3d3bf7fb6c834ef8e56be83d38c489c51b3c0896a25800e4ef09af

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

window.Resizing ||= {}
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

1 entries across 1 versions & 1 rubygems

Version Path
resizing-rails-0.1.0.pre app/assets/javascripts/resizing/rails/progressbar.js