-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
113 lines (98 loc) · 3.2 KB
/
Copy pathindex.js
File metadata and controls
113 lines (98 loc) · 3.2 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
// Famous dependencies
var DOMElement = require('famous/dom-renderables/DOMElement');
var FamousEngine = require('famous/core/FamousEngine');
var Box = require('./Box');
// Boilerplate code to make your life easier
FamousEngine.init();
// UI events are sent up to parent nodes
var scene = FamousEngine.createScene('body');
var rootNode = scene.addChild();
var parent = rootNode.addChild(new Box('parent', 'orange', 0, 0, 900, 500, '0'));
// onReceive catches all UI events that we
// added to the node and all child nodes
parent.onReceive = function(event, payload){
//payload gives access to the node --> payload.node
console.log('onReceive event ' + event + ' payload ' + payload);
if(event==="click"){
var whoWasClicked = payload.node.id;
this.emit(whoWasClicked);
console.log('Click was registered' + whoWasClicked);
this.nodeDomElement.setContent('parent: sent event from my '+whoWasClicked);
this.emit('custom_event', whoWasClicked);
}
}
/****** Child Nodes ******/
/* var daughter = rootNode.addChild(new Box('daughter', 'purple', 0, 0, 250, 250, '3'));
daughter.setAlign(0.5, 0.5)
.setMountPoint(1, 1);
daughter.id = 'daughter';
*/
var daughter = parent.addChild()
.setAlign(1, 1)
.setMountPoint(1, 1)
.setSizeMode('absolute', 'absolute', 'absolute')
.setAbsoluteSize(250, 250);
// id for click event and content
daughter.id = 'daughter';
daughter.el = new DOMElement(daughter, {
content: 'click: '+ daughter.id,
properties:{
'background': 'purple',
'color':'white',
'font-size': '25px'
}
});
// Listen for click on daughter
daughter.addUIEvent('click');
daughter.onReceive = function(event, payload){
if(event==='click'){
console.log('A click happened on the daughter');
daughter.el.setContent('A click happened on the daughter');
} else {
console.log('Daughter heard ' + event);
daughter.el.setContent('Daughter heard ' + event);
}
}
// Listen for custom events from parent
/*
daughter.addComponent({
onReceive: function(event,payload){
console.log('onReceive from daughter' + event + " " + payload);
if(event === 'son'){
console.log('The daugher was notified that son was clicked');
daughter.el.setContent('you clicked my brother');
}
}
});
*/
var son = parent.addChild()
.setAlign(0, 1)
.setMountPoint(0, 1)
.setSizeMode('absolute', 'absolute', 'absolute')
.setAbsoluteSize(250, 250);
// id for click event and content
son.id = 'son';
son.el = new DOMElement(son, {
content: 'click: '+son.id,
properties:{
'background': 'turquoise',
'color':'white',
'font-size': '25px'
}
});
// Listen for click on son
son.addUIEvent('click');
// Listen for custom events from parent
son.addComponent({
onReceive:function(event,payload){
console.log('The son was notified of event');
if(event==='daughter'){
console.log('The son was notified that daughter was clicked');
son.el.setContent('you clicked my sister');
} else {
console.log('Son heard ' + event);
son.el.setContent('Son heard ' + event);
}
}
});