Skip to content

Commit 9a386b6

Browse files
committed
Mouse Events Basics
1 parent 76b73b3 commit 9a386b6

3 files changed

Lines changed: 90 additions & 88 deletions

File tree

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
importance: 5
1+
الأهمية: 5
22

33
---
44

5-
# Selectable list
5+
# قائمة قابلة للتحديد
66

7-
Create a list where elements are selectable, like in file-managers.
7+
قم بإنشاء قائمة يمكن فيها تحديد العناصر , مثل الموجودة بمدير الملفات.
88

9-
- A click on a list element selects only that element (adds the class `.selected`), deselects all others.
10-
- If a click is made with `key:Ctrl` (`key:Cmd` for Mac), then the selection is toggled on the element, but other elements are not modified.
9+
- عند النقر فوق عنصر في القائمة يتم تحديد هذا العنصر فقط (إضافة الفئةs `.selected`), وإلغاء تحديد العناصر الأخرى.
10+
- إذا تم النقر مع `key:Ctrl` (`key:Cmd` لنظام Mac), يتم التحديد على العنصر ، ولكن لا يتم تغيير بقية العناصر
1111

12-
The demo:
12+
مثال توضيحي:
1313

1414
[iframe border="1" src="solution" height=180]
1515

16-
P.S. For this task we can assume that list items are text-only. No nested tags.
16+
P.S. ملاحظة: في هذه المهمة ، تحتوي جميع عناصر القائمة على نص فقط. لا توجد علامات متداخلة
1717

18-
P.P.S. Prevent the native browser selection of the text on clicks.
18+
P.P.S. منع اختيار النص الأصلي للمتصفح على النقرات.

2-ui/3-event-details/1-mouse-events-basics/article.md

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
`contextmenu`
2828

29-
:يعمل عندما يتم الضغط على زر الفأرة الأيمن. وهناك طرق أخرى لفتح قائمة السياق ، على سبيل المثال باستخدام مفتاح معين من لوحة المفاتيح ، ويمكن أيضًا استخدامه في هذه الحالة ، لذا فهو ليس بالضبط حدث للماوس .
29+
يعمل عندما يتم الضغط على زر الفأرة الأيمن. وهناك طرق أخرى لفتح قائمة السياق ، على سبيل المثال باستخدام مفتاح معين من لوحة المفاتيح ، ويمكن أيضًا استخدامه في هذه الحالة ، لذا فهو ليس بالضبط حدث للماوس .
3030

3131
... وهناك أيضا العديد من الأحداث الأخرى ، واللتى سنتطرق لها لاحقًا
3232
.
3333

34-
## نرتيب الأحداث
34+
## ترتيب الأحداث
3535

3636
كما ترى من القائمة السابقة ، قد يقوم إجراء المستخدم بتشغيل أكثر من حدث أو أحداث متعددة
3737

@@ -54,164 +54,166 @@
5454

5555
## زر الماوس
5656

57-
Click-related events always have the `button` property, which allows to get the exact mouse button.
57+
تحتوي دائما الأحداث المتعلقة بالنقر على خاصية `button`, والتي تسمح لك بأستخدام زر الماوس.
5858

59-
We usually don't use it for `click` and `contextmenu` events, because the former happens only on left-click, and the latter -- only on right-click.
59+
وعادة لا نستخدم هذه الخاصية لكل من هذين الحدثين `click` و `contextmenu` , وذلك لأن الأول يحدث فقط عند النقر بزر الماوس الأيسر ، والأخير - فقط عند النقر بزر الماوس الأيمن.
6060

61-
From the other hand, `mousedown` and `mouseup` handlers we may need `event.button`, because these events trigger on any button, so `button` allows to distinguish between "right-mousedown" and "left-mousedown".
61+
من ناحية أخرى فإن, `mousedown` و `mouseup` قد تحتاج معالجتها إلى `event.button`, وذلك لأن هذه الأحداث من الممكن أن تعمل على أى زر لذا فإن `button` يتيح لك التمييز بين "زر الماوس الأيمن" و "زر الماوس الأيسر".
6262

