-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
128 lines (103 loc) · 3.64 KB
/
script.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var app = angular.module("eventApp",[]);
app.controller("parentController",function($scope){
$scope.name="Parent";
$scope.parentMessage = "";
$scope.parentArea = "";
// parent listens to son
$scope.$on('SON_TO_PARENT',function(e,msg){
$scope.WriteMessage("Son",msg);
});
// parent listens to daughter
$scope.$on('DAUGHTER_TO_PARENT',function(e,msg){
$scope.WriteMessage("Daughter",msg);
});
$scope.$on('DAUGHTER_TO_FAMILY',function(e,msg){
$scope.WriteMessage("Daughter",msg);
});
// parent broadcast a msg to all child
$scope.talkToAll = function(){
$scope.WriteMessage("Me",$scope.parentMessage);
$scope.$broadcast('PARENT_TO_ALL',$scope.parentMessage);
};
// parent communicate with son
$scope.talkToSon = function(){
$scope.WriteMessage("Me",$scope.parentMessage);
$scope.$broadcast('PARENT_TO_SON',$scope.parentMessage);
};
// parent communicate with daughter
$scope.talkToDaughter = function(){
$scope.WriteMessage("Me",$scope.parentMessage);
$scope.$broadcast('PARENT_TO_DAUGHTER',$scope.parentMessage);
};
$scope.WriteMessage = function(who,msg){
var message = who+":- "+msg;
$scope.parentArea += message + "\n";
};
});
app.controller("sonController",function($scope,$rootScope){
$scope.name = "Son";
$scope.sonArea = "";
$scope.sonMessage = "";
// son listent to parent
$scope.$on('PARENT_TO_SON',function(e,msg){
$scope.WriteMessage("Daddy",msg);
});
$scope.$on('PARENT_TO_ALL',function(e,msg){
$scope.WriteMessage("Daddy",msg);
});
$scope.$on('DAUGHTER_TO_FAMILY', function(E, msg) {
$scope.WriteMessage("Sister",msg);
});
// son listens to sister
$rootScope.$on('DAUGHTER_TO_BROTHER',function(e,msg){
$scope.WriteMessage("Sister",msg);
});
// son send event to parent
$scope.talkToParent = function(){
$scope.WriteMessage("Me",$scope.sonMessage);
$scope.$emit('SON_TO_PARENT',$scope.sonMessage);
};
// son communicate to sister
$scope.talkToSister = function(){
$scope.WriteMessage("Me",$scope.sonMessage);
$rootScope.$emit('SON_TO_SISTER',$scope.sonMessage);
};
$scope.WriteMessage = function(who,msg){
var message = who + ":- "+msg;
$scope.sonArea += message + "\n";
};
});
app.controller("daughterController",function($scope,$rootScope){
$scope.name = "Daughter";
$scope.daughterArea = "";
$scope.daughterMessage = "";
// daughter listens to parent
$scope.$on('PARENT_TO_DAUGHTER',function(e,msg){
$scope.WriteMessage("Daddy",msg);
});
$scope.$on('PARENT_TO_ALL',function(e,msg){
$scope.WriteMessage("Daddy",msg);
});
// sister listens to brother
$rootScope.$on('SON_TO_SISTER',function(e,msg){
$scope.WriteMessage("Brother",msg);
});
// daughter send event to parent
$scope.talkToParent = function(){
$scope.WriteMessage("Me",$scope.daughterMessage);
$scope.$emit('DAUGHTER_TO_PARENT',$scope.daughterMessage);
};
// daughter communicate to brother
$scope.talkToBrother = function(){
$scope.WriteMessage("Me",$scope.daughterMessage);
$scope.$emit('DAUGHTER_TO_BROTHER',$scope.daughterMessage);
};
$scope.talkToFamily = function(){
$scope.WriteMessage("Me",$scope.daughterMessage);
$scope.$parent.$broadcast('DAUGHTER_TO_FAMILY', $scope.daughterMessage);
};
$scope.WriteMessage = function(who,msg){
var message = who + ":- "+msg;
$scope.daughterArea += message + "\n";
};
});