-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path65-uzunluk-olcusu-cevirme-uygulamasi.htm
367 lines (284 loc) · 13.5 KB
/
65-uzunluk-olcusu-cevirme-uygulamasi.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Uzunluk Ölçüsü Çevirme Uygulaması</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- DIŞARIDAN YÜKLENEN KÜTÜPHANE DOSYALARI -->
<link rel="stylesheet" type="text/css" href="kutuphane/basic.css">
<script src="kutuphane/basic.js" type="text/javascript" charset="utf-8"></script>
<style>
body {
overflow: hidden;
}
/* enable 0 yapılan nesne, silik görünmesin. */
.basic_textbox:disabled {
opacity: 1 !important;
}
/* Birim seçme diyalogundaki butonlar, üzerlerine geldiğinde farklı renk olsun. */
.unit-selection-dialog-buttons-type:hover {
background-color: whitesmoke !important;
}
.unit-selection-dialog-buttons-type:active {
background-color: lightgray !important;
}
</style>
<script>
/*
UZUNLUK ÖLÇÜSÜ ÇEVİRME UYGULAMASI
- Bu projeyi; mobil (android, ios), web ve masaüstü uygulaması olarak paketlemeyi deneyebilirsiniz:
https://cordova.apache.org/
*/
var APP_ORIGINAL_WIDTH = 410
var APP_MAX_WIDTH = 410
// Varsayılan, verilen uzunluk birim sıra numarası. m
var DEFAULT_GIVEN_LENGTH_UNIT_INDEX = 3
// Varsayılan, hesaplanmış uzunluk birim sıra numarası. cm
var DEFAULT_CALCULATED_LENGTH_UNIT_INDEX = 5
// Uzunluk ölçü birimlerinin listesi
var lengthMeasurementUnits = [
{name: "Kilometre", short:"km"},
{name: "Hektometre", short:"hm"},
{name: "Dekametre", short:"dam"},
{name: "Metre", short:"m"},
{name: "Desimetre", short:"dm"},
{name: "Santimetre", short:"cm"},
{name: "Milimetre", short:"mm"},
]
// NOT: index değeri, dizinin sıra numarasıdır. 0: km, 1:hm, 2:dam, 3:m, 4:dm, 5:cm, 6:mm
// Başlangıç sayfası
var a0
// Verilen uzunluk metin kutusu
var txtGivenLength
// Hesaplanan uzunluk metin kutusu
var txtCalculatedLength
// Metin kutularının üzerindeki, küçük birim butonları (Selected Unit Button)
var subGivenUnit
var subCalculatedUnit
// İlk çalışan fonksiyon.
var start = function() {
// İçeriği, ekrana sığdır.
page.fit(APP_ORIGINAL_WIDTH, APP_MAX_WIDTH)
// NESNE: Başlangıç sayfası
a0 = cbox(0, 0, page.width, page.height)
that.color = "#FEC108"
// NESNE: Duman beyazı taşıyıcı kutu
a0.b1 = cbox(0, 0, 370, 470)
that.color = "whitesmoke"
that.round = 13
that.element.style.boxShadow = "2px 3px 6px rgba(0, 0, 0, 0.2)"
that.center()
// NESNE: Küçük logo resimi
a0.b1.imgLogo = cimg(0, 40, 80, 80)
that.load("resimler/65/logo.png")
that.center("left")
// NESNE: Başlık
a0.b1.lblTitle = clbl(0, 140, a0.b1.width, 40)
that.text = "Uzunluk Ölçüsü Çevirme"
that.element.style.fontFamily = "opensans-bold"
that.textColor = "#141414"
that.textAlign = "center"
// NESNE: Metin kutularının arkasındaki beyaz taşıyıcı kutu
a0.b1.c1 = cbox(20, 210, 330, 240)
that.color = "white"
that.element.style.boxShadow = "2px 3px 6px rgba(0, 0, 0, 0.05)"
that.round = 13
// NESNE: Verilen uzunluk metin kutusu
a0.b1.c1.txtGivenLength = ctxt(0, 50)
that.title = "Verilen Uzunluk:"
that.minimal = 1
that.color = "#D8D8D8"
that.center("left")
// Her karakter eklendiğinde, hesapla fonksiyonunu çağır.
that.inputElement.addEventListener("keyup", calculateLength)
// Sadece sayı girilebilsin.
that.inputElement.setAttribute("type", "number")
txtGivenLength = that
// NESNE: Hesaplanan uzunluk metin kutusu
a0.b1.c1.txtCalculatedLength = ctxt()
that.title = "Hesaplanan Uzunluk:"
that.minimal = 1
that.color = "#D8D8D8"
that.aline(a0.b1.c1.txtGivenLength, "bottom", 60)
that.enabled = 0
that.opacity = 1
txtCalculatedLength = that
// NESNE: Verilen uzunluk metin kutusunun üstündeki, küçük birim butonu
a0.b1.c1.subGivenUnit = createSelectedUnitButton(txtGivenLength)
that.setSelectedIndex(DEFAULT_GIVEN_LENGTH_UNIT_INDEX)
subGivenUnit = that
// NESNE: Hesaplanan uzunluk metin kutusunun üstündeki, küçük birim butonu
a0.b1.c1.subCalculatedUnit = createSelectedUnitButton(txtCalculatedLength)
that.setSelectedIndex(DEFAULT_CALCULATED_LENGTH_UNIT_INDEX)
subCalculatedUnit = that
// NESNE: Birimleri birbirleri ile değiştirme butonu
a0.b1.c1.imgSwitchUnitsButton = cimg(0, 0, 40, 40)
that.load("resimler/65/change.png")
that.space = 12
that.round = 13
that.rotate = 90
that.color = "whitesmoke"
// Üzerine gelindiğinde, basılabilir işareti görünsün.
that.element.style.cursor = "pointer"
that.left = txtGivenLength.left + txtGivenLength.width - that.width
that.top = txtGivenLength.top + txtGivenLength.height + 10
that.onClick(function(self) {
var temp = subGivenUnit.getSelectedIndex()
subGivenUnit.setSelectedIndex(subCalculatedUnit.getSelectedIndex())
subCalculatedUnit.setSelectedIndex(temp)
calculateLength()
})
// Sayfa boyutu her değiştiğinde,
page.onResize(function() {
page.fit(APP_ORIGINAL_WIDTH, APP_MAX_WIDTH)
a0.width = page.width
a0.height = page.height
a0.b1.center()
})
}
// Metin kutusunun üstünde, küçük bir birim butonu oluşturur.
var createSelectedUnitButton = function(txtObject) {
var object = clbl(0, 0, "auto", 28)
that.color = "white"
that.textColor = "#4A4A4A"
that.fontSize = 16
that.round = 13
that.spaceX = 10
that.spaceY = 3
that.element.style.fontFamily = "opensans-bold"
that.element.style.cursor = "pointer"
// Konumu, sağa yaslanmış olarak hesapla:
// Böylece, metin değiştiğinde, sola doğru uzar.
that.right = txtObject.upperObject.width - txtObject.left - txtObject.width + 10
that.top = txtObject.top
that.top += (txtObject.height / 2) - (that.height / 2)
// NOT: Yükseklik manuel olarak ayarlanmıştır.
// NOT: Genişlik "auto" ama sağa dayalı olduğu için,
// boyutu değiştiğinde, yeniden konumlandırmaya gerek yok.
// Böylece, object.onResize() kullanmaya gerek kalmamıştır.
object.setSelectedIndex = function(index) {
// En az
if (index < 0) {
index = 0
}
// En fazla
if (index > lengthMeasurementUnits.length - 1) {
index = lengthMeasurementUnits.length - 1
}
object.text = lengthMeasurementUnits[index].short
object.selectedIndex = index
}
object.getSelectedIndex = function() {
return object.selectedIndex
}
object.openUnitSelectionDialog = function(self) {
createUnitSelectionDialog(object, object.getSelectedIndex())
}
object.onClick(object.openUnitSelectionDialog)
// İlk birim seçilsin,
object.setSelectedIndex(0)
// kütüphane sistemine dahil et.
makeBasicObject(object)
return object
}
// Birim seçme diyalog penceresi oluştur.
var createUnitSelectionDialog = function(connectedObject, selectedIndex) {
// NOT: Bu diyalog nesnesi, her seferinde yeniden oluşturulur.
// Ve seçim yapıldığında, diyalog nesnesi silinir.
// NESNE: Diyalog penceresinin arkasındaki karartma kutusu.
var object = cbox(0, 0, page.width, page.height)
that.color = "rgba(0, 0, 0, 0.8)"
// NESNE: Karartma kutusu boyutlarındaki, pencereyi kapatma butonu (görünmez).
object.boxbtnClose = cbox(0, 0, page.width, page.height)
that.color = "transparent"
// NESNE: Birim butonlarının arkasındaki beyaz kutu.
object.b1 = cbox(0, 0, 250, 300)
that.color = "white"
that.round = 13
// Bu fonksiyon, onClick() ile ayarlanmadan önce tanımlanmış olmalı.
object.selectUnit = function(self) {
connectedObject.setSelectedIndex(self.index)
calculateLength()
object.remove()
}
object.boxbtnClose.index = selectedIndex
object.boxbtnClose.onClick(object.selectUnit)
var TOP_BOTTOM_SPACE = 10
// Birim seçme butonlarını oluştur.
for (var i = 0; i < lengthMeasurementUnits.length; i++) {
object.b1["btn" + i] = cbtn()
that.color = "white"
that.fontSize = 20
that.round = 0
that.text = lengthMeasurementUnits[i].name
that.width = object.b1.width
that.top = i * 50 + TOP_BOTTOM_SPACE
that.minimal = 1
// Nesnenin taşıdığı index değeri.
that.index = i
// Önceden seçilmiş olanı farklı göster.
if (i == selectedIndex) {
that.color = "#FEC108"
} else {
that.setMotion("background-color 0.3s")
that.element.classList.add("unit-selection-dialog-buttons-type")
}
that.onClick(object.selectUnit)
// Oluşturulan butonlara göre, taşıyıcı nesnenin yüksekliğini ayarla.
object.b1.height = that.top + that.height + TOP_BOTTOM_SPACE
}
// Taşıyıcı kutuyu ortala.
object.b1.center()
// Sayfa boyutu her değiştiğinde, bu nesne için bu ayarları yeniden düzenle.
page.onResize(function() {
object.width = page.width
object.height = page.height
object.b1.center()
})
// NOT: basic.js sistemine dahil edilmesine gerek yoktur. makeBasicObject(object)
// - Dışarıdan, that ile ulaşılmayacak.
// - Bir kutu nesnesinin içinde, otomatik taşınmasına gerek yok.
}
// Verilen bilgilere göre hesaplama yap.
var calculateLength = function() {
// NOT: Birimler arasındaki değişimi hesaplamak için sıra numarasından (index) faydalanıyor.
// Verilen bilgi boş ise,
if (txtGivenLength.text == "") {
// Hesaplanan bilgi boş olarak ayarlansın.
txtCalculatedLength.text = ""
} else {
// Verilen bilgiyi sayısal olarak al.
var givenLength = parseFloat(txtGivenLength.text)
// Verilen bilginin, birim dizi sırasını al.
var givenUnitIndex = subGivenUnit.getSelectedIndex()
// Hesaplanan bilginin, birim dizi sırasını al.
var calculatedUnitIndex = subCalculatedUnit.getSelectedIndex()
var generateNumber = function(count) {
var number = "1"
for (var i = 0; i < count; i++) {
number += "0"
}
return num(number, "integer")
}
var answer = 0
var zeroCount = 0
// Ölçü birimleri arasındaki çevirme işlemi.
if (givenUnitIndex > calculatedUnitIndex) {
zeroCount = givenUnitIndex - calculatedUnitIndex
answer = givenLength / generateNumber(zeroCount)
} else if (givenUnitIndex < calculatedUnitIndex) {
zeroCount = calculatedUnitIndex - givenUnitIndex
answer = givenLength * generateNumber(zeroCount)
} else {
answer = givenLength
}
// Sonucu göster.
txtCalculatedLength.text = answer
}
}
</script>
</head>
<body>
<!-- HTML içeriği -->
</body>
</html>