Skip to content

Commit 75135fe

Browse files
Update mouse event basics
Change the outdated method of `which` with `button` as it is on the current page.
1 parent 2054f02 commit 75135fe

File tree

1 file changed

+120
-106
lines changed
  • 2-ui/3-event-details/1-mouse-events-basics

1 file changed

+120
-106
lines changed
Lines changed: 120 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,103 @@
1-
# Mouse events basics
1+
# Fare olaylarıyla ilgili temel bilgiler
22

3-
Mouse events come not only from "mouse manipulators", but are also emulated on touch devices, to make them compatible.
3+
Fare olayları yalnızca "fare olayi ya da manipülasyonu" ile gerçekleşmez, aynı zamanda dokunmatik cihazlara da uyumlu hale getirmek için bu cihazlarda taklit edilir.
44

5-
In this chapter we'll get into more details about mouse events and their properties.
5+
Bu bölümde fare olayları ve özellikleri hakkında daha fazla ayrıntıya gireceğiz.
66

7-
## Mouse event types
7+
## Fare olay türleri
88

9-
We can split mouse events into two categories: "simple" and "complex"
9+
Fare olaylarını "basit" ve "karmaşık" olarak iki kategoriye ayırabiliriz.
1010

11-
### Simple events
11+
### Basit fare olayları
1212

13-
The most used simple events are:
13+
En çok kullanılan basit olaylar şunlardır:
1414

15-
`mousedown/mouseup`
16-
: Mouse button is clicked/released over an element.
15+
`mousedown/mouseup`
16+
: Fare ile bir öğenin üzerine tıklanır / bırakılır.
1717

1818
`mouseover/mouseout`
19-
: Mouse pointer comes over/out from an element.
19+
: Fare ile bir öğenin üzerine gelinir / uzaklaşılır.
2020

2121
`mousemove`
22-
: Every mouse move over an element triggers that event.
22+
: Bir öğenin üzerine yapılan her fare bu olayı tetikler.
2323

24-
...There are several other event types too, we'll cover them later.
24+
...Başka olay türleri de var, bunları daha sonra ele alacağız.
2525

26-
### Complex events
26+
### Karmaşık fare olayları
2727

2828
`click`
29-
: Triggers after `mousedown` and then `mouseup` over the same element if the left mouse button was used.
29+
: Farenin sol tuşuna basıldığında, aynı öğe üzerinde `mousedown` ve ardından `mouseup` olayının gerçekleşmesi ile tetiklenir.
3030

3131
`contextmenu`
32-
: Triggers after `mousedown` if the right mouse button was used.
32+
: Farenin sağ tuşuna basıldığında, `mousedown` olayı gerçekleşirse tetiklenir.
3333

3434
`dblclick`
35-
: Triggers after a double click over an element.
35+
: Bir ögenin üzerine çift tıklandıktan sonra tetiklenir.
3636

37-
Complex events are made of simple ones, so in theory we could live without them. But they exist, and that's good, because they are convenient.
37+
Karmaşık olaylar basit olayların birleşimi, bu yüzden teoride onlarsız da işlerimizi görebiliriz. Ama karmaşık olayların var olmaları iyi çünkü kullanışlılar.
3838

39-
### Events order
39+
### Olay sırası
4040

41-
An action may trigger multiple events.
41+
Bir eylem birden fazla fare olayı tetikleyebilir.
4242

43-
For instance, a click first triggers `mousedown`, when the button is pressed, then `mouseup` and `click` when it's released.
43+
Örneğin, bir tıklama, düğmeye basıldığında önce `mousedown` olayını, ardından `mouseup` olayını ve fare butonu bırakıldığında `click` olayını tetikler.
4444

45-
In cases when a single action initiates multiple events, their order is fixed. That is, the handlers are called in the order `mousedown` -> `mouseup` -> `click`. Events are handled in the same sequence: `onmouseup` finishes before `onclick` runs.
45+
Tek bir eylemin birden çok fare olayı başlattığı durumlarda, bunların sırası sabittir. İşleyiciler her zaman şu sıraya göre çağırılır: `mousedown` -> `mouseup` -> `click`. Olaylar aynı sırayla işlenir: önce `onclick` çalışır sonra `onmouseup`.
4646

