Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove $ from progress.js #628

Merged
merged 4 commits into from
Dec 25, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/ui/progress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'
import { canvas } from '../utils/abilities'
import { tpl } from '../templates'

Expand Down Expand Up @@ -56,9 +55,9 @@ class Circle {

class BaseRenderer {
constructor(el) {
this.element = $(el)
this.element.data('uploadcare-progress-renderer', this)
this.element.addClass('uploadcare--progress')
this.element = document.querySelector(el)
this.element.dataset['uploadcare-progress-renderer'] = this
this.element.classList.add('uploadcare--progress')
}

update() {}
Expand All @@ -67,31 +66,36 @@ class BaseRenderer {
class TextRenderer extends BaseRenderer {
constructor() {
super(...arguments)
this.element.addClass('uploadcare--progress_type_text')
this.element.html(tpl('progress__text'))
this.text = this.element.find('.uploadcare--progress__text')
this.element.classList.add('uploadcare--progress_type_text')
this.element.innerHTML = tpl('progress__text')
this.text = this.element.querySelector('.uploadcare--progress__text')
}

setValue(val) {
val = Math.round(val * 100)
return this.text.html(`${val} %`)
return (this.text.innerHTML = `${val} %`)
}
}

class CanvasRenderer extends BaseRenderer {
constructor() {
super(...arguments)
this.canvasEl = $('<canvas>')
.addClass('uploadcare--progress__canvas')
.get(0)
this.element.addClass('uploadcare--progress_type_canvas')
this.element.html(this.canvasEl)
this.canvasEl = document
.createElement('canvas')
.classList.add('uploadcare--progress__canvas')
this.element.classList.add('uploadcare--progress_type_canvas')
this.element.innerHTML = this.canvasEl
this.setValue(0, true)
}

update() {
var arc, ctx, half, size
half = Math.floor(Math.min(this.element.width(), this.element.height()))
const getWidth = element =>
parseFloat(window.getComputedStyle(element, null).width.replace('px', ''))
const getHeight = element => element.offsetHeight

half = Math.floor(Math.min(getWidth(this.element), getHeight(this.element)))

size = half * 2
if (half) {
if (this.canvasEl.width !== size || this.canvasEl.height !== size) {
Expand Down Expand Up @@ -150,7 +154,7 @@ class CanvasRenderer extends BaseRenderer {

__setValue(val) {
this.val = val
this.element.attr('aria-valuenow', (val * 100).toFixed(0))
this.element.setAttribute('aria-valuenow', (val * 100).toFixed(0));
return this.update()
}

Expand Down