/
view_event_propagation.js
87 lines (75 loc) 路 2.56 KB
/
view_event_propagation.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var win = Titanium.UI.currentWindow;
win.backgroundColor = '#13386c';
win.name = "window";
var a = Ti.UI.createView({borderColor:'#133899',borderWidth:6,borderRadius:2,backgroundColor:'orange',width:100,height:100,top:10,name:"view a"});
var b = Ti.UI.createView({borderColor:'#133899',borderWidth:6,borderRadius:2,backgroundColor:'purple',width:100,height:100,top:115,right:40,name:"view b"});
var c = Ti.UI.createView({borderColor:'#133899',borderWidth:6,borderRadius:2,backgroundColor:'red',width:100,height:100,top:115,left:40,name:"view c"});
var d = Ti.UI.createView({borderColor:'#133899',borderWidth:6,borderRadius:2,backgroundColor:'cyan',width:100,height:100,top:220,name:"view d"});
a.add(Ti.UI.createLabel({name:"label a",color:'white',text:'A',height:'auto',width:'auto',font:{fontSize:48,fontWeight:'bold',fontFamily:'Helvetica Neue'}}));
b.add(Ti.UI.createLabel({name:"label b",color:'white',text:'B',height:'auto',width:'auto',font:{fontSize:48,fontWeight:'bold',fontFamily:'Helvetica Neue'}}));
c.add(Ti.UI.createLabel({name:"label c",color:'white',text:'C',height:'auto',width:'auto',font:{fontSize:48,fontWeight:'bold',fontFamily:'Helvetica Neue'}}));
d.add(Ti.UI.createLabel({name:"label d",color:'white',text:'D',height:'auto',width:'auto',font:{fontSize:48,fontWeight:'bold',fontFamily:'Helvetica Neue'}}));
var l = Ti.UI.createLabel({
color:'white',
font:{fontSize:14,fontWeight:'bold',fontFamily:'Helvetica Neue'},
bottom:5,
textAlign:'center',
text:'click anywhere',
height:'auto',
width:'auto'
});
var l2 = Ti.UI.createLabel({
color:'white',
font:{fontSize:14,fontFamily:'Helvetica Neue'},
bottom:25,
textAlign:'center',
text:'',
height:'auto',
width:'auto'
});
win.add(a);
win.add(b);
win.add(c);
win.add(d);
win.add(l);
win.add(l2);
function clear(o)
{
var t = o.text;
setTimeout(function()
{
if (o.text == t)
{
o.text = "";
}
},1000);
}
win.addEventListener('click',function(ev)
{
l2.text = "window: You clicked on " +ev.source.name;
clear(l2);
});
a.addEventListener('click',function(ev)
{
l.text = "view: You clicked on " +ev.source.name;
Ti.API.info('Clicked: '+ev.source.name);
clear(l);
});
b.addEventListener('click',function(ev)
{
l.text = "view: You clicked on " +ev.source.name;
Ti.API.info('Clicked: '+ev.source.name);
clear(l);
});
c.addEventListener('click',function(ev)
{
l.text = "view: You clicked on " +ev.source.name;
Ti.API.info('Clicked: '+ev.source.name);
clear(l);
});
d.addEventListener('click',function(ev)
{
l.text = "view: You clicked on " +ev.source.name;
Ti.API.info('Clicked: '+ev.source.name);
clear(l);
});