/
mvc.html
105 lines (105 loc) · 2.81 KB
/
mvc.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
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en:us'>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>DevShop.Me :: MVC Pattern</title>
<style>
</style>
<script type="text/javascript" src="devshop.js"></script>
<script type="text/javascript">
var Echo={
onKeyUp:function(msg){
document.getElementById('echo').innerHTML=msg;
}
};
var Mirror={
onKeyUp:function(msg){
var arr=msg.split('');
var msg='';
if(arr.length>0)
for(var x=arr.length-1;x>=0;x--)
msg+=arr[x];
document.getElementById('mirror').innerHTML=msg;
}
};
var DataProxy=DevShop.SingletonFactory({
extend : DevShop.Proxy,
implement : DevShop.ProxyInterface,
instance : {
NAME:"DataProxy"
}
});
var StartUpCmd=DevShop.SingletonFactory({
implement : DevShop.CommandInterface,onRegister:function(){alert('y');},
instance : {
execute:function(notification){console.log(notification.name);
this.facade.registerProxy(DataProxy);
this.facade.registerMediator(UIMediator);
}
}
});
var KeyUpCmd=DevShop.SingletonFactory({
implement : DevShop.CommandInterface,
instance : {
execute:function(notification){console.log(notification.name);
var msg=this.facade.retrieveProxy(DataProxy.NAME).getData();
Echo.onKeyUp(msg);
Mirror.onKeyUp(msg);
}
}
});
var UIMediator=DevShop.SingletonFactory({
extend : DevShop.Mediator,
implement : DevShop.MediatorInterface,
instance : {
NAME:"UIMediator",
listNotificationInterests:function(){
return [this.facade.ON_KEYUP];
},
handleNotification:function(){
switch(this.notification.name){
case this.facade.ON_KEYUP:
this.facade.retrieveProxy(DataProxy.NAME).setData(this.notification.body);
this.facade.sendNotification(this.facade.CMD_KEYUP);
break;
default:
break;
}
}
}
});
var UI=DevShop.SingletonFactory({
extend:DevShop.Facade,
instance:{
ON_KEYUP:"ON_KEYUP",
CMD_KEYUP:"CMD_KEYUP",
initialize:function(){
this.initializeFacade(this);
this.registerCommand(this.CMD_STARTUP,StartUpCmd);
this.registerCommand(this.CMD_KEYUP,KeyUpCmd);
this.sendNotification(this.CMD_STARTUP);
},
onKeyUp:function(){
this.sendNotification(this.ON_KEYUP,document.getElementById('box').value);
}
}
});
</script>
</head>
<body>
<form>
<table>
<tr>
<td>Type in this box:</td>
<td><input onkeyup="UI.onKeyUp()" type="text" id="box" name="box" value="" size="50"/></td>
</tr>
<tr>
<td>Echo:</td><td><div id="echo"></div></td>
</tr>
<tr>
<td>Mirror:</td><td><div id="mirror"></div></td>
</tr>
</table>
</form>
</body>
</html>