63-
The possible values of `event.button` are:
63+
القيم المحتملة لـ `event.button` هي:
6464

65-
| Button state | `event.button` |
65+
| حالة الزر | `event.button` |
6666
|--------------|----------------|
67-
| Left button (primary) | 0 |
68-
| Middle button (auxillary) | 1 |
69-
| Right button (secondary) | 2 |
70-
| X1 button (back) | 3 |
71-
| X2 button (forward) | 4 |
67+
| الزر الأيسر (أساسي) | 0 |
68+
| الزر الأوسط (مساعد) | 1 |
69+
| الزر الايمن (ثانوي) | 2 |
70+
| X1 زر (خلف) | 3 |
71+
| X2 زر (أمام) | 4 |
7272

73-
Most mouse devices only have the left and right buttons, so possible values are `0` or `2`. Touch devices also generate similar events when one taps on them.
73+
تحتوي معظم أجهزة الماوس على الزرين الأيسر والأيمن فقط ، لذا فإن القيم المحتملة هي "0" أو "2". وكذلك الأجهزة التي تعمل باللمس أيضًا تولد أحداثًا مماثلة عندما ينقر عليها .
7474

75-
Also there's `event.buttons` property that has all currently pressed buttons as an integer, one bit per button. In practice this property is very rarely used, you can find details at [MDN](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons) if you ever need it.
75+
هناك أيضًا خاصية `event.buttons` تحتوي على جميع الأزرار المضغوطة حاليًا كعدد صحيح ، بت واحد لكل زر. في الواقع ، نادرًا ما يتم استخدامها, يمكنك الرجوع الى مزيد من التفاصيل على [MDN](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons)اذا احتجت اليها في أي وقت.
7676

77-
```warn header="The outdated `event.which`"
78-
Old code may use `event.which` property that's an old non-standard way of getting a button, with possible values:
77+
```warn header="عفا عليها الزمن `event.which`"
78+
في الأكواد القديمة قد تجد استخدام خاصية `event.which` وهي تعتبر طريقة قديمة غير قياسية للحصول على زر ، مع القيم المحتملة :
7979

80-
- `event.which == 1`left button,
81-
- `event.which == 2`middle button,
82-
- `event.which == 3`right button.
80+
- `event.which == 1`الزر الأيسر,
81+
- `event.which == 2`الزر الأوسط,
82+
- `event.which == 3`الزر الأيمن.
8383

84-
As of now, `event.which` is deprecated, we shouldn't use it.
84+
إعتباراً من الأن, `event.which` تم ايقافها, لذا لا يجب إستخدامها.
8585
```
8686
87-
## Modifiers: shift, alt, ctrl and meta
87+
## مفاتيح التعديل: shift, alt, ctrl و meta
8888
89-
All mouse events include the information about pressed modifier keys.
89+
تتضمن جميع أحداث الماوس معلومات عند الضغط على مفاتيح التعديل
9090
91-
Event properties:
91+
خصائص الحدث :
9292
9393
- `shiftKey`: `key:Shift`
94-
- `altKey`: `key:Alt` (or `key:Opt` for Mac)
94+
- `altKey`: `key:Alt` (أو `key:Opt` لنظام تشغيل Mac)
9595
- `ctrlKey`: `key:Ctrl`
96-
- `metaKey`: `key:Cmd` for Mac
96+
- `metaKey`: `key:Cmd` لنظام Mac
9797
98-
They are `true` if the corresponding key was pressed during the event.
98+
تكون القيمة `true`   إذا تم الضغط على المفتاح المقابل أثناء الحدث.
9999
100-
For instance, the button below only works on `key:Alt+Shift`+click:
100+
على سبيل المثال, الزر أدناه يعمل فقط عند الضغط على `key:Alt+Shift` ثم النقر :
101101
102102
```html autorun height=60
103-
<button id="button">Alt+Shift+Click on me!</button>
103+
<button id="button">Alt+Shift+أنقر علي!</button>
104104
105105
<script>
106106
button.onclick = function(event) {
107107
*!*
108108
if (event.altKey && event.shiftKey) {
109109
*/!*
110-
alert('Hooray!');
110+
alert('مرحى!');
111111
}
112112
};
113113
</script>
114114
```
115115

116-
```warn header="Attention: on Mac it's usually `Cmd` instead of `Ctrl`"
117-
On Windows and Linux there are modifier keys `key:Alt`, `key:Shift` and `key:Ctrl`. On Mac there's one more: `key:Cmd`, corresponding to the property `metaKey`.
116+
```warn header="إنتبه: نظام Mac عادة نستخدم `Cmd` بدلا من `Ctrl`"
117+
في نظامى التشغيل Windows و Linux توجد مفاتيح التعديل `key:Alt`, `key:Shift` و `key:Ctrl`. بينما نظام تشغيل Mac هناك آخر: `key:Cmd`, يتوافق مع خاصية `metaKey`.
118118

119-
In most applications, when Windows/Linux uses `key:Ctrl`, on Mac `key:Cmd` is used.
119+
في معظم التطبيقات, عندما Windows/Linux بستخدم `key:Ctrl`, على Mac نستخدم `key:Cmd`.
120120

121-
That is: 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.
121+
وهذا يعنى: عندما يقوم مستخدم Windows بالضغط على `key:Ctrl+Enter` أو `key:Ctrl+A`, فإن مستخدم Mac يضغط على `key:Cmd+Enter` أو `key:Cmd+A`, وهكذا.
122122

123-
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.
123+
لذا إذا أردنا دعم مجموعات مثل `key:Ctrl`+ النقر, فمن المنطقي بالنسبة لنظام Mac نستخدم `key:Cmd`+ النقر. وهذا يكون أكثر راحة لمستخدمي Mac .
124124

125-
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 MacOS, and it generates the `contextmenu` event, not `click` like Windows/Linux.
125+
حتى اذا أردنا إجبار مستخدمي Mac بإستخدام `key:Ctrl`+ النقر -- فهذا يعد صعباً.وتكمن المشكلة في : أن النقر الأيسر مع المفتاح `key:Ctrl` تكون بمثابة *right-click* على MacOS, وبالتالى تقوم بتشغيل حدث `contextmenu` , وليس `click` كما في Windows/Linux.
126126

127-
So if we want users of all operating systems to feel comfortable, then together with `ctrlKey` we should check `metaKey`.
127+
ولذلك إذا أردنا أن يشعر المستخدمين لجميع أنظمة التشغيل بالراحة , بإستخدامهم `ctrlKey` فإنه ينبغي علينا التحقق من `metaKey`.
128128

129-
For JS-code it means that we should check `if (event.ctrlKey || event.metaKey)`.
129+
بالنسبة لترميز - JS فإنه يجب علينا التحقق مما إذا كان `if (event.ctrlKey || event.metaKey)`.
130130
```
131131
132-
```warn header="There are also mobile devices"
133-
Keyboard combinations are good as an addition to the workflow. So that if the visitor uses a keyboard -- they work.
132+
```warn header="هناك أيضا أجهزة هواتف محمولة"
133+
وجود لوحة مفاتيح أمر جيد كإضافة الى سير العمل. فإذا كان الزائر يستخدمها -- فلا بأس.
134134
135-
But if their device doesn't have it -- then there should be a way to live without modifier keys.
135+
ولكن إذا لم يكن أجهزتهم بها -- فلابد أن تكون هناك طريقة للعمل بدون مفاتيح التعديل.
136136
```
137137

138-
## Coordinates: clientX/Y, pageX/Y
138+
## الأحداثيات: clientX/Y, pageX/Y
139139

140-
All mouse events provide coordinates in two flavours:
140+
جميع أحداث الماوس توفر إحداثيات بطريقتين:
141141

142-
1. Window-relative: `clientX` and `clientY`.
143-
2. Document-relative: `pageX` and `pageY`.
142+
1. نسبي-للنافذة: `clientX` و `clientY`.
143+
2. نسبي-للمستند: `pageX` و `pageY`.
144144

145-
We already covered the difference between them in the chapter <info:coordinates>.
145+
وقد غطينا بالفعل الإختلاف بينهما في فصل <info:coordinates>.
146146

147-
In short, document-relative coordinates `pageX/Y` are counted from the left-upper corner of the document, and do not change when the page is scrolled, while `clientX/Y` are counted from the current window left-upper corner. When the page is scrolled, they change.
147+
بإختصار , الأحداثيات النسبية-للمستند `pageX/Y` يتم حسابها من الزاوية العلويه اليسرى للمستند, ولا تتغير أو تتأثر عند تمرير الصفحة, بينما `clientX/Y` تحسب من الواوية العلوية اليسرى للنافذة الحالية. وعندما يتم تمرير الصفحة , فإنها تتغير.
148148

149-
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`, no matter how the page is scrolled.
149+
على سبيل المثال, إذا كان لدينا نافذة بحجم 500x500, ومؤشر الماوس في الزاوية العلوية اليسرى , فإن `clientX` و `clientY` تكون `0`, بغض النظر عن أى تمرير للصفحة.
150150

151-
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` in that aspect.
151+
وإذا كان مؤشر الماوس في المنتصف, فإن `clientX` و `clientY` تكون `250`, بغض النظر عن مكانه في المستند. وهي تتشابه مع `position:fixed` في هذا الجانب.
152152

153153
````online
154-
Move the mouse over the input field to see `clientX/clientY` (the example is in the `iframe`, so coordinates are relative to that `iframe`):
154+
حرك الماوس فوق حقل الإدخال لرؤية `clientX/clientY` (هذا المثال موجود في `iframe`, لذا فإن الأحداثيات مرتبطة بهذا `iframe`):
155155
156156
```html autorun height=50
157-
<input onmousemove="this.value=event.clientX+':'+event.clientY" value="Mouse over me">
157+
<input onmousemove="this.value=event.clientX+':'+event.clientY" value="حرك الماوس فوقي">
158158
```
159159
````
160160

161-
## Preventing selection on mousedown
161+
## منع الإختيار في الماوس
162162

163-
Double mouse click has a side-effect that may be disturbing in some interfaces: it selects text.
163+
النقر المزدوج بزر الماوس له تأثير جانبي قد يكون غير ملائم في بعض الواجهات: فهو يحدد النص.
164164

165-
For instance, a double-click on the text below selects it in addition to our handler:
165+
على سبيل المثال, يؤدي النقر المزدوج على النص أدناه إلى تحديده بالإضافة إلى معالجنا:
166166

167167
```html autorun height=50
168-
<span ondblclick="alert('dblclick')">Double-click me</span>
168+
<span ondblclick="alert('dblclick')">أنقر مرتين علي</span>
169169
```
170170

171-
If one presses the left mouse button and, without releasing it, moves the mouse, that also makes the selection, often unwanted.
171+
إذا قمت بالضغط مع الإستمرار على زر الماوس الأيسر, ودون تحرير الزر , "إضغط مع الإستمرار على الماوس",فسيكون هناك أيضًا تحديد , وقد يكون على غير ما تريد.
172172

173-
There are multiple ways to prevent the selection, that you can read in the chapter <info:selection-range>.
173+
هناك عدة طرق لمنع التحديد , بإمكانك أن تقرأ عنها في فصل <info:selection-range>.
174174

175-
In this particular case the most reasonable way is to prevent the browser action on `mousedown`. It prevents both these selections:
175+
في هذه الحالة ، فإن الطريقة الأكثر منطقية هي منع إجراء المتصفح من `mousedown`. وسيؤدي هذا الى الغاء كل هذه التحديدات:
176176

177177
```html autorun height=50
178-
Before...
178+
قبل...
179179
<b ondblclick="alert('Click!')" *!*onmousedown="return false"*/!*>
180-
Double-click me
180+
أنقر مرتين علي
181181
</b>
182-
...After
182+
...بعد
183183
```
184184

185-
Now the bold element is not selected on double clicks, and pressing the left button on it won't start the selection.
185+
الآن لم يتم تحديد العنصر بالخط العريض بنقرات مزدوجة ، ولن يؤدي الضغط على الزر الأيسر عليه إلى بدء التحديد.
186186

187-
Please note: 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 for users.
188187

189-
````smart header="Preventing copying"
190-
If we want to disable selection to protect our page content from copy-pasting, then we can use another event: `oncopy`.
188+
يرجى ملاحظة أن النص الموجود بداخله لا يزال قابلاً للتحديد. ومع ذلك ، يجب ألا يبدأ التحديد في النص نفسه ، ولكن قبله أو بعده. عادة هذا جيد للمستخدمين.
189+
190+
````smart header="منع النسخ"
191+
إذا أردنا تعطيل التحديد لحماية محتوى صفحتنا من لصق النسخ ، فيمكننا استخدام حدث آخر
192+
: `oncopy`.
191193
192194
```html autorun height=80 no-beautify
193195
<div *!*oncopy="alert('Copying forbidden!');return false"*/!*>
194-
Dear user,
195-
The copying is forbidden for you.
196-
If you know JS or HTML, then you can get everything from the page source though.
196+
عزيزي المستخدم،
197+
النسخ ممنوع لك.
198+
إذا كنت تعرف JS أو HTML ، فيمكنك الحصول على كل شيء من مصدر الصفحة.
197199
</div>
198200
```
199-
If you try to copy a piece of text in the `<div>`, that won't work, because the default action `oncopy` is prevented.
201+
إذا حاولت نسخ جزء من النص في `<div>`, فلن ينجح ذلك, لأن الإجراء الافتراضي `oncopy` ممنوع.
200202
201-
Surely the user has access to HTML-source of the page, and can take the content from there, but not everyone knows how to do it.
203+
من المؤكد أن المستخدم لديه حق الوصول إلى مصدر HTML-للصفحة, ويمكنه أخذ المحتوى من هناك, ولكن لا يعرف الجميع كيفية القيام بذلك.
202204
````
203205

204-
## Summary
206+
## ملخص
205207

206-
Mouse events have the following properties:
208+
تتميز أحداث الماوس بالخصائص التالية:
207209

208-
- Button: `button`.
209-
- Modifier keys (`true` if pressed): `altKey`, `ctrlKey`, `shiftKey` and `metaKey` (Mac).
210-
- If you want to handle `key:Ctrl`, then don't forget Mac users, they usually use `key:Cmd`, so it's better to check `if (e.metaKey || e.ctrlKey)`.
210+
- زر: `button`.
211+
- مفاتيح التعديل (`true` إذا تم الضغط عليه): `altKey`, `ctrlKey`, `shiftKey` و `metaKey` (Mac).
212+
- إذا كنت تريد التعامل معها `key:Ctrl`, لذا لا تنسى Mac مستخدمي , عادة ما يستخدم `key:Cmd`, لذلك من الأفضل التحقق `if (e.metaKey || e.ctrlKey)`.
211213

212-
- Window-relative coordinates: `clientX/clientY`.
213-
- Document-relative coordinates: `pageX/pageY`.
214+
- إحداثيات النافذة: `clientX/clientY`.
215+
- إحداثيات المستند: `pageX/pageY`.
214216

215-
The default browser action of `mousedown` is text selection, if it's not good for the interface, then it should be prevented.
217+
الإجراء الافتراضي للحدث `mousedown` هو تحديد النص, إذا كان من المرجح أن يتدخل في الواجهة يمكنك إلغاؤه.
216218

217-
In the next chapter we'll see more details about events that follow pointer movement and how to track element changes under it.
219+
في الفصل التالي ، سنرى المزيد من التفاصيل حول الأحداث التي تتبع حركة المؤشر وكيفية تتبع تغييرات العناصر تحت المؤشر

2-ui/3-event-details/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# UI Events
1+
# أحداث الواجهة
22

3-
Here we cover most important user interface events and how to work with them.
3+
هنا سوف ندرس الأحداث الرئيسية لواجهة المستخدم وكيفية العمل معها.

0 commit comments

Comments
 (0)