forked from RubyLouvre/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avalon.progressbar.js
34 lines (34 loc) · 1.22 KB
/
avalon.progressbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
define(["avalon"], function(avalon) {
var defaults = {
value: 0
}
avalon.ui.progressbar = function(element, id, vmodels, opts) {
var $element = avalon(element),
model, el
//处理配置
var options = avalon.mix({}, defaults, opts, $element.data())
$element.addClass("ui-progressbar ui-widget ui-widget-content ui-corner-all")
element.innerHTML = '<div class="ui-progressbar-value ui-widget-header ui-corner-left ui-corner-right" ms-bind-value="updateValue" style="width:' + options.value + '%;"></div>'
var fragment = document.createDocumentFragment()
while (el = element.firstChild) {
fragment.appendChild(el)
}
model = avalon.define(id, function(vm) {
vm.value = options.value
vm.updateValue = function(v) {
if (isFinite(v)) {
this.style.width = v + "%"
}
}
})
avalon.nextTick(function() {
element.appendChild(fragment)
avalon.scan(element, [model].concat(vmodels))
})
return model
}
return avalon
})
/*
<div ms-ui="progressbar" data-value="37" style="width:50%"></div>
*/