47-
```online
48-
Click the button below and you'll see the events. Try double-click too.
47+
````online
48+
Gerçekleşen eylemleri görmek için aşağıdaki butonu tıkla. Çift tıklamayı da dene.
4949
50-
On the teststand below all mouse events are logged, and if there are more than 1 second delay between them, then they are separated by a horizontal ruler.
50+
Aşağıdaki test standında, tüm fare olayları kaydedilir ve aralarında 1 saniyeden fazla gecikme varsa, yatay bir cetvel ile ayrılırlar.
5151
52-
Also we can see the `which` property that allows to detect the mouse button.
52+
Ayrıca, fare butonuna tıklandıgında algılanmasını sağlayan "which" özelliğini görebilirsiniz.
5353
5454
<input onmousedown="return logMouse(event)" onmouseup="return logMouse(event)" onclick="return logMouse(event)" oncontextmenu="return logMouse(event)" ondblclick="return logMouse(event)" value="Click me with the right or the left mouse button" type="button"> <input onclick="logClear('test')" value="Clear" type="button"> <form id="testform" name="testform"> <textarea style="font-size:12px;height:150px;width:360px;"></textarea></form>
5555
```
5656
57-
## Getting the button: which
57+
Tıklamayla ilgili bütün olaylar `button` özelliğine sahiptir ve bu da olayın tam olarak hangi fare butonu ile çalıştığını bulmamızı sağlar.
58+
59+
`click` ve `contextmenu` olayları için kullanılamaz çünkü `click` sadece sol tıklamada, `contextmenu` sadece sağ tıklamada gerçekleşir.
60+
61+
Ancak `mousedown` ve `mouseup` olaylarını takip etmek istersek, o zaman `button` özelliğine ihtiyacımız olur, çünkü bu olaylar herhangi bir fare butonu ile gerçekleşebilir, bu yüzden `button` "right-mousedown" (sağ- tıklama) ile "left-mousedown" (sol-tıklama) olayını ayırt etmemizi sağlar.
62+
63+
Üç olası değer vardır:
5864
59-
Click-related events always have the `which` property, which allows to get the exact mouse button.
65+
| Button State | event.button |
66+
| Sol tuşa tıklama | 0 |
67+
| Orta tuşa tıklama | 1 |
68+
| Sağ tuşa tıklama | 2 |
69+
| X1 tuşa tıklama (geri tuşu) | 3 |
70+
| X2 tuşa tıklama (ileri tuşu) | 4 |
6071
61-
It is not used for `click` and `contextmenu` events, because the former happens only on left-click, and the latter -- only on right-click.
72+
Çoğu fare aygıtında yalnızca sol ve sağ düğmeler bulunur, bu nedenle olası değerler 0 veya 2'dir. Dokunmatik aygıtlar da üzerlerine bir kez dokunduğunda benzer olaylar oluşturur.
6273
63-
But if we track `mousedown` and `mouseup`, then we need it, because these events trigger on any button, so `which` allows to distinguish between "right-mousedown" and "left-mousedown".
74+
Ayrıca, o anda basılan tüm düğmelere düğme başına bir bit olmak üzere tamsayı olarak sahip olan `event.buttons` özelliği vardır. Uygulamada bu özellik çok nadiren kullanılır, ihtiyacınız olursa [MDN](https://developer.mozilla.org/en-US/docs/Web/api/MouseEvent/buttons)'de ayrıntıları bulabilirsiniz.
6475
65-
There are the three possible values:
76+
## Zamanı geçmiş which butonu
6677
67-
- `event.which == 1` -- the left button
68-
- `event.which == 2` - the middle button
69-
- `event.which == 3` - the right button
78+
Eski kodlar, olası değerlerle buton elde etmenin eski bir yolu olan event.which özelliğini kullanabilir:
7079
71-
The middle button is somewhat exotic right now and is very rarely used.
80+
- `event.which == 1` -- sol tuşa tıklama
81+
- `event.which == 2` - orta tuşa tıklama
82+
- `event.which == 3` - sağ tuşa tıklama
7283
73-
## Modifiers: shift, alt, ctrl and meta
84+
**Şu an itibariyle artık kullanımdan kaldırılan event.which olayını artık kullanmamalıyız.**
7485
75-
All mouse events include the information about pressed modifier keys.
86+
## Değiştiriciler: shift, alt, ctrl and meta
7687
77-
The properties are:
88+
Tüm fare olayları, basılan değiştirici tuşlarla ilgili bilgileri içerir.
89+
90+
Özellikler (properties):
7891
7992
- `shiftKey`
8093
- `altKey`
8194
- `ctrlKey`
82-
- `metaKey` (`key:Cmd` for Mac)
95+
- `metaKey` (`key:Cmd` Mac için)
8396
84-
For instance, the button below only works on `key:Alt+Shift`+click:
97+
Örneğin, aşağıdaki düğme yalnızca `Alt+Shift`+fare tıklaması ile beraber çalışır:
8598
8699
```html autorun height=60
87-
<button id="button">Alt+Shift+Click on me!</button>
100+
<button id="button">Alt+Shift+Click tıkla!</button>
88101
89102
<script>
90103
button.onclick = function(event) {
@@ -97,62 +110,64 @@ For instance, the button below only works on `key:Alt+Shift`+click:
97110
</script>
98111
```
99112
100-
```warn header="Attention: on Mac it's usually `Cmd` instead of `Ctrl`"
101-
On Windows and Linux there are modifier keys `key:Alt`, `key:Shift` and `key:Ctrl`. On Mac there's one more: `key:Cmd`, it corresponds to the property `metaKey`.
113+
```warn header="Dikkat: Mac için genellikle `Ctrl` yerine `Cmd` kullanılır."
114+
Windows ve Linux işletim sistemlerinde `key:Alt`, `key:Shift` and `key:Ctrl` değiştiricileri bulunur. Mac için bir değiştirici daha var: `key:Cmd`, bu `metaKey` özelliğine karşılık gelir.
102115
103-
In most cases when Windows/Linux uses `key:Ctrl`, on Mac people use `key:Cmd`. So where a Windows user presses `key:Ctrl+Enter` or `key:Ctrl+A`, a Mac user would press `key:Cmd+Enter` or `key:Cmd+A`, and so on, most apps use `key:Cmd` instead of `key:Ctrl`.
116+
Çoğu zaman Windows/Linux üzerinde bir durum için `key:Ctrl` kullanılırken, Mac üzerinde `key:Cmd` kullanılır. Bu yüzden Windows kullanıcısı `key:Ctrl+Enter` ya da `key:Ctrl+A` kullandığı zaman, Mac kullanıcısı `key:Cmd+Enter` ya da `key:Cmd+A` kullanır. Bir çok uygulama da `key:Ctrl` yerine `key:Cmd` kullanır.
104117
105-
So if we want to support combinations like `key:Ctrl`+click, then for Mac it makes sense to use `key:Cmd`+click. That's more comfortable for Mac users.
118+
Dolayısıyla, Ctrl + tıklama gibi kombinasyonları kullanacagımız zaman, Mac için Cmd + tıklamayı kullanmak mantıklıdır. Bu, Mac kullanıcıları için fiziksel açıdan da daha rahat bir çözümdür.
106119
107-
Even if we'd like to force Mac users to `key:Ctrl`+click -- that's kind of difficult. The problem is: a left-click with `key:Ctrl` is interpreted as a *right-click* on Mac, and it generates the `contextmenu` event, not `click` like Windows/Linux.
120+
Mac kullanıcılarını `key: Ctrl` + tıklama yapmaya zorlasak bile sorun şudur: `key:Ctrl` ile sol tıklama, Mac'te *sağ tıklama* olarak yorumlanır ve Windows / Linux gibi `click` değil, `contextmenu` olayını oluşturur.
108121
109-
So if we want users of all operational systems to feel comfortable, then together with `ctrlKey` we should use `metaKey`.
122+
Dolayısıyla, tüm işletim sistemlerinin kullanıcılarının kendilerini rahat hissetmelerini istiyorsak, o zaman `ctrlKey` ile birlikte `metaKey` kullanmalıyız.
110123
111-
For JS-code it means that we should check `if (event.ctrlKey || event.metaKey)`.
124+
JS kodu için bu, `if (event.ctrlKey || event.metaKey) şeklinde tuşları kontrol etmemiz gerektiği anlamına gelir.
112125
```
113126
114-
```warn header="There are also mobile devices"
115-
Keyboard combinations are good as an addition to the workflow. So that if the visitor has a
116-
keyboard -- it works. And if your device doesn't have it -- then there's another way to do the same.
127+
```warn header="Hesaba katmamız gereken bir başka durum da mobil cihazlar"
128+
Klavye kombinasyonları ziyaretçinin klavyesi varsa çalışır.
129+
Ancak eğer kullanıcı klavyesiz kullanıyorsa -- o zaman aynısını yapmanın başka bir yolu var.
117130
```
118131
119-
## Coordinates: clientX/Y, pageX/Y
132+
## Koordinatlar: clientX/Y, pageX/Y
133+
134+
Tüm fare olaylarının iki farklı türde koordinatları vardır:
120135
121-
All mouse events have coordinates in two flavours:
136+
1. Pencereye bağlı koordinatlar (Window-relative): `clientX` ve `clientY`.
137+
2. Belgeye bağlı koordınatlar (Document-relative): `pageX` ve `pageY`.
122138
123-
1. Window-relative: `clientX` and `clientY`.
124-
2. Document-relative: `pageX` and `pageY`.
139+
Kısaca, belgeye bağlı koordinatlar pageX / Y, belgenin en sol üst köşesinden sayılır ve sayfa kaydırıldığında da değişmez, clientX / Y ise geçerli pencerenin (wındow) sol üst köşesinden sayılır. Sayfa kaydırıldığında değişirler.
125140
126-
For instance, if we have a window of the size 500x500, and the mouse is in the left-upper corner, then `clientX` and `clientY` are `0`. And if the mouse is in the center, then `clientX` and `clientY` are `250`, no matter what place in the document it is. They are similar to `position:fixed`.
141+
Örneğin, 500x500 boyutunda bir penceremiz varsa ve fare en sol üst köşedeyse, o zaman `clientX` ve `clientY` `0` olur. Fare tam ortadaysa, o zaman belgenin neresinde olursa olsun `clientX` ve `clientY` `250` olur. `position:fixed` ile benzer şekilde çalışır.
127142
128143
````online
129-
Move the mouse over the input field to see `clientX/clientY` (it's in the `iframe`, so coordinates are relative to that `iframe`):
144+
`clientX/clientY` değerlerini görmek için fare ile üzerinden geç. ("iframe" içinde yapıldı, bu nedenle koordinatlar bu "iframe" e göredir):
130145
131146
```html autorun height=50
132147
<input onmousemove="this.value=event.clientX+':'+event.clientY" value="Mouse over me">
133148
```
134149
````
135150

136-
Document-relative coordinates are counted from the left-upper corner of the document, not the window.
137-
Coordinates `pageX`, `pageY` are similar to `position:absolute` on the document level.
151+
Belgeye bağlı koordinatlar, pencereden değil, belgenin sol üst köşesinden sayılır.
152+
"PageX", "pageY" koordinatları, belge düzeyinde "position: absolute" ile benzerdir.
138153

139-
You can read more about coordinates in the chapter <info:coordinates>.
154+
Bunlar arasındaki farkı burada daha detaylı olarak işledik <info:coordinates>.
140155

141-
## No selection on mousedown
156+
## mousedown olayında metin seçimini önleme
142157

143-
Mouse clicks have a side-effect that may be disturbing. A double click selects the text.
158+
Fare tıklamalarının rahatsız edici olabilecek bir yan etkisi vardır. Çift tıklama metni seçer.
144159

145-
If we want to handle click events ourselves, then the "extra" selection doesn't look good.
160+
Bütün tıklama olaylarını kendimiz kontrole almak istiyorsak, "ekstra" olarak metin seçimi iyi olmayabilir.
146161

147-
For instance, a double-click on the text below selects it in addition to our handler:
162+
Örneğin, aşağıdaki metne çift tıklamak, işleyicimize ek olarak bir tıkladıgımız kelimeyi seçer:
148163

149164
```html autorun height=50
150-
<b ondblclick="alert('dblclick')">Double-click me</b>
165+
<b ondblclick="alert('dblclick')">Bana çift tıkla</b>
151166
```
152167

153-
There's a CSS way to stop the selection: the `user-select` property from [CSS UI Draft](https://www.w3.org/TR/css-ui-4/).
168+
Seçimi durdurmanın bir CSS yolu vardır: `user-select` özelliğini buradan incelyebilirsiniz. [CSS UI Draft](https://www.w3.org/TR/css-ui-4/).
154169

155-
Most browsers support it with prefixes:
170+
Çoğu tarayıcı bunu destekler:
156171

157172
```html autorun height=50
158173
<style>
@@ -164,80 +179,79 @@ Most browsers support it with prefixes:
164179
}
165180
</style>
166181

