代码拉取完成,页面将自动刷新
define(["avalon", "avalon.button"], function(avalon) {
var widget = avalon.ui.spinner = function(element, data, vmodels) {
var $element = avalon(element),options = data.spinnerOptions,
model, el
var fragment = document.createDocumentFragment()
//这才是真正的UI
var span = document.createElement("span")
span.className = "ui-spinner ui-widget ui-widget-content ui-corner-all"
span.innerHTML = '<a class="ui-spinner-button ui-spinner-up ui-corner-tr" ms-widget="button" data-button-corner-class="false" data-button-primary="ui-icon ui-icon-triangle-1-n">▲</a>' +
'<a class="ui-spinner-button ui-spinner-down ui-corner-br" ms-widget="button" data-button-corner-class="false" data-button-primary="ui-icon ui-icon-triangle-1-s" >▼</a>'
$element.addClass("ui-spinner-input")
element.autocomplete = "off"
model = avalon.define(data.spinnerId, function(vm) {
vm.min = options.min
avalon.mix(vm, options)
vm.addNumber = function(e) {
e.preventDefault()
vm.value += vm.step
if (vm.value > vm.max) {
vm.value = vm.max
}
}
vm.reduceNumber = function(e) {
e.preventDefault()
vm.value -= vm.step
if (vm.value < vm.min) {
vm.value = vm.min
}
}
})
avalon.nextTick(function() {
element.parentNode.insertBefore(span, element.nextSibling)
fragment.appendChild(element)
var buttons = []
while (el = span.firstChild) {
if (el.tagName === "A") {
buttons.push(el)
}
fragment.appendChild(el)
}
element.setAttribute("ms-attr-value", "value")
element = span//偷天换日
buttons[0].setAttribute("ms-click", "addNumber")
buttons[1].setAttribute("ms-click", "reduceNumber")
element.appendChild(fragment)
avalon.scan(element, [model].concat(vmodels))
})
return model
}
widget.defaults = {
value: 0,
min: 1 << 31,
max: Infinity,
step: 1
}
return avalon
})
/*
<input ms-ui="spinner" name="value" />
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。