|
26 | 26 |
|
27 | 27 | `contextmenu` |
28 | 28 |
|
29 | | -:يعمل عندما يتم الضغط على زر الفأرة الأيمن. وهناك طرق أخرى لفتح قائمة السياق ، على سبيل المثال باستخدام مفتاح معين من لوحة المفاتيح ، ويمكن أيضًا استخدامه في هذه الحالة ، لذا فهو ليس بالضبط حدث للماوس . |
| 29 | +يعمل عندما يتم الضغط على زر الفأرة الأيمن. وهناك طرق أخرى لفتح قائمة السياق ، على سبيل المثال باستخدام مفتاح معين من لوحة المفاتيح ، ويمكن أيضًا استخدامه في هذه الحالة ، لذا فهو ليس بالضبط حدث للماوس . |
30 | 30 |
|
31 | 31 | ... وهناك أيضا العديد من الأحداث الأخرى ، واللتى سنتطرق لها لاحقًا |
32 | 32 | . |
33 | 33 |
|
34 | | -## نرتيب الأحداث |
| 34 | +## ترتيب الأحداث |
35 | 35 |
|
36 | 36 | كما ترى من القائمة السابقة ، قد يقوم إجراء المستخدم بتشغيل أكثر من حدث أو أحداث متعددة |
37 | 37 |
|
|
54 | 54 |
|
55 | 55 | ## زر الماوس |
56 | 56 |
|
57 | | -Click-related events always have the `button` property, which allows to get the exact mouse button. |
| 57 | +تحتوي دائما الأحداث المتعلقة بالنقر على خاصية `button`, والتي تسمح لك بأستخدام زر الماوس. |
58 | 58 |
|
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` , وذلك لأن الأول يحدث فقط عند النقر بزر الماوس الأيسر ، والأخير - فقط عند النقر بزر الماوس الأيمن. |
60 | 60 |
|
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` يتيح لك التمييز بين "زر الماوس الأيمن" و "زر الماوس الأيسر". |
62 | 62 |
|
63 | | -The possible values of `event.button` are: |
| 63 | +القيم المحتملة لـ `event.button` هي: |
64 | 64 |
|
65 | | -| Button state | `event.button` | |
| 65 | +| حالة الزر | `event.button` | |
66 | 66 | |--------------|----------------| |
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 | |
72 | 72 |
|
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". وكذلك الأجهزة التي تعمل باللمس أيضًا تولد أحداثًا مماثلة عندما ينقر عليها . |
74 | 74 |
|
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)اذا احتجت اليها في أي وقت. |
76 | 76 |
|
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` وهي تعتبر طريقة قديمة غير قياسية للحصول على زر ، مع القيم المحتملة : |
79 | 79 |
|
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` – الزر الأيمن. |
83 | 83 |
|
84 | | -As of now, `event.which` is deprecated, we shouldn't use it. |
| 84 | +إعتباراً من الأن, `event.which` تم ايقافها, لذا لا يجب إستخدامها. |
85 | 85 | ``` |
86 | 86 |
|
87 | | -## Modifiers: shift, alt, ctrl and meta |
| 87 | +## مفاتيح التعديل: shift, alt, ctrl و meta |
88 | 88 |
|
89 | | -All mouse events include the information about pressed modifier keys. |
| 89 | +تتضمن جميع أحداث الماوس معلومات عند الضغط على مفاتيح التعديل |
90 | 90 |
|
91 | | -Event properties: |
| 91 | +خصائص الحدث : |
92 | 92 |
|
93 | 93 | - `shiftKey`: `key:Shift` |
94 | | -- `altKey`: `key:Alt` (or `key:Opt` for Mac) |
| 94 | +- `altKey`: `key:Alt` (أو `key:Opt` لنظام تشغيل Mac) |
95 | 95 | - `ctrlKey`: `key:Ctrl` |
96 | | -- `metaKey`: `key:Cmd` for Mac |
| 96 | +- `metaKey`: `key:Cmd` لنظام Mac |
97 | 97 |
|
98 | | -They are `true` if the corresponding key was pressed during the event. |
| 98 | +تكون القيمة `true` إذا تم الضغط على المفتاح المقابل أثناء الحدث. |
99 | 99 |
|
100 | | -For instance, the button below only works on `key:Alt+Shift`+click: |
| 100 | +على سبيل المثال, الزر أدناه يعمل فقط عند الضغط على `key:Alt+Shift` ثم النقر : |
101 | 101 |
|
102 | 102 | ```html autorun height=60 |
103 | | -<button id="button">Alt+Shift+Click on me!</button> |
| 103 | +<button id="button">Alt+Shift+أنقر علي!</button> |
104 | 104 |
|
105 | 105 | <script> |
106 | 106 | button.onclick = function(event) { |
107 | 107 | *!* |
108 | 108 | if (event.altKey && event.shiftKey) { |
109 | 109 | */!* |
110 | | - alert('Hooray!'); |
| 110 | + alert('مرحى!'); |
111 | 111 | } |
112 | 112 | }; |
113 | 113 | </script> |
114 | 114 | ``` |
115 | 115 |
|
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`. |
118 | 118 |
|
119 | | -In most applications, when Windows/Linux uses `key:Ctrl`, on Mac `key:Cmd` is used. |
| 119 | +في معظم التطبيقات, عندما Windows/Linux بستخدم `key:Ctrl`, على Mac نستخدم `key:Cmd`. |
120 | 120 |
|
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`, وهكذا. |
122 | 122 |
|
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 . |
124 | 124 |
|
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. |
126 | 126 |
|
127 | | -So if we want users of all operating systems to feel comfortable, then together with `ctrlKey` we should check `metaKey`. |
| 127 | +ولذلك إذا أردنا أن يشعر المستخدمين لجميع أنظمة التشغيل بالراحة , بإستخدامهم `ctrlKey` فإنه ينبغي علينا التحقق من `metaKey`. |
128 | 128 |
|
129 | | -For JS-code it means that we should check `if (event.ctrlKey || event.metaKey)`. |
| 129 | +بالنسبة لترميز - JS فإنه يجب علينا التحقق مما إذا كان `if (event.ctrlKey || event.metaKey)`. |
130 | 130 | ``` |
131 | 131 |
|
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 | +وجود لوحة مفاتيح أمر جيد كإضافة الى سير العمل. فإذا كان الزائر يستخدمها -- فلا بأس. |
134 | 134 |
|
135 | | -But if their device doesn't have it -- then there should be a way to live without modifier keys. |
| 135 | +ولكن إذا لم يكن أجهزتهم بها -- فلابد أن تكون هناك طريقة للعمل بدون مفاتيح التعديل. |
136 | 136 | ``` |
137 | 137 |
|
138 | | -## Coordinates: clientX/Y, pageX/Y |
| 138 | +## الأحداثيات: clientX/Y, pageX/Y |
139 | 139 |
|
140 | | -All mouse events provide coordinates in two flavours: |
| 140 | + جميع أحداث الماوس توفر إحداثيات بطريقتين: |
141 | 141 |
|
142 | | -1. Window-relative: `clientX` and `clientY`. |
143 | | -2. Document-relative: `pageX` and `pageY`. |
| 142 | +1. نسبي-للنافذة: `clientX` و `clientY`. |
| 143 | +2. نسبي-للمستند: `pageX` و `pageY`. |
144 | 144 |
|
145 | | -We already covered the difference between them in the chapter <info:coordinates>. |
| 145 | +وقد غطينا بالفعل الإختلاف بينهما في فصل <info:coordinates>. |
146 | 146 |
|
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` تحسب من الواوية العلوية اليسرى للنافذة الحالية. وعندما يتم تمرير الصفحة , فإنها تتغير. |
148 | 148 |
|
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`, بغض النظر عن أى تمرير للصفحة. |
150 | 150 |
|
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` في هذا الجانب. |
152 | 152 |
|
153 | 153 | ````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`): |
155 | 155 |
|
156 | 156 | ```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="حرك الماوس فوقي"> |
158 | 158 | ``` |
159 | 159 | ```` |
160 | 160 |
|
161 | | -## Preventing selection on mousedown |
| 161 | +## منع الإختيار في الماوس |
162 | 162 |
|
163 | | -Double mouse click has a side-effect that may be disturbing in some interfaces: it selects text. |
| 163 | +النقر المزدوج بزر الماوس له تأثير جانبي قد يكون غير ملائم في بعض الواجهات: فهو يحدد النص. |
164 | 164 |
|
165 | | -For instance, a double-click on the text below selects it in addition to our handler: |
| 165 | +على سبيل المثال, يؤدي النقر المزدوج على النص أدناه إلى تحديده بالإضافة إلى معالجنا: |
166 | 166 |
|
167 | 167 | ```html autorun height=50 |
168 | | -<span ondblclick="alert('dblclick')">Double-click me</span> |
| 168 | +<span ondblclick="alert('dblclick')">أنقر مرتين علي</span> |
169 | 169 | ``` |
170 | 170 |
|
171 | | -If one presses the left mouse button and, without releasing it, moves the mouse, that also makes the selection, often unwanted. |
| 171 | +إذا قمت بالضغط مع الإستمرار على زر الماوس الأيسر, ودون تحرير الزر , "إضغط مع الإستمرار على الماوس",فسيكون هناك أيضًا تحديد , وقد يكون على غير ما تريد. |
172 | 172 |
|
173 | | -There are multiple ways to prevent the selection, that you can read in the chapter <info:selection-range>. |
| 173 | +هناك عدة طرق لمنع التحديد , بإمكانك أن تقرأ عنها في فصل <info:selection-range>. |
174 | 174 |
|
175 | | -In this particular case the most reasonable way is to prevent the browser action on `mousedown`. It prevents both these selections: |
| 175 | + في هذه الحالة ، فإن الطريقة الأكثر منطقية هي منع إجراء المتصفح من `mousedown`. وسيؤدي هذا الى الغاء كل هذه التحديدات: |
176 | 176 |
|
177 | 177 | ```html autorun height=50 |
178 | | -Before... |
| 178 | +قبل... |
179 | 179 | <b ondblclick="alert('Click!')" *!*onmousedown="return false"*/!*> |
180 | | - Double-click me |
| 180 | + أنقر مرتين علي |
181 | 181 | </b> |
182 | | -...After |
| 182 | +...بعد |
183 | 183 | ``` |
184 | 184 |
|
185 | | -Now the bold element is not selected on double clicks, and pressing the left button on it won't start the selection. |
| 185 | +الآن لم يتم تحديد العنصر بالخط العريض بنقرات مزدوجة ، ولن يؤدي الضغط على الزر الأيسر عليه إلى بدء التحديد. |
186 | 186 |
|
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. |
188 | 187 |
|
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`. |
191 | 193 |
|
192 | 194 | ```html autorun height=80 no-beautify |
193 | 195 | <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 ، فيمكنك الحصول على كل شيء من مصدر الصفحة. |
197 | 199 | </div> |
198 | 200 | ``` |
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` ممنوع. |
200 | 202 |
|
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-للصفحة, ويمكنه أخذ المحتوى من هناك, ولكن لا يعرف الجميع كيفية القيام بذلك. |
202 | 204 | ```` |
203 | 205 |
|
204 | | -## Summary |
| 206 | +## ملخص |
205 | 207 |
|
206 | | -Mouse events have the following properties: |
| 208 | +تتميز أحداث الماوس بالخصائص التالية: |
207 | 209 |
|
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)`. |
211 | 213 |
|
212 | | -- Window-relative coordinates: `clientX/clientY`. |
213 | | -- Document-relative coordinates: `pageX/pageY`. |
| 214 | +- إحداثيات النافذة: `clientX/clientY`. |
| 215 | +- إحداثيات المستند: `pageX/pageY`. |
214 | 216 |
|
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` هو تحديد النص, إذا كان من المرجح أن يتدخل في الواجهة يمكنك إلغاؤه. |
216 | 218 |
|
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 | +في الفصل التالي ، سنرى المزيد من التفاصيل حول الأحداث التي تتبع حركة المؤشر وكيفية تتبع تغييرات العناصر تحت المؤشر |
0 commit comments