-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimpleTable.js
More file actions
755 lines (633 loc) · 27 KB
/
Copy pathsimpleTable.js
File metadata and controls
755 lines (633 loc) · 27 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
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
// Created by Philippe MEYER 2016-2017 //
function SimpleTable(zoneId, tableId, tableClass) {
//"use strict";
this.doc = document;
this.zoneId = zoneId;
this.zone = this.doc.getElementById(this.zoneId);
this.tableId = tableId || 'tableId';
this.tableClass = tableClass || 'tableClass';
this.table;
this.translations={};
this.config={};
this.header={};
this.data={};
this.dataKeys=[];
this.offset=0;
this.html5ImputDateSupport=false;
this.allowSearch=false;
this.dragObj=null;
this.selectedRow;
this.modalValidation;
var test = document.createElement("input");
test.setAttribute("type", "date");
this.html5ImputDateSupport = (test.type !== "text");
//this.html5ImputDateSupport=false;
this.Save=function(){
if(this.config.save)
this.config.save();
}
this.getData=function(){
return JSON.stringify(this.data);
}
//------------------
this.CreateSelect=function(aList,aName,aValue){
var doc = this.doc;
var anOption;
var elem = doc.createElement("select");
elem.setAttribute('name',aName);
elem.setAttribute('id',aName);
var arr = aList.split(",");
for(var i = 0; i < arr.length;i+=2){
anOption = doc.createElement("option");
anOption.value = arr[i];
anOption.text = arr[i+1];
if(aValue===arr[i]){
anOption.selected = true;
}
elem.appendChild(anOption);
}
return elem;
}
this.CreateCheckBox=function(aList,aName,aValue){
var doc = this.doc;
var val;
var arr = aList.split(",");
if(arr.length!==2)
return this.CreateInput('string',aName,aValue);
else{
var elem = doc.createElement("input");
elem.setAttribute('type','checkbox');
elem.setAttribute('name',aName);
elem.setAttribute('id',aName);
elem.setAttribute('value',aList); // We keep the list whole in order to be able to retrieve one of the two values
if(aValue===arr[1]){
elem.checked = true;
}
return elem;
}
}
this.CreateInput=function(aType,aName,aValue){
var doc = this.doc;
var html_type,html_value,html_readOnly;
var elem = doc.createElement("input");
html_value = aValue;
html_type = 'text';
html_readOnly='';
if(aType==='mm-dd-yyyy' & this.html5ImputDateSupport){ // English date
// aaaa-mm-jj
html_value = aValue.substring(6,10)+"-"+aValue.substring(0,2)+"-"+aValue.substring(3,5);
html_type = 'date';
}
else if(aType==='dd-mm-yyyy' & this.html5ImputDateSupport){ // French date
html_value = aValue.substring(6,10)+"-"+aValue.substring(3,5)+"-"+aValue.substring(0,2);
html_type = 'date';
}
else if(aType==='dd/mm/yyyy' & this.html5ImputDateSupport){ // French date
html_value = aValue.substring(6,10)+"/"+aValue.substring(3,5)+"/"+aValue.substring(0,2);
html_type = 'date';
}
else if(aType==='mm/dd/yyyy' & this.html5ImputDateSupport){ // English date
// aaaa-mm-jj
html_value = aValue.substring(6,10)+"/"+aValue.substring(0,2)+"/"+aValue.substring(3,5);
html_type = 'date';
}
else if(aType==='protected'){ // English date
// aaaa-mm-jj
html_readOnly = 'readonly';
}
elem.setAttribute('type',html_type);
elem.setAttribute('name',aName);
elem.setAttribute('id',aName);
elem.setAttribute('value',html_value);
if(html_readOnly==='readonly'){
elem.setAttribute('readonly',html_readOnly);
}
return elem;
}
this.SetTranslations=function(json_str){
this.translations = JSON.parse(json_str);
}
this.translate=function(token){
var itemTranslated = token
if ( this.translations[token]){
itemTranslated= this.translations[token];
}
return itemTranslated;
}
this.SetConfig=function(json_str){
this.config = JSON.parse(json_str);
// If a modal is wished on row click then add information to the SimpleGrid object
var self;
var booModal = false;
var modalPtr;
if(this.config.modal){
var modalId = this.config.modal;
if(modalId.length!==0){
modalPtr=this.doc.getElementById(modalId);
if(modalPtr){
self=this;
this.config.booModal=true;
this.config.modal=modalPtr;
this.config.modalTitle='Modifiying';
this.config.modalLeft='';
this.config.modalTop='';
booModal=true;
}
}
}
if(!booModal){
this.config.booModal=false;
this.config.modal=null;
this.config.modalTitle='none';
}
if(this.config.allowSearch){
if(this.config.allowSearch==='yes'){
this.allowSearch=true;
}
}
}
this.SetData=function(json_str){
this.data = JSON.parse(json_str);
}
this.SetHeader=function(json_str){
this.header = JSON.parse(json_str); // Array of objets with 3 properties : name (internal), type (for sorting), title (to show)
for(var i=0;i<this.header.arr.length;i++){
this.header.arr[i].sortWay='up'; // Adding property sortWay to the objet
}
}
// If a modal is wished on row click then add information to the SimpleGrid object
var booModal = false;
var modalPtr;
if(this.config.modal){
var modalId = this.config.modal;
if(modalId.length!=0){
modalPtr=this.doc.getElementById(modalId);
if(modalPtr){
this.booModal=true;
this.modal=modalPtr;
}
}
}
this.showModal=function(rowId){
var row_prefix = this.tableId+"_row";
if (rowId.length===0) return;
rowId = rowId.replace(row_prefix,'');
var item = '';
var modalTitle = this.translate('Modifying');
var lineOffset = parseInt(rowId);
if(lineOffset===-1)
modalTitle = this.translate('Adding');
this.offset = lineOffset;
var self = this;
var ptr = this.config.modal;
var doc = this.doc;
if(ptr){
ptr.innerHTML = "";
var aDiv = doc.createElement("div");
var elem,aValue,aName,aType,aTitle;
aDiv.setAttribute('class','modal-content');
aDiv.setAttribute('id','modalRect');
// Cross to close modal
var spanClose = doc.createElement("span");
spanClose.setAttribute('class','close');
spanClose.setAttribute('id','close_sg_modal');
// Adding cross character
var txt = doc.createTextNode('X');
spanClose.appendChild(txt);
aDiv.appendChild(spanClose);
elem = doc.createElement("br");
aDiv.appendChild(elem);
var aTitle = doc.createElement("div");
aTitle.setAttribute('class','sg_title');
txt = doc.createTextNode(modalTitle);
aTitle.appendChild(txt);
aDiv.appendChild(aTitle);
elem = doc.createElement("br");
aDiv.appendChild(elem);
var nrCols = this.header.arr.length;
for(var i=0;i<nrCols;i++){
aTitle = this.header.arr[i].title;
if(aTitle!==''){
elem = doc.createElement("label");
txt = doc.createTextNode(aTitle);
elem.appendChild(txt);
aDiv.appendChild(elem);
}
if (lineOffset!=-1)
aValue = this.data.arr[lineOffset][this.header.arr[i].name];
else
aValue = '';
aName = this.header.arr[i].name;
aType = this.header.arr[i].type;
if(this.header.arr[i].cb_list){
elem = this.CreateCheckBox(this.header.arr[i].cb_list,this.header.arr[i].name,aValue);
}
else if(this.header.arr[i].list){
elem = this.CreateSelect(this.header.arr[i].list,this.header.arr[i].name,aValue);
}
else{
elem = this.CreateInput(this.header.arr[i].type,this.header.arr[i].name,aValue);
if(this.header.arr[i].placeholder){
elem.setAttribute('placeholder',this.header.arr[i].placeholder);
}
if(this.header.arr[i].maxlength){
elem.setAttribute('maxlength',this.header.arr[i].maxlength);
}
}
aDiv.appendChild(elem);
elem = doc.createElement("br");
aDiv.appendChild(elem);
elem = doc.createElement("br");
aDiv.appendChild(elem);
}
var aSpan = doc.createElement("span");
aSpan.setAttribute('class','err_sg_modal');
aDiv.appendChild(aSpan);
elem = doc.createElement("br");
aDiv.appendChild(elem);
elem = doc.createElement("button");
elem.setAttribute('id','validate');
elem.setAttribute('class','sg_ok');
item=this.translate('Validate');
txt = doc.createTextNode(item);
elem.appendChild(txt);
elem.onclick = function() {
var booOK=true;
if(self.modalValidation){
booOK=self.modalValidation();
}
if(booOK){
var ptr,lineOffset,nrCols;
lineOffset = self.offset;
if(lineOffset==-1){
self.data.arr.push({});
lineOffset = self.data.arr.length-1;
}
nrCols = self.header.arr.length;
var val;
for(var i=0;i<nrCols;i++){
val='';
ptr = self.doc.getElementById(self.header.arr[i].name);
if(ptr){
val = ptr.value;
aType = self.header.arr[i].type;
if(aType==='mm-dd-yyyy' & self.html5ImputDateSupport){ // English date : aaaa-mm-jj
val= val.substring(5,7)+"-"+val.substring(8,10)+"-"+val.substring(0,4)
}
else if(aType==='dd-mm-yyyy' & self.html5ImputDateSupport){ // French date
val= val.substring(8,10)+"-"+val.substring(5,7)+"-"+val.substring(0,4)
}
else if(aType==='mm/dd/yyyy' & self.html5ImputDateSupport){ // French date
val= val.substring(5,7)+"/"+val.substring(8,10)+"/"+val.substring(0,4)
}
else if(aType==='dd/mm/yyyy' & self.html5ImputDateSupport){ // French date
val= val.substring(8,10)+"/"+val.substring(5,7)+"/"+val.substring(0,4)
}
else if(self.header.arr[i].cb_list){
var arr = val.split(',');
if(arr.length===2)
if(ptr.checked) val=arr[1]; else val=arr[0];
}
}
self.data.arr[lineOffset][self.header.arr[i].name]=val;
}
self.config.modal.style.display = "none";
// self.saveModalCoordinates();
self.Draw();
}
return false;
}
aDiv.appendChild(elem);
elem = doc.createElement("button");
elem.setAttribute('id','cancel');
elem.setAttribute('class','sg_caution');
item = this.translate('Cancel');
txt = doc.createTextNode(item);
elem.appendChild(txt);
elem.onclick = function() {
//self.saveModalCoordinates();
self.config.modal.style.display = "none";
//self.Draw();
return false;
}
aDiv.appendChild(elem);
elem = doc.createElement("button");
elem.setAttribute('id','delete');
elem.setAttribute('class','sg_warning');
item = this.translate('Delete');
txt = doc.createTextNode(item);
elem.appendChild(txt);
elem.onclick = function() {
var lineOffset = self.offset;
self.data.arr.splice(lineOffset,1);
self.selectedRow="";
//self.saveModalCoordinates();
self.config.modal.style.display = "none";
self.Draw();
return false;
}
aDiv.appendChild(elem);
elem = doc.createElement("br");
aDiv.appendChild(elem);
elem = doc.createElement("br");
aDiv.appendChild(elem);
ptr.appendChild(aDiv);
var close_sg_modal = document.getElementById("close_sg_modal");
close_sg_modal.onclick = function() {
//self.saveModalCoordinates();
self.config.modal.style.display = "none";
self.Draw();
}
if(self.config.modalLeft!==''){
var ptr= document.getElementById('modalRect');
if(ptr){
ptr.style.position='absolute'; // Only now !
ptr.style.left = self.config.modalLeft;
ptr.style.top = self.config.modalTop;
}
}
self.config.modal.style.display = "block";
}
}
this.saveModalCoordinates=function(){
if(this.config.booModal===true){
var ptr= document.getElementById('modalRect');
if(ptr){
this.config.modalLeft=ptr.style.left;
this.config.modalTop=ptr.style.top;
}
}
}
this.sort=function(colId){
var item='';
var obj;
var type;
var sortWay='up';
var offset;
var self = this;
this.selectedRow='';
for(var i=0;i<this.header.arr.length;i++){
if(this.header.arr[i].id===colId){
obj=this.header.arr[i];
type=obj.type;
sortWay=obj.sortWay;
offset = i;
i=this.header.arr.length+1;
}
if(obj){
self=this;
var aKey = this.dataKeys[offset];
self.data.arr.sort(function(a, b){
var boo_Sort_Integer = false;
var intA,intB = 0;
var elA,elB = '';
var elA = (a[aKey]+'') || ''; // If something mistyped in json
var elB = (b[aKey]+'') || ''; // Coercing to string for the numbers
if(type==='number'){
boo_Sort_Integer = true;
elA = elA.replace(",","."); // in case is a french float with decimal separator as ','
elB = elB.replace(",",".");
intA = parseInt(elA);
intB = parseInt(elB);
}else if(type==='string'){
elA = elA.toLowerCase();
elB = elB.toLowerCase();
}else if(type==='dd-mm-yyyy' || type==='dd/mm/yyyy'){ // French date
boo_Sort_Integer = true;
intA = parseInt(elA.substring(3,5))*100;
intA +=parseInt(elA.substring(0,2));
intA +=parseInt(elA.substring(6,10))*10000;
intB = parseInt(elB.substring(3,5))*100;
intB +=parseInt(elB.substring(0,2));
intB +=parseInt(elB.substring(6,10))*10000;
}else if(type==='mm-dd-yyyy' || type==='mm/dd/yyyy'){ // English date
// ex : 12/01/2016 => 20160000 + 1200 + 1 = 20161201
boo_Sort_Integer = true;
intA = parseInt(elA.substring(3,5));//Day
intA +=parseInt(elA.substring(0,2))*100;//Month
intA +=parseInt(elA.substring(6,10))*10000; //Yea r
intB = parseInt(elB.substring(3,5));
intB +=parseInt(elB.substring(0,2))*100;
intB +=parseInt(elB.substring(6,10))*10000;
}
if(boo_Sort_Integer){
if(intA <intB){
if(sortWay==='up') {return -1;} else {return 1;}
}else if(intA > intB){
if(sortWay==='up') {return 1;} else {return -1;}
}
else return 0;
}
else{
if(elA <elB){
if(sortWay==='up') {return -1;} else {return 1;}
}else if(elA > elB){
if(sortWay==='up') {return 1;} else {return -1;}
}
else return 0;
}
return 0;
});
if(sortWay==='up') {obj.sortWay='down'} else {obj.sortWay='up'}
}
}
this.Draw();
}
this.Draw=function(objSearch){
var searchFor = '';
var searchForLower = '';
if(objSearch){
searchFor = objSearch.value;
searchForLower = searchFor.toLowerCase();
}
var athead,aHead,att,elem,item,txt,aLine,lineObj,lineObjLen;
this.zone.innerHTML = "";
var doc = this.doc; // For speed
var aTable = doc.createElement("table");
aTable.setAttribute('class',this.tableClass);
// ------------- Building Header -------------------------
athead = doc.createElement("div");
athead.setAttribute('class','stayFixed');
if(this.config.width){
var aWidth = parseInt(this.config.width);
aWidth = aWidth - 20;
athead.setAttribute('style','width:'+aWidth+'px;width:'+aWidth+'px;overflow-y: hidden;');
}
aHead = doc.createElement("tr");
var nrCols = this.header.arr.length;
// We need to know the number of visible columns because the width
// of each individual column is minored by (24/nrVisibleCols) due to the scroler area
var nrVisibleCols = 0;
for(var i=0;i<nrCols;i++){
if(this.header.arr[i].width!=='0px'){
nrVisibleCols++;
}
}
if(nrVisibleCols===0) nrVisibleCols=1; // no zero dividing
for(var i=0;i<nrCols;i++){
if(this.header.arr[i].width!=='0px'){
elem = doc.createElement("th");
// Adding an id to each column header to be able to sort them
elem.setAttribute('id',this.tableId+"_"+"col"+i);
// Computing the size of each column
if(this.header.arr[i].width){
aWidth = parseInt(this.header.arr[i].width);
// aWidth = aWidth-(20/nrVisibleCols);
elem.setAttribute('style','width:'+aWidth+'px;');
}
// Adding the title of each column header
txt = doc.createTextNode(this.header.arr[i].title);
elem.appendChild(txt);
// adding the column header to the header
aHead.appendChild(elem);
}
}
athead.appendChild(aHead); // adding the header (tr) to div of class 'stayFixed'
aTable.appendChild(athead); // adding the div to the table
var self = this;
// ------------- Building Body -----------------------------
// Creating a scrollable div (overflow-y) surrounding the body of the table
var atbody = doc.createElement('div');
atbody.setAttribute('class','doscroll');
var aStyle = "overflow-y: scroll;";
if(this.config.height){ // If we have defined an height
var anHeight = parseInt(this.config.height);
anHeight = anHeight - 24; // lowering by 24 px to figure out approximatly the height of the header
aStyle = aStyle+"height:"+anHeight+"px;max-height:"+anHeight+"px;";
}
atbody.setAttribute('style',aStyle);
if(this.config.booModal){ // I a modal is asked in the config
atbody.addEventListener("click",function(e){
var target = (e.target) ? e.target : e.srcElement;
var parent = target.parentNode;
if (parent){
self.showModal(parent.id)
self.selectedRow=parent.id;
}
}); // Adding an Event listener
}
var nrLines=0;
var boo_show = true;
for(var i=0;i<this.data.arr.length;i++){
nrLines++;
boo_show = false;
// Getting the object from the array
lineObj = this.data.arr[i];
if(searchForLower.length>0){
Object.keys(lineObj).forEach(function(key) {
item = lineObj[key];
item = item.toLowerCase();
if (item.indexOf(searchForLower)!==-1){
boo_show = true;
}
});
}else{
boo_show = true;
}
if(boo_show){
aLine= doc.createElement("tr");
// adding an id to tr for modals
var anId = this.tableId+"_"+"row"+i;
aLine.setAttribute('id',anId);
// We want the selected row to appear 'selected' (class .selectedRow)
if(this.selectedRow===anId){
aLine.setAttribute('class','selectedRow');
}
// Looping thru properties of each data object
var j =0;
Object.keys(lineObj).forEach(function(key) {
if(i===0){
self.dataKeys.push(key);
}
if(self.header.arr[j].width!=='0px'){
elem = doc.createElement("td");
txt = doc.createTextNode(lineObj[key]); // Set the td content to the corresponding item in the data array
elem.appendChild(txt);
if(self.header.arr[j].width){ // If we were given a width
aStyle ="width:"+self.header.arr[j].width+";";
elem.setAttribute('style',aStyle);
}
aLine.appendChild(elem);
}
j++;
});
atbody.appendChild(aLine);// adding the line (tr) to the table
}
}
aTable.appendChild(atbody);// adding the line (tr) to the table
if(this.config.width)
this.zone.style="width:"+this.config.width+";border-radius:6px;padding:6px;padding-bottom:6px;border:1px solid black;";
this.zone.appendChild(aTable);
//Adding the number of records left of the footer
txt = doc.createTextNode("# "+nrLines);
elem = doc.createElement("b");
elem.appendChild(txt);
this.zone.appendChild(elem);
if(this.allowSearch){
elem = doc.createElement("label");
item = this.translate('Search');
txt = doc.createTextNode(' '+item+' : ');
elem.appendChild(txt);
elem.setAttribute('style','margin-left:20px;font-style:italic;');
this.zone.appendChild(elem);
elem = this.CreateInput('string','sg_search',searchFor);
elem.setAttribute('style','margin-left:5px;width:200px;margin-top:-10px;border-radius:4px;border : 1px solid #777;');
elem.onkeyup = function() {
self.Draw(this); // this will be the this of the input text
}
this.zone.appendChild(elem);
}
// Creating the 'New' Button right of footer
elem = doc.createElement("button");
elem.setAttribute('id','simpleGrid_add');
var item = this.translate('New');
txt = doc.createTextNode(item);
elem.appendChild(txt);
elem.onclick = function() {
self.showModal('-1');
return false;
}
elem.setAttribute('style','font-weight:bold;padding:3px;padding-left:20px;padding-right:20px;float:right;margin-top:-10px;');
this.zone.appendChild(elem);
// Creating the 'Save' Button right of footer
elem = doc.createElement("button");
elem.setAttribute('id','simpleGrid_Save');
var item = this.translate('Save');
txt = doc.createTextNode(item);
elem.appendChild(txt);
elem.onclick = function(){
self.Save();
}
elem.setAttribute('style','font-weight:bold;padding:3px;padding-left:20px;padding-right:20px;float:right;margin-top:-10px;');
this.zone.appendChild(elem);
var ptr = this.doc.getElementById('sg_search');
if(ptr){
var strLength = ptr.value.length;
ptr.focus();
if(strLength>0){
ptr.setSelectionRange(strLength, strLength);
}
}
var anId;
var self = this;
for(var i=0;i<this.header.arr.length;i++){
anId = this.tableId+"_"+"col"+i
this.header.arr[i].id=anId; // adding an attribute id to each colum header
this.header.arr[i].ptr=doc.getElementById(anId); // adding an attribute ptr to each colum header
if(this.header.arr[i].ptr){ // Only if my header is real (not 0px)
this.header.arr[i].ptr.addEventListener("click",function(e){
var target = (e.target) ? e.target : e.srcElement;
self.sort(target.id);
});}
}
}
}
function $get(id){
var prefix= id.substr(0,1);
if(prefix=="#" || prefix=="."){
return document.querySelector(id);
}
else {
return document.getElementById(id);
}
}