167-
Before...
182+
Önce...
168183
<b ondblclick="alert('Test')">
169-
Unselectable
184+
Seçilemez
170185
</b>
171-
...After
186+
...Sonra
172187
```
173188

174-
Now if you double-click on "Unselectable", it doesn't get selected. Seems to work.
189+
Şimdi "Seçilemez" üzerine çift tıklarsanız, seçilmez. Çalışıyor gibi görünüyor.
175190

176-
...But there is a potential problem! The text became truly unselectable. Even if a user starts the selection from "Before" and ends with "After", the selection skips "Unselectable" part. Do we really want to make our text unselectable?
191+
...Ancak potansiyel bir sorun var! Metin gerçekten seçilemez hale geldi. Kullanıcı seçimi "Önce" den başlatıp "Sonra" ile bitirse bile, seçim "Seçilemeyen" kısmı atlar. Metnimizi gerçekten seçilemez hale getirmek istiyor muyuz?
177192

178-
Most of time, we don't. A user may have valid reasons to select the text, for copying or other needs. That may be inconvenient if we don't allow them to do it. So this solution is not that good.
193+
Çoğu zaman bunu istemeyiz. Bir kullanıcının metni seçmek, kopyalamak veya diğer ihtiyaçları için geçerli nedenleri olabilir. Bunu yapmalarına izin vermezsek bu rahatsız edici olabilir. Yani bu çözüm o kadar iyi değil.
179194

180-
What we want is to prevent the selection on double-click, that's it.
195+
İstediğimiz sadece çift tıklamayla seçimi engellemek, hepsi bu.
181196

182-
A text selection is the default browser action on `mousedown` event. So the alternative solution would be to handle `mousedown` and prevent it, like this:
197+
Metin seçimi `mousedown` olayıyla beraber gerçekleşen bir tarayıcı işlemi. Bu yüzden alternatif yöntem `mousedown` olayını engellemek, şu şekilde:
183198

184199
```html autorun height=50
185-
Before...
200+
Önce...
186201
<b ondblclick="alert('Click!')" *!*onmousedown="return false"*/!*>
187-
Double-click me
202+
Çift tıkla
188203
</b>
189-
...After
204+
...Sonra
190205
```
191206

192-
Now the bold element is not selected on double clicks.
207+
Artık kalın yazı tipiyle yazılmış öğe çift tıklamayla seçilmiyor.
193208

194-
The text inside it is still selectable. However, the selection should start not on the text itself, but before or after it. Usually that's fine though.
209+
İçindeki metin hala seçilebilir. Ancak, seçim metnin kendisinde değil, ondan önce veya sonra başlamalıdır. Yine de genellikle bu sorun olmaz ve en iyi çözüm alternatifidir.
195210

196-
````smart header="Canceling the selection"
197-
Instead of *preventing* the selection, we can cancel it "post-factum" in the event handler.
198211

199-
Here's how:
212+
````smart header="Metin seçimini iptal etme"
213+
Seçimi *önlemek* yerine, olay işleyicisini "post-factum" iptal edebiliriz.
214+
Şu şekilde:
200215
201216
```html autorun height=50
202-
Before...
217+
Önce...
203218
<b ondblclick="*!*getSelection().removeAllRanges()*/!*">
204-
Double-click me
219+
Çift tıkla!
205220
</b>
206-
...After
221+
...Sonra
207222
```
208223
209-
If you double-click on the bold element, then the selection appears and then is immediately removed. That doesn't look nice though.
210-
````
224+
Kalın yazı tipiyle yazılmış öğeye çift tıklarsanız, seçim görünür ve hemen kaldırılır. Yine de bu hoş görünmüyor.````
211225
212-
````smart header="Preventing copying"
213-
If we want to disable selection to protect our content from copy-pasting, then we can use another event: `oncopy`.
226+
````smart header="Kopyalamayı önlemek"
227+
İçeriğimizi kopyalayıp yapıştırmaya karşı korumak için seçimi devre dışı bırakmak istiyorsak, başka bir özellik kullanabiliriz.
214228
215229
```html autorun height=80 no-beautify
216230
<div *!*oncopy="alert('Copying forbidden!');return false"*/!*>
217-
Dear user,
218-
The copying is forbidden for you.
219-
If you know JS or HTML, then you can get everything from the page source though.
231+
Sevgili kullanıcı,
232+
Kopyalama bu metin için yasaktır.
233+
Eğer JS ve HTML biliyorsanız yine de buradaki her şeyi kopyalayabilirsiniz.
220234
</div>
221235
```
222-
If you try to copy a piece of text in the `<div>`, that won't work, because the default action `oncopy` is prevented.
236+
Eğer `<div>` içindeki bir yazıyı kopyalamaya çalışırsanız, işe yaramaz, çünkü normal olarak varsayılan `oncopy` özelliği şimdi engellendi.
223237
224-
Surely that can't stop the user from opening HTML-source, but not everyone knows how to do it.
238+
Elbette bu, kullanıcının HTML kaynağını açmasını engelleyemez, ancak herkes bunu nasıl yapacağını bilmiyor.
225239
````
226240

227-
## Summary
241+
## Özet
228242

229-
Mouse events have the following properties:
243+
Fare olayları aşağıdaki özelliklere sahiptir:
230244

231-
- Button: `which`.
232-
- Modifier keys (`true` if pressed): `altKey`, `ctrlKey`, `shiftKey` and `metaKey` (Mac).
233-
- If you want to handle `key:Ctrl`, then don't forget Mac users, they use `key:Cmd`, so it's better to check `if (e.metaKey || e.ctrlKey)`.
245+
- Buton: `button`.
246+
- Değiştirici tuşlar (basıldığında `true` değerini verir): `altKey`, `ctrlKey`, `shiftKey` and `metaKey` (Mac).
247+
- `key:Ctrl` ile işlem yapacaksanız, Mac kullanıcılarını unutmayın, Mac kullanıcıları `key:Cmd` kullanırlar bu sebeple `if (e.metaKey || e.ctrlKey)` ile bunu kontrol etmeniz gerekir.
234248

235-
- Window-relative coordinates: `clientX/clientY`.
236-
- Document-relative coordinates: `pageX/pageY`.
249+
- Pencereye bağlı koordinatlar : `clientX/clientY`.
250+
- Belgeye bağlı koordinatlar : `pageX/pageY`.
237251

238-
It's also important to deal with text selection as an unwanted side-effect of clicks.
252+
Ayrıca, tıklamaların istenmeyen bir yan etkisi olarak metin seçimiyle uğraşmak da önemlidir.
239253

240-
There are several ways to do this, for instance:
241-
1. The CSS-property `user-select:none` (with browser prefixes) completely disables text-selection.
242-
2. Cancel the selection post-factum using `getSelection().removeAllRanges()`.
243-
3. Handle `mousedown` and prevent the default action (usually the best).
254+
Bunu yapmanın birkaç yolu vardır, örneğin:
255+
1. CSS methodu `user-select:none` tamamiyle metin seçimini engeller.
256+
2. Ondan sonra gelecek metin seçimini iptal et; `getSelection().removeAllRanges()`.
257+
3.`mousedown` olayını engelle ve varsayılan metin seçimi durumunu engelle (genellikle en iyi çözüm).

0 commit comments

Comments
 (0)