-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
141 lines (113 loc) · 3.79 KB
/
script.js
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
/**
* Creates an alias for the document object.
* @type {Document}
*/
let $ = document;
/**
* Selects and returns the first element with the specified class name.
* @param {string} selector - The class name of the desired element.
* @returns {Element | null} - The first element found with the specified class name.
*/
const _class = (selector) => {
const element = $.querySelector('.'+ selector);
if(!element){
throw new Error(`No element found with class ${selector}`);
}
return element;
}
/**
* Selects and returns the element with the specified ID.
* @param {string} selector - The ID of the desired element.
* @returns {Element | null} - The element found with the specified ID.
*/
const _id = (selector) => {
const element = $.querySelector('#'+ selector);
if(!element){
throw new Error(`No element found with id ${selector}`)
}
return element;
}
/**
* Creates a new DOM element with the specified name.
* @param {string} name - The name of the element to be created (e.g., 'div', 'span', etc.).
* @returns {Element} - The created DOM element.
* @throws {Error} - Throws an error if the provided name is not valid.
*/
const _create = (name) => {
let element;
if (name !== '') {
element = $.createElement(name);
} else {
throw new Error('Element name is not valid');
}
return element;
}
/**
* Logs the provided value to the console.
* @param {*} value - The value to be logged.
*/
const _log = (value)=>{
if(typeof value == 'undefined'){
console.log('-------------')
}else{
console.log(value);
}
}
const getSelect = ()=>{
let selectLa = _id('dateSelector');
return selectLa.value;
}
const updateElement = (day,date,monthName,year)=>{
const getDay = _id('day');
const getDate = _id('date');
const getMonth = _id('month');
const getYear = _id('year');
getDay.innerHTML = day;
getDate.innerHTML = date;
getMonth.innerHTML = monthName;
getYear.innerHTML = year;
}
const updateDate = ()=>{
const getChangeButton = _id('changeDateButton');
getChangeButton.addEventListener('click',()=>{
const value = getSelect();
if(value=='sorani'){
let sorani = soraniCalendar();
updateElement(sorani.dayName,sorani.day,sorani.monthName,sorani.year)
}else if(value=='kurmanci'){
let kurmanci = kurmanciCalendar();
updateElement(kurmanci.dayName,kurmanci.day,kurmanci.monthName,kurmanci.year)
}else if(value == 'kellhurri'){
let kellhurri = kelhuriCalendar();
updateElement(kellhurri.dayName,kellhurri.day,kellhurri.monthName,kellhurri.year)
}else if(value=='leki'){
let leki = lakiCalendar();
updateElement(leki.dayName,leki.day,leki.monthName,leki.year)
}else if(value == 'hewrami'){
let hewrami = hewramiCalendar();
updateElement(hewrami.dayName,hewrami.day,hewrami.monthName,hewrami.year)
}else if(value == 'zazaki'){
let zazaki = zazakiCalendar();
updateElement(zazaki.dayName,zazaki.day,zazaki.monthName,zazaki.year)
}
})
}
let sorani = soraniCalendar();
console.log(sorani);
updateElement(
sorani.dayName,sorani.day,sorani.monthName,sorani.year
);
const getButtonInfo = _class('btn-info');
getButtonInfo.addEventListener('click',()=>{
const getModal = _class('modal');
getModal.style.display = 'inline';
const closeButton = getModal.querySelector('.close');
closeButton.addEventListener('click',()=>{
getModal.style.display = 'none';
})
const closeButtonBottom = getModal.querySelector('button#closeModalBtn');
closeButtonBottom.addEventListener('click',()=>{
getModal.style.display = 'none';
})
})
updateDate();