-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
222 lines (203 loc) · 9.43 KB
/
index.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Module Pattern Test</title>
<!-- Bootstrap -->
<link href="lib/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<br>
<div class="container ">
<div class="row">
<!-- START: Module 1-->
<div class="col-xs-6 col-lg-4">
<div class="form-horizontal ">
<div class="form-group">
<div class=" col-sm-12 text-center">
<button type="button" class="btn btn-success" id="btn_module1_id">Load module 1</button>
</div>
</div>
</div>
<div class="well">
<h2 class="text-center">Module 1</h2>
<h4>first instance</h4>
<div class="well" id="div_module1_i1_id">
</div>
<div class="form-horizontal ">
<div class="form-group ">
<div class="col-sm-12 ">
<input type="text" class="form-control text-center" id="input_module1_i1_id" disabled="true" placeholder="New value">
</div>
</div>
<div class="form-group">
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module1_showVal1_id" disabled="true">show value</button>
</div>
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module1_setVal1_id" disabled="true">set value</button>
</div>
</div>
</div>
<h4>second instance</h4>
<div class="well" id="div_module1_i2_id">
</div>
<div class="form-horizontal ">
<div class="form-group ">
<div class="col-sm-12 ">
<input type="text" class="form-control text-center" id="input_module1_i2_id" disabled="true" placeholder="New value">
</div>
</div>
<div class="form-group">
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module1_showVal2_id" disabled="true">show value</button>
</div>
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module1_setVal2_id" disabled="true">set value</button>
</div>
</div>
</div>
</div>
</div>
<!-- END: Module 1-->
<!-- BEGIN: Module 2-->
<div class="col-xs-6 col-lg-4">
<div class="form-horizontal ">
<div class="form-group">
<div class=" col-sm-12 text-center">
<button type="button" class="btn btn-success" id="btn_module2_id">Load module 2</button>
</div>
</div>
</div>
<div class="well">
<h2 class="text-center">Module 2</h2>
<h4>first instance</h4>
<div class="well" id="div_module2_i1_id">
</div>
<div class="form-horizontal ">
<div class="form-group ">
<div class="col-sm-12 ">
<input type="text" class="form-control text-center" id="input_module2_i1_id" disabled="true" placeholder="New value">
</div>
</div>
<div class="form-group">
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module2_showVal1_id" disabled="true">show value</button>
</div>
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module2_setVal1_id" disabled="true">set value</button>
</div>
</div>
</div>
<h4>second instance</h4>
<div class="well" id="div_module2_i2_id">
</div>
<div class="form-horizontal ">
<div class="form-group ">
<div class="col-sm-12 ">
<input type="text" class="form-control text-center" id="input_module2_i2_id" disabled="true" placeholder="New value">
</div>
</div>
<div class="form-group">
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module2_showVal2_id" disabled="true">show value</button>
</div>
<div class=" col-sm-6 text-center">
<button type="button" class="btn btn-primary" id="btn_module2_setVal2_id" disabled="true">set value</button>
</div>
</div>
</div>
</div>
</div>
<!-- END: Module 2-->
<!-- BEGIN: Log Module-->
<div class="col-xs-6 col-lg-4">
<div class="text-center">
<h4>LOG</h4>
</div>
<div class="well" id="div_log_id">
</div>
</div>
<!-- END: Log Module-->
</div>
</div>
</body>
</html>
<script src="lib/head.load.js"></script>
<script src="modules/LogModule.js"></script>
<script>
/**
* Module which initializes the other modules
*
* @module InitModules
*/
(function InitModules(){
/**
* initializes the main methods of the module
*
* @method init
*/
var init= function(){
setActions();
};
/**
* sets the actions of the page by adding a listener to each buttons.
* After the buttons were pressed, these are disabled to avoid loading them again
* @method setActions
*/
var setActions=function(){
document.getElementById("btn_module1_id").addEventListener('click',function(){
document.getElementById("btn_module1_id").disabled=true;
loadModule("div_module1_i1_id","input_module1_i1_id","btn_module1_showVal1_id","btn_module1_setVal1_id","Module1");
loadModule("div_module1_i2_id","input_module1_i2_id","btn_module1_showVal2_id","btn_module1_setVal2_id","Module1");
});
document.getElementById("btn_module2_id").addEventListener('click',function(){
document.getElementById("btn_module2_id").disabled=true;
loadModule("div_module2_i1_id","input_module2_i1_id","btn_module2_showVal1_id","btn_module2_setVal1_id","Module2");
loadModule("div_module2_i2_id","input_module2_i2_id","btn_module2_showVal2_id","btn_module2_setVal2_id","Module2");
});
};
/**
* This method loads dynamically and initializes the module, this is done by passing the module's name as a param,
* in addition to be passed the IDs with which will interact.
* @method loadModule
*
* @param divModuleId{String} ID html where the module will work
* @param inputModuleId{String} ID input where a value can be set as a value of a attribute of the module
* @param btnModuleShowValId{String} ID of the button which shows the value saved by the module
* @param btnModuleSetValId{String} ID of the button which sets the attribute of the module
* @param moduleName{String} name of the module which will be set and initialized
*/
var loadModule= function(divModuleId,inputModuleId,btnModuleShowValId,btnModuleSetValId,moduleName){
head.load([
'modules/'+moduleName+'.js'
], function() {
showDebug();
//Because the modules are loaded into the global scope by lazy loading, these can be called with this.
var module=new this[moduleName](divModuleId,inputModuleId,btnModuleShowValId,btnModuleSetValId);
LogModule.show(""+moduleName+" was instantiated ");
module.loadActions();
});
/**
* Debug method to show information at the log panel
* @method showDebug
*/
var showDebug= function(){
console.info(Object.keys( window ));
}
};
/**
* To initialize the self executing module
*/
init();
})();
</script>