-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
3005 lines (2246 loc) · 75.6 KB
/
Copy pathbasic.js
File metadata and controls
3005 lines (2246 loc) · 75.6 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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Bismillah */
/*
basic.js (v26.03.26) A lightweight JavaScript library for building web-based applications with simple code. No need to write HTML or CSS — just use basic JavaScript.
- Project Site: https://bug7a.github.io/basic.js/
The Art of Fun Coding — With basic.js
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com>
- https://github.com/bug7a
Licensed under the Apache License, Version 2.0
*/
(function() {
"use strict";
const basic = {};
/*
if ( typeof module === "object" && typeof module.exports === "object" ) {
module.exports = basic;
} else {
window.basic = basic;
}
*/
window.basic = basic;
basic.startTime = Date.now();
basic.ACTION_COLOR = "#689BD2";
basic.ACTION2_COLOR = "cadetblue";
basic.WARNING_COLOR = "tomato";
basic.ALERT_COLOR = "gold";
basic.CANCEL_COLOR = "lightgray";
basic.TEXT_COLOR = "rgba(0, 0, 0, 0.8)";
basic.BACKGROUND_COLOR = "whitesmoke";
basic.DARK_BACKGROUND_COLOR = "#141414";
basic.FONT_SIZE = 20;
basic.BUTTON_WIDTH = 130;
basic.BUTTON_HEIGHT = 50;
basic.BUTTON_COLOR = basic.ACTION_COLOR;
basic.BUTTON_TEXT_COLOR = "rgba(0, 0, 0, 0.65)";
basic.TEXTBOX_WIDTH = 270;
basic.TEXTBOX_HEIGHT = 50;
basic.gunler = ["Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi"];
basic.days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
basic.aylar = ["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık"];
basic.months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
window.that = null;
window.previousThat = null;
window.prevThat = null;
let defaultContainerBox = null;
let previousDefaultContainerBox;
let loopTimer;
const resizeDetection = {};
resizeDetection.objectAndFunctionList = [];
const motionController = {};
motionController.WITH_MOTION_TIME = 50;
motionController.DONT_MOTION_TIME = 40;
basic.start = function () {
// - windows için ayrı css dosyası olabilir.
/*
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = './basic/basic.min.css';
document.getElementsByTagName('HEAD')[0].appendChild(link);
*/
window.page = new MainBox();
page.containerBox = null;
setDefaultContainerBox(page);
//page.bodyElement.style.margin = "0px";
//page.bodyElement.style.overflow = "hidden";
// console.log("basic.js: set body { margin: 0px, overflow: hidden }");
page.mainBox = createBox(0, 0, page.width, page.height);
//page.mainBox = createBox(0, 0, "100%", "100%");
page.mainBox.containerBox = null;
that.elem.style.position = "fixed";
that.color = "transparent";
page.onResize(function() {
if (typeof page.refreshSize === "function") {
page.refreshSize();
}
});
if (typeof start === "function") {
start();
basic.afterStart();
}
if (typeof loop === "function") {
if(!loopTimer) setLoopTimer(1000);
}
};
basic.afterStart = function () {
// Hız testi:
// var timeUsed = (Date.now() - basic.startTime)
// console.log(timeUsed);
// Hız testi için kullanılabilecek yöntem.
//console.time("işlem");
// ağır işlem
//console.timeEnd("işlem");
};
// you cant use console.log in *.min.js files but println
window.println = function ($message, $type = "log") {
// type: "error", "warn", "info", "table", "dir", ""
const _console = console;
_console[$type]($message);
};
//window.println = basic.println;
window.random = function ($first, $second) {
let result = 0;
if ($second != undefined) {
if ($second < $first) {
println("basic.js: random(): The second parameter (number) must be greater than the first.", "error");
} else {
result = $first + Math.round(Math.random() * ($second - $first));
}
} else {
println("basic.js: random(): Two parameters (numbers) must be sent.", "error");
}
return result;
};
//window.random = basic.random;
window.num = function ($str, $type = "float") {
if ($type == "float") {
const i = parseFloat($str);
return Math.round(i * 100) / 100;
} else if ($type == "integer" || $type == "int") {
return parseInt($str);
}
};
//window.num = basic.num;
window.str = function ($num) {
return String($num);
};
//window.str = basic.str;
window.isMobile = function () {
let answer = 0;
let a = navigator.userAgent || navigator.vendor || window.opera;
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
answer = 1;
}
return answer;
};
//window.isMobile = basic.isMobile;
window.go = function ($url, $windowType = "_self") {
// window.location.href = $url;
const openedWindow = window.open($url, $windowType);
// openedWindow.document.write("<p>Test Message</p>");
return openedWindow;
};
//window.go = basic.go;
// Tek haneli sayıyı, başına "0" ekleyerek iki haneli yapar. 03:10:05
window.twoDigitFormat = function($number) {
if ($number <= 9) {
$number = "0" + $number;
}
return $number;
};
//window.twoDigitFormat = basic.twoDigitFormat;
basic.storage = {
save(key, value) {
localStorage.setItem(key, JSON.stringify(value));
},
has(key) {
return localStorage.getItem(key) !== null;
},
load(key) {
try {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : null;
} catch (e) {
console.warn("storage parse error:", key);
return null;
}
},
remove(key) {
localStorage.removeItem(key);
},
clear() {
localStorage.clear();
}
};
// basic.storage olarak değiştirilebilir.
/*
window.storage = {
save(key, value) {
window.localStorage.setItem(key, JSON.stringify(value));
},
load(key) {
return JSON.parse(window.localStorage.getItem(key));
},
remove(key) {
window.localStorage.removeItem(key);
}
};
*/
//window.storage = basic.storage;
// Zaman bilgisi
basic.time = {
get hour() {
let dt = new Date();
return dt.getHours();
},
get minute() {
let dt = new Date();
return dt.getMinutes();
},
get second() {
let dt = new Date();
return dt.getSeconds();
},
get millisecond() {
let dt = new Date();
return dt.getMilliseconds();
}
};
//window.clock = basic.clock;
// Tarih bilgisi
basic.date = {
get year() {
let dt = new Date();
return dt.getFullYear();
},
get monthNumber() {
let dt = new Date();
let month = dt.getMonth();
month++;
return month;
},
get ayAdi() {
return basic.aylar[this.monthNumber - 1];
},
get monthName() {
return basic.months[this.monthNumber - 1];
},
get dayOfWeek() {
let dt = new Date();
return dt.getDay(); // 0-6
},
get gunAdi() {
return basic.gunler[this.dayNumber];
},
get dayName() {
return basic.days[this.dayNumber];
},
get dayOfMonth() {
let dt = new Date();
return dt.getDate(); // 1-31
},
get now() {
return Date.now();
}
};
//window.date = basic.date;
// Common methods and properties of basic objects.
class Basic_UIComponent {
/*
_type;
_containerBox;
_element;
_visible;
_displayType;
_opacity;
_rotate;
_backgroundColor;
_border;
_borderColor;
_round;
_fontSize;
_textColor;
_textAlign;
_motionString;
_clickable;
_eventFuncList;
NOTE: Browsers perform "render optimization." JavaScript collects many small changes you make to the DOM or style attributes while it's running, then applies these changes all at once. But be careful! If you force Reflow/Style (for example, by calling .offsetHeight), the browser will be forced to apply all the changes at once.
*/
constructor($type) {
this._type = $type;
this._visible = 1;
this._displayType = "block";
this._opacity = 1;
this._rotate = 0;
this._padding = 0;
this._motionString = "none";
this._clickable = 0;
this._eventFuncList = []; // for _addEventListener() - Otomatik temizleme
}
// alternative for containerBox
get parentBox() {
return this._containerBox;
}
// alternative for containerBox
set parentBox($value) {
this._containerBox = $value;
}
get containerBox() {
return this._containerBox;
}
set containerBox($value) {
this._containerBox = $value;
}
// Hizalama ve boyutlandırma.
get left() {
if (this.position == "absolute") {
return parseFloat(this.elem.style.left);
} else {
return this.elem.offsetLeft;
}
}
set left($value) {
this.elem.style.right = "";
this.elem.style.left = parseFloat($value) + "px";
}
get top() {
if (this.position == "absolute") {
return parseFloat(this.elem.style.top);
} else {
return this.elem.offsetTop;
}
}
set top($value) {
this.elem.style.bottom = "";
this.elem.style.top = parseFloat($value) + "px";
}
get right() {
return parseFloat(this.elem.style.right);
}
set right($value) {
this.elem.style.left = "";
this.elem.style.right = parseFloat($value) + "px";
}
get bottom() {
return parseFloat(this.elem.style.bottom);
}
set bottom($value) {
this.elem.style.top = "";
this.elem.style.bottom = parseFloat($value) + "px";
}
get totalLeft() {
return calcSpace(this.elem, "Left");
}
get totalTop() {
return calcSpace(this.elem, "Top");
}
get width() {
if (typeof this._width != "string") {
return this._width || 0;
} else {
return this.elem.offsetWidth;
}
}
set width($value) {
// VALUES TYPE:
// 100
// "auto"
// "100%"
// "calc(100% - 10px)"
this._width = $value;
if (typeof $value != "string") {
this.elem.style.width = parseFloat($value) + "px";
} else {
this.elem.style.width = $value;
}
}
get height() {
if (typeof this._height != "string") {
return this._height || 0;
} else {
return this.elem.offsetHeight;
}
}
set height($value) {
this._height = $value;
if (typeof $value != "string") {
this.elem.style.height = parseFloat($value) + "px";
} else {
this.elem.style.height = $value;
}
}
get rotate() {
return this._rotate;
}
set rotate($value) {
this._rotate = parseInt($value);
this.elem.style.transform = "rotate(" + $value + "deg)";
}
// -- Hizalama ve boyutlandırma SONU
// Genel özellikler
get visible() {
return this._visible;
}
set visible($value) {
this._visible = $value;
// display tipini daha sonra kullanmak üzere sakla.
if (this.elem.style.display && this.elem.style.display != "none") {
this._displayType = this.elem.style.display;
}
this.elem.style.display = ($value == 1) ? this._displayType : "none";
}
get clickable() {
return this._clickable;
}
set clickable($value) {
this._clickable = $value;
this.elem.style.pointerEvents = ($value == 1) ? "auto" : "none";
}
get opacity() {
return this._opacity;
}
set opacity($value) {
this._opacity = $value;
this.elem.style.opacity = $value;
}
get color() {
return this._backgroundColor;
}
set color($value) {
this._backgroundColor = $value;
this.elem.style.backgroundColor = $value;
}
get padding() {
return this._padding || 0;
}
set padding($value) {
this._padding = $value;
let paddingLeft, paddingRight, paddingTop, paddingBottom;
if (typeof $value === 'number') {
paddingLeft = paddingRight = paddingTop = paddingBottom = $value;
}
else if (Array.isArray($value)) {
const len = $value.length;
if (len === 1) {
paddingLeft = paddingRight = paddingTop = paddingBottom = $value[0];
}
else if (len === 2) {
paddingLeft = paddingRight = $value[0];
paddingTop = paddingBottom = $value[1];
}
else if (len === 3) {
paddingLeft = paddingRight = $value[0];
paddingTop = paddingBottom = $value[1];
}
else if (len === 4) {
paddingLeft = $value[0];
paddingTop = $value[1];
paddingRight = $value[2];
paddingBottom = $value[3];
}
else {
//throw new Error('padding değeri 1–4 elemanlı bir dizi ya da tek sayı olmalıdır.');
}
}
else {
//throw new Error('padding değeri ya sayı olmalı ya da 1–4 elemanlı bir dizi olmalıdır.');
}
this.elem.style.paddingLeft = paddingLeft + 'px';
this.elem.style.paddingTop = paddingTop + 'px';
this.elem.style.paddingRight = paddingRight + 'px';
this.elem.style.paddingBottom = paddingBottom+ 'px';
}
// -- Genel özellikler SONU
// Kenarlık
get border() {
return this._border;
}
set border($value) {
this._border = $value;
this.elem.style.borderWidth = $value + "px";
}
get borderColor() {
return this._borderColor;
}
set borderColor($value) {
this._borderColor = $value;
this.elem.style.borderColor = $value;
}
get round() {
return this._round;
}
set round($value) {
this._round = $value;
this.elem.style.borderRadius = $value + "px";
}
// -- Kenarlık SONU
// Metin özellikleri
get fontSize() {
return this._fontSize;
}
set fontSize($value) {
this._fontSize = $value;
this.elem.style.fontSize = $value + "px";
}
// fontSize Alternatif kullanım.
get textSize() {
return this._fontSize;
}
set textSize($value) {
this._fontSize = $value;
this.elem.style.fontSize = $value + "px";
}
get textColor() {
return this._textColor;
}
set textColor($value) {
this._textColor = $value;
this.elem.style.color = $value;
}
get textAlign() {
return this._textAlign;
}
set textAlign($value) {
this._textAlign = $value;
this.elem.style.textAlign = $value;
}
// Metin özellikleri SONU
get position() {
return (this.elem.style.position) ? this.elem.style.position : "absolute";
}
set position($value) {
this.elem.style.position = $value;
if ($value == "relative") {
this.left = 0;
this.top = 0;
}
}
// Otomatik hizalama metodları
center($position) {
moveToCenter(this, $position);
}
centerBy($obj, $position) {
moveToCenterBy(this, $obj, $position);
}
aline($obj, $position, $space = 0, $secondPosition) {
moveToAline(this, $obj, $position, $space, $secondPosition);
}
// -- Otomatik hizalama metodları SONU
// Nesneyi sil.
remove() {
// 1. Eklenmiş tüm eventleri kaldır. _addEventListener() - Otomatik temizleme
if (this._eventFuncList && this._eventFuncList.length) {
for (let i = this._eventFuncList.length - 1; i >= 0; i--) {
const ev = this._eventFuncList[i];
ev.elem.removeEventListener(ev.eventName, ev.eventFunc);
this._eventFuncList.pop();
}
}
// 2. Eğer resizeDetection kaydı varsa, onu da kaldır
if (resizeDetection && typeof resizeDetection.remove_onResize === "function") {
resizeDetection.remove_onResize(this.elem, null); // null ile tüm fonksiyonları sil
}
// NOTE: Eğer page.onResize kullanılmış ise manuel kaldırılmalı.
// 3. DOM'dan sil
this.elem.remove();
// 4. Tüm özellikleri sil:
/*
const _this = this;
setTimeout(function() {
for (let key in _this) {
delete _this[key]; // Tüm özellikleri sil
}
}, 1000); // WHY: May be have a css animation
*/
}
// Toplu özellik değiştirmesi.
props($defaultParams, $params, $props) {
setProparties(this, $defaultParams, $params, $props);
}
// Olay ekleme: onClick, onResize da kullanılıyor.
_addEventListener($eventName, $func, $element, $useCapture = false) {
/* // More options:
$useCapture =
{
capture: false, // Event capture mı bubbling mi? (varsayılan: false)
once: false, // Sadece 1 defa mı çalışsın? (true ise dinleyici otomatik kaldırılır)
passive: false // `event.preventDefault()` çağrılmayacaksa true yapılabilir
}
*/
let _that = this;
const eventFunc = function (event) {
$func(_that, event); // İlk parametre nesnenin kendisi.
}
$element.addEventListener($eventName, eventFunc, $useCapture);
// Otomatik temizleme için kaydet.
const eventDataItem = {};
eventDataItem.eventName = $eventName;
eventDataItem.originalFunc = $func;
eventDataItem.eventFunc = eventFunc;
eventDataItem.elem = $element;
this._eventFuncList.push(eventDataItem); // Nesne .remove() edilirken, hepsi temizlenir.
const removeEvent = function() {
_that._removeEventListener($eventName, $func, $element);
};
return removeEvent; // Eklenen olayı kolayca silmek için fonksiyon döndür.
};
// Olay silme: remove_onClick, remove_onResize da kullanılıyor.
_removeEventListener($eventName, $func, $element) {
//Otomatik temizleme
let eventFunc = null; // Orjinal fonksiyon bulunacak.
for (let i = 0; i < this._eventFuncList.length; i++) {
if (this._eventFuncList[i].originalFunc == $func) {
eventFunc = this._eventFuncList[i].eventFunc;
this._eventFuncList.splice(i, 1);
break;
}
}
if (eventFunc) {
$element.removeEventListener($eventName, eventFunc);
}
//$element.removeEventListener($eventName, $func);
};
// NEW: Olay ekleme: object.on("click", function);
on($eventName, $func, $useCapture = false) {
const _elem = (this._type == "textbox") ? this.inputElement : this.elem; // WHY: textbox için olayları input elementine bağla.
this.clickable = 1; // WHY: Clickable bazen 0 da unutulabilir, otomatik 1 ver. Gerekirse kullanıcı 0 yapar.
return this._addEventListener($eventName, $func, _elem, $useCapture);
/* #1
_elem.addEventListener($eventName, $func, $useCapture);
// Olayı kolayca silebilmek için hazır bir fonksiyon oluştur.
const removeEvent = function() {
_elem.removeEventListener($eventName, $func);
};
return eventInfo;
*/
// TODO: $eventName resize ise, resizeDetection.onResize ile ekleme yapılabilir.
}
// NOTE: Bir olay eklendiğinde, silme fonksiyonunu oluşturup, return ediyor.
// NEW: Olay ekleme: object.off("click", function);
off($eventName, $func) {
// Eğer ihityaç olursa, manuel olarak da, tek tek eventler silinebilir.
const _elem = (this._type == "textbox") ? this.inputElement : this.elem;
//_elem.removeEventListener($eventName, $func);
this._removeEventListener($eventName, $func, _elem);
}
onResize($func) {
resizeDetection.onResize(this, $func);
}
remove_onResize($func) {
resizeDetection.remove_onResize(this.elem, $func);
}
// Hareket
setMotion($motionString) {
// example motionString: "left 1s, top 1s, width 1s, height 1s, transform 1s, background-color 1s, border-radius 1s, opacity 1s"
// example motionString: "all 0.3s"
//this.setMotionNow($motionString);
const _that = this;
if(this._setMotionTimeout) clearTimeout(this._setMotionTimeout);
this._setMotionTimeout = setTimeout(function(){
_that.setMotionNow($motionString);
}, motionController.DONT_MOTION_TIME);
}
getMotion() {
return this._motionString;
}
setMotionNow($motionString) {
this._motionString = $motionString;
this.elem.style.transition = $motionString;
}
// Özellik değişimi, hareket ile olsun.
withMotion($func) {
const _that = this;
if(this._withMotionTimeout) clearTimeout(this._withMotionTimeout);
this._withMotionTimeout = setTimeout(function() {
_that.canMotionNow();
$func(_that);
}, motionController.WITH_MOTION_TIME);
}
// Harekete, belli bir süre ara ver.
dontMotion() {
this.elem.style.transition = "none";
const _that = this;
if(this._dontMotionTimeout) clearTimeout(this._dontMotionTimeout);
this._dontMotionTimeout = setTimeout(function(){
_that.elem.style.transition = _that._motionString;
}, motionController.DONT_MOTION_TIME);
}
// Harekete arayı, süresi dolmadan iptal et.
canMotionNow() {
this.elem.style.transition = this._motionString;
}
}
/* MAINBOX COMPONENT (page) */
class MainBox {
/*
_box;
_element;
_bodyElement;
_backgroundColor;
_zoom;
*/
constructor() {
this._bodyElement = document.getElementsByTagName("BODY")[0];
this._element = this._bodyElement;
this._backgroundColor = "white";
this._zoom = 1;
}
// short usage of element
get elem() {
return this._element;
}
get element() {
return this._element;
}
/*
get contElement() {
return this._element;
}
*/
// NOTE: .elem, .elem, .elem all the same. You can delete contElement --> element
get bodyElement() {
return this._bodyElement;
}
get mainBox() {
return this._box;
}
set mainBox($value) {
this._box = $value;
this._element = this._box.elem;
}
get width() {
let _w;
_w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
return withPageZoom(_w);
}
get height() {
let _h;
_h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
return withPageZoom(_h);
}
// .text alternatif kullanım:
get html() {
return this._box.elem.innerHTML;
}
set html($value) {
this._box.elem.innerHTML = $value;
}
get zoom() {
return this._zoom;
}
set zoom($value) {
this._zoom = $value;
this.bodyElement.style.transformOrigin = "top left";
this.bodyElement.style.transform = "scale(" + $value + ")";
page.refreshSize();
}
get color() {
return this._backgroundColor;
}
set color($value) {
this._backgroundColor = $value;
this.bodyElement.style.backgroundColor = $value;
}
// fit
fit($value = document.body.clientWidth, $maxValue) {
// WHY: onResize da hesaplama yaparken, zoom değerini hesaba katmasın diye.
// mesela page.width zoom değeri hesaba katıldığında farklı oluyor.
page.zoom = 1;
let _w = page.width;
// ikinci değer yok ise,
$maxValue = $maxValue || $value;
// ekran genişliği izin verilenden fazla ise,
if (_w > $maxValue) {
page.zoom = $maxValue / $value;