forked from RubyLouvre/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchur.html
67 lines (60 loc) · 1.82 KB
/
archur.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>arthur.js</title>
<script type="text/javascript" src="../dist/avalon.js"></script>
</head>
<body>
<div id="aaa"></div>
<script>
function heredoc(fn) {
return fn.toString().replace(/^[^\/]+\/\*!?\s?/, '').
replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*</g, '><')
}
var textProp = 'textContent' in document ? 'textContent': 'innerText'
function fireClick(el) {
if (el.click) {
el.click()
}else {
//https://developer.mozilla.org/samples/domref/dispatchEvent.html
var evt = document.createEvent('MouseEvents')
evt.initMouseEvent('click', true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
!el.dispatchEvent(evt);
}
}
function expect(a){
return {
toBe:function(b){
console.log(a, b, a === b)
}
}
}
var div = document.getElementById('aaa')
div.innerHTML = heredoc(function () {
/*
<input type='radio' ms-controller='attr1' ms-attr='{checked:@a}' >
*/
})
vm = avalon.define({
$id: 'attr1',
a: true
})
avalon.scan(div)
var el = div.children[0]
expect(el.checked).toBe(true)
console.log(' 第一次求值 ',el.nodeName)
vm.a = false
setTimeout(function () {
expect(el.checked).toBe(false)
console.log(' 第2次求值 ')
fireClick(div.children[0])
setTimeout(function () {
expect(el.checked + '1').toBe('true1')
console.log(' 第3次求值 ')
}, 1000)
}, 100)
</script>
</body>
</html>