/
JSClassGenerator.html
384 lines (359 loc) · 14.2 KB
/
JSClassGenerator.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=WINDOWS-1252" >
<meta http-equiv="author" content="Engelbert Niehaus">
<meta http-equiv="last-modification" content="22.02.2013 (9:35)">
<meta http-equiv="content-language" content="de">
<meta http-equiv="desktop-type" content="tasks">
<script language="javascript">
//#################################################################
//# Javascript Code Generator
//# GNU Public License V3 - OpenSource
//# created with JavaScript Class Generator by Engelbert Niehaus
//# 2012 University Koblenz-Landau
//#################################################################
function replaceStringReverse(pString,pReplace,pSearch)
//###### replaces in the string "pString" multiple substrings "pSearch" by "pReplace"
{
return replaceString(pString,pSearch,pReplace);
}
function replaceString(pString,pSearch,pReplace)
//###### replaces in the string "pString" multiple substrings "pSearch" by "pReplace"
{
//alert("cstring.js - replaceString() "+pString);
if (pString != '') {
var vHelpString = '';
var vN = pString.indexOf(pSearch);
var vReturnString = '';
while (vN >= 0)
{
if (vN > 0)
vReturnString += pString.substring(0, vN);
vReturnString += pReplace;
if (vN + pSearch.length < pString.length) {
pString = pString.substring(vN+pSearch.length, pString.length);
} else {
pString = ''
}
vN = pString.indexOf(pSearch);
};
};
return vReturnString + pString;
}
function getDate() {
var vNow = new Date();
var vMonth = vNow.getMonth()+1;
return vNow.getDate()+"."+vMonth+"."+vNow.getFullYear();
}
function createJSClass()
{
var vString = "";
var vDate = getDate();
var vClassname = document.fCreator.tClassname.value;
var vClassFile = vClassname.toLowerCase()+".js";
var vSuperClassname = document.fCreator.tSuperClassname.value;
var vAuthor = document.fCreator.tAuthor.value;
var vEMail = document.fCreator.tEMail.value;
var vHeader = document.fCreator.tHeader.value;
var vSuperClass = document.fCreator.tSuperClass.value;
var vMethodHeader = document.fCreator.tMethodHeader.value;
var vAttributes = document.fCreator.tAttributes.value;
var vMethods = document.fCreator.tMethods.value;
var vClassTail = document.fCreator.tClassTail.value;
var vAttribArray = vAttributes.split(/\n/);
var vMethodArray = vMethods.split(/\n/);
var vAttribConstructor = ""; //" //---Attributes-------------------------\n";
var vMethodConstructor = " //---Methods----------------------------\n";
var vOutput = vHeader;
if (vSuperClassname == "") {
vSuperClass = " // no superclass defined\n";
};
vOutput = replaceString(vOutput,"___AUTHOR___",vAuthor);
vOutput = replaceString(vOutput,"___EMAIL___",vEMail);
vOutput = replaceString(vOutput,"___SUPERCLASS___",vSuperClass);
vOutput = replaceString(vOutput,"___SUPERCLASSNAME___",vSuperClassname);
vOutput = replaceString(vOutput,"___CLASSFILENAME___",vClassFile);
vOutput = replaceString(vOutput,"___DATE___",vDate);
vMethodHeader = replaceString(vMethodHeader,"___SUPERCLASS___",vSuperClass);
vMethodHeader = replaceString(vMethodHeader,"___CLASSNAME___",vClassname);
vMethodHeader = replaceString(vMethodHeader,"___CLASSFILENAME___",vClassFile);
vMethodHeader = replaceString(vMethodHeader,"___DATE___",vDate);
var vMethod = vMethodHeader;
//vAttributes = replaceString(vAttributes,"\n","\nthis.");
//alert(vAttributes);
for (var i=0; i<vAttribArray.length; i++) {
//alert(vAttribArray[i]);
if (vAttribArray[i].indexOf("=")>0) {
vAttribConstructor += "\tthis."+vAttribArray[i]+";\n";
}
};
var vSplitArray;
for (var i=0; i<vMethodArray.length; i++) {
if (vMethodArray[i].indexOf("(")>0) {
vSplitArray = vMethodArray[i].split("(");
vMethodConstructor += "\tthis."+vSplitArray[0]+"\t = "+vSplitArray[0]+"_"+vClassname+";\n";
};
}
vOutput = replaceString(vOutput,"___ATTRIBUTES___",vAttribConstructor);
vOutput = replaceString(vOutput,"___METHODS___",vMethodConstructor);
var vMethodname = "";
var vMethodAllParamters = "";
for (var i=0; i<vMethodArray.length; i++) {
vMethod = vMethodHeader;
var vOpenBracketPos = vMethodArray[i].indexOf("(");
if (vOpenBracketPos >0) {
vSplitArray = vMethodArray[i].split("(");
var vCloseBracketPos = vSplitArray[1].lastIndexOf(")");
if (vCloseBracketPos<0) {
alert("ERROR: Method definition error!\n No closing bracket!\n"+vMethodArray[i]);
} else {
vMethodAllParamters = vSplitArray[1].substring(0,vCloseBracketPos);
};
vMethod = replaceString(vMethod,"___METHODCALL___",vMethodArray[i]);
vMethod = replaceString(vMethod,"___METHODNAME___",vSplitArray[0]);
vMethod = replaceString(vMethod,"___METHODPARAMETERS___",vMethodAllParamters);
vOutput += vMethod;
//vSplitArray = vMethodArray[i].split("(");
} else {
//alert("ERROR: Method definition error!\n No opening bracket!\n"+vMethodArray[i]);
}
};
vOutput += vClassTail;
vOutput = replaceString(vOutput,"___CLASSNAME___",vClassname);
document.fCreator.tOutput.value = vOutput;
alert("Javascript Class Created!\nCopy Javascript Code into File and\nuse filename '"+vClassFile+"'!");
}
var vDOM_ID = new Array();
vDOM_ID.push("tClassname");
vDOM_ID.push("tSuperClassname");
vDOM_ID.push("tAuthor");
vDOM_ID.push("tEMail");
vDOM_ID.push("tAttributes");
vDOM_ID.push("tMethods");
//vDOM_ID.push("");
function saveLocalStorage() {
//localStorage.setItem("lastname", "Smith");
// Retrieve
//document.getElementById("result").innerHTML = localStorage.getItem("lastname");
//alert("vDOM_ID.length="+vDOM_ID.length);
for (var i=0;i < vDOM_ID.length; i++ ) {
var vID = vDOM_ID[i];
var vNode = document.getElementById(vID);
if (vNode) {
//alert(vID+"="+vNode.value);
localStorage.setItem(vID,vNode.value);
};
};
};
function loadLocalStorage() {
//alert("vDOM_ID.length="+vDOM_ID.length);
for (var i=0;i < vDOM_ID.length; i++ ) {
var vID = vDOM_ID[i];
var vValue = localStorage.getItem(vID);
if (vValue) {
var vNode = document.getElementById(vID);
vNode.value = vValue;
} else {
//alert("vID="+vID+" is undefined");
};
};
}
function clearLocalStorage() {
//alert("vDOM_ID.length="+vDOM_ID.length);
for (var i=0;i < vDOM_ID.length; i++ ) {
var vID = vDOM_ID[i];
localStorage.removeItem(vID);
};
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="generator" content="Bluefish 2.2.2" >
<title>Javascript DOM Class Generator</title>
</head>
<body style="font-family:Arial,Verdana; font-size:12pt; color:black" bgcolor="white">
<center><h1>Javascript DOM Class Generator</h1>
<a href="http://www.gnu.org/licenses/quick-guide-gplv3.pdf" target="vGNU_Licence">GNU Public Licence V3</a> <hr>
<b>Import Javascript Classes in <a href="../javascript2htmlcreator/index.html" target="_blank">HTML-Javascript Environment</a></b>
<br>
<input type="button" onclick="saveLocalStorage()" value="Save Local Storage">
-------
<input type="button" onclick="clearLocalStorage()" value="Clear Local Storage">
</center>
<form name="fCreator">
<table bgcolor="#A9BCF5" border="1">
<tbody><tr>
<td>
<b>Class Name:</b> <input name="tClassname" id="tClassname" value="EProof__QID__" type="text">
</td>
<td>
<b>Super Class Name:</b> <input name="tSuperClassname" id="tSuperClassname" value="" type="text"> <br>leave empty if this class does not inherit from a super class.
</td>
</tr>
<!-- <tr>
<td colspan=2 align="center">
<b>DOM Type:</b> <input name="tDOMType" value="DIV" type="text">
<b>DOM Display:</b> <input name="tDOMDisplay" value="DOMDISPLAY" type="text">
<b>DOM Edit:</b> <input name="tDOMEdit" value="DOMEDIT" type="text">
</td>
</tr> -->
<tr>
<td>
<b>Author:</b> <input name="tAuthor" id="tAuthor" value="Engelbert Niehaus" type="text">
</td>
<td>
<b>e-Mail Author:</b> <input name="tEMail" id="tEMail" value="niehaus@uni-landau.de" type="text">
</td>
</tr>
<tr>
<td>
<b>Attributes</b><br>
<textarea name="tAttributes" id="tAttributes" cols="60" rows="10">aTreeXML = null
aRootID = "TREEXML"
aRootDOM = document.getElementById(this.aRootID)
aDOMIDs = new Array("MYID1","MYID2","OTHERID1") </textarea>
</td>
<td>
<b>Methods</b><br>
<textarea name="tMethods" id="tMethods" cols="60" rows="10">load_IMathAS()
load_LS()
save_LS()
parseXML()
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="bCreatorButton" value=" Create Javascript Class " onclick="createJSClass()" type="button">
<b>Javascript Source Code</b><br>
<textarea name="tOutput" cols="125" rows="20"> </textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<hr>
The following text areas define templates for the JavaScript Class Generation. If want to use
differente templates for the javascript class generator, just download the file and edit the HTML
source code. Use your Browser to save the html-file to your local filesystem.
It is pure HTML with the javascript functions included in the file. So it will be easy to modify
the source code according to your requirements and constraints.
<hr>
<b>Class Header</b><br>
<textarea name="tHeader" cols="125" rows="10">//#################################################################
//# Javascript Class: ___CLASSNAME___()
//# SuperClass: ___SUPERCLASSNAME___
//# Class Filename: ___CLASSFILENAME___
//#
//# Author of Class: ___AUTHOR___
//# email: ___EMAIL___
//# created ___DATE___
//# last modifications ___DATE___
//# GNU Public License - OpenSource
//# created with JavaScript Class Generator by Engelbert Niehaus
//#################################################################
//---------------------------------------------------------------------
//---Import this Class in HTML-File with
// <SCRIPT LANGUAGE="JavaScript" SRC="___CLASSFILENAME___"> </SCRIPT>
//---------------------------------------------------------------------
//---Constructor of Class ___CLASSNAME___()
// Call the constructor for creating an instance of class ___CLASSNAME___
// by the following command in HTML-file that imports this class
// var vMyInstance = new ___CLASSNAME___();
//---------------------------------------------------------------------
//----Attributes-------------------------------------------------------
//---------------------------------------------------------------------
// If you want to access the attributes of ___CLASSNAME___, use
// the attribute name with a leading "this." in the definition of method of ___CLASSNAME___, e.g.
// this.myattrib3 = "Hello World";
//---------------------------------------------------------------------
//----Methodes---------------------------------------------------------
//---------------------------------------------------------------------
// In the definition of the methods of '___CLASSNAME___'
// the function name is extended with '____CLASSNAME___'.
// This is done to avoid name space conflicts, if you overwrite a
// method 'my_method()' that was inherited from a superclass 'MySuperClass' e.g.
// SuperClass: MySuperClass.my_method()
// Class: ___CLASSNAME___.my_method()
// The method definitions are as follows
// function my_method____CLASSNAME___(...) { .....
// and
// function my_method_MySuperClass(...) { .....
function ___CLASSNAME___ () {
___SUPERCLASS___
//---------------------------------------------------------------------
//---Attributes of Class "___CLASSNAME___()"
//---------------------------------------------------------------------
___ATTRIBUTES___
//---------------------------------------------------------------------
//---Methods of Class "___CLASSNAME___()" defined as JS functions
//---------------------------------------------------------------------
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<b>Method Header</b><br>
<textarea name="tMethodHeader" cols="125" rows="10">
//#################################################################
//# Method: ___METHODNAME___()
//# used in Class: ___CLASSNAME___
//#
//# Comment:
//#
//# created ___DATE___
//# last modifications ___DATE___
//#################################################################
this.___METHODNAME___ = function (___METHODPARAMETERS___) {
//----Debugging------------------------------------------
// The following alert-Command is useful for debugging
//alert("___CLASSFILENAME___:___METHODCALL___-Call")
//----Create Object/Instance of ___CLASSNAME___----
// var vMyInstance = new ___CLASSNAME___();
// vMyInstance.___METHODCALL___;
//-------------------------------------------------------
//>>>> INSERT YOUR CODE HERE <<<<<
//___METHODCODE___
};
//----End of Method ___METHODNAME___ Definition
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<b>Inherit from SuperClass</b><br>
<textarea name="tSuperClass" cols="125" rows="3"> //--------------------------------------
//---Super Class------------------------
this.SuperClass = ___SUPERCLASSNAME___;
this.SuperClass();
//--------------------------------------
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<b>Class Tail</b><br>
<textarea name="tClassTail" cols="125" rows="3">
}
//-------------------------------------------
//---End Definition of Class-----------------
// JS Class: ___CLASSNAME___
//-------------------------------------------
</textarea>
</td>
</tr>
</tbody></table>
</form>
<center>
<script>
// Check browser support
if (typeof(Storage) != "undefined") {
//alert("Local Storage");
loadLocalStorage();
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
</script>
Javascript Class Generator was developed 2015 by Engelbert Niehaus - <a href="http://www.uni-koblenz-landau.de/" target="_bank">University Koblenz-Landau</a> <br>
<br>
<a href="http://mathematik.uni-landau.de/javascript/classgenerator/" target="_blank">http://mathematik.uni-landau.de/javascript/classgenerator/</a>
</center>
</body></html>