URL: http://github.com/javascript-tutorial/fa.javascript.info/pull/318.patch
andler is not going to call `preventDefault()`. +آپشن اختیاری `passive: true` از `addEventListener` این سیگنال را به مرورگر میدهد که مرورگر هندلر `preventDefault()` را صدا نخواهد کرد.. -Why might that be needed? +چرا ممکن است که به این آپشن نیاز پیدا کنیم؟ -There are some events like `touchmove` on mobile devices (when the user moves their finger across the screen), that cause scrolling by default, but that scrolling can be prevented using `preventDefault()` in the handler. +ایونت هایی همچون `touchmove` در دیوایسهای موبایلی وجود دارند (زمانی که یوزر انگشت خود را برروی صفحهنمایش حرکت میدهد) که به صورت پیشفرض باعث اسکرول میشوند اما این اسکرول خوردن میتواند با وجود `preventDefault()` در هندلر جلوگیری شود. -So when the browser detects such event, it has first to process all handlers, and then if `preventDefault` is not called anywhere, it can proceed with scrolling. That may cause unnecessary delays and "jitters" in the UI. +بنابراین زمانی که مرورگر چنین ایونتی را شناسایی میکند اول از همه باید همهی هندلرهارا بررسی کرده و اگر `preventDefault` جایی صدا زده نشده باشد میتواند با اسکرول خوردن ادامه یابد که این میتواند سبب تاخیرها و لرزشهای غیرضروری شود. -The `passive: true` options tells the browser that the handler is not going to cancel scrolling. Then browser scrolls immediately providing a maximally fluent experience, and the event is handled by the way. +گزینه `passive: true` به مرورگر میگوید که هندلر قصد لغو اسکرول را ندارد آنگاه مرورگر بلافاصله عمل اسکرول را انجام میدهد و تجربه خوب و روانی را برای کاربر به وجود میآورد و درضمن رویداد هم هندل میشود. -For some browsers (Firefox, Chrome), `passive` is `true` by default for `touchstart` and `touchmove` events. +در بعضی از مرورگرها (فایرفاکس و کروم) مقدار `passive` به صورت پیشفرض برای رویدادهای `touchstart` و `touchmove` مقدار `true` دارد. ->>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b +> > > > > > > bae0ef44d0208506f6e9b7f3421ee640ab41af2b ## event.defaultPrevented @@ -141,12 +143,12 @@ Upon right click, the closest context menu should show up. ``` @@ -181,25 +185,26 @@ Now the button-level menu works as intended. But the price is high. We forever d An alternative solution would be to check in the `document` handler if the default action was prevented? If it is so, then the event was handled, and we don't need to react on it. - ```html autorun height=80 no-beautify run -Right-click for the document menu (added a check for event.defaultPrevented)
++ Right-click for the document menu (added a check for event.defaultPrevented) +
``` @@ -217,9 +222,9 @@ The object will catch any right-click, look through stored handlers and run the But then each piece of code that wants a context menu should know about that object and use its help instead of the own `contextmenu` handler. ``` -## Summary +## خلاصه -There are many default browser actions: +اکشن های دیفالت مختلفی وجود دارند: - `mousedown` -- starts the selection (move the mouse to select). - `click` on `` -- checks/unchecks the `input`. @@ -228,11 +233,11 @@ There are many default browser actions: - `contextmenu` -- the event happens on a right-click, the action is to show the browser context menu. - ...there are more... -All the default actions can be prevented if we want to handle the event exclusively by JavaScript. +اگر بخواهیم تا ایونت را به طور خاص با جاوااسکریپت هندل کنیم میتوانیم از همهی اکشنهای پیشفرض جلوگیری کنیم. -To prevent a default action -- use either `event.preventDefault()` or `return false`. The second method works only for handlers assigned with `onRight-click here for the document context menu
@@ -155,14 +155,15 @@ Upon right click, the closest context menu should show up. ``` -The problem is that when we click on `elem`, we get two menus: the button-level and (the event bubbles up) the document-level menu. +مشکل این است زمانی که برروی `elem` کلیک کنیم دو منو خواهیم داشت: منوی تعریف شده برروی دکمه و (زمانی که رویداد bubble up میکند) منوی تعریف شده در داکیومنت. -How to fix it? One of solutions is to think like: "When we handle right-click in the button handler, let's stop its bubbling" and use `event.stopPropagation()`: +چطور این مسئله را فیکس کنیم؟ یکی از راهحل ها این است: "زمانی که که میخواهیم کلیکراست را در هندلر دکمه هندل کنیم بیاید تا bubbling آن را متوقف کرده" و از `()event.stopPropagation` استفاده کنیم. ```html autorun height=80 no-beautify runRight-click for the document menu
@@ -208,18 +209,20 @@ An alternative solution would be to check in the `document` handler if the defau
```
-Now everything also works correctly. If we have nested elements, and each of them has a context menu of its own, that would also work. Just make sure to check for `event.defaultPrevented` in each `contextmenu` handler.
+حالا همه چیز به درستی کار میکند. این راه حل حتی اگر المنتهای تودرتویی داشته باشیم که هرکدام منوی خودشان را داشته باشند هم کار میکند. فقط اطمینان حاصل کنید که `event.defaultPrevented` در هر یک از هندلرهای `contextmenu` چک میشود.
```smart header="event.stopPropagation() and event.preventDefault()"
As we can clearly see, `event.stopPropagation()` and `event.preventDefault()` (also known as `return false`) are two different things. They are not related to each other.
+به خوبی میتوانیم ببینیم که `event.stopPropagation()` و `event.preventDefault()` (که همچنین به عنوان `return false` شناخته میشود) دو چیز متفاوت از هم هستند که به یکدیگر ربطی ندارند.
```
```smart header="Nested context menus architecture"
+همچنین راههای جایگزینی برای پیادهسازی منوهای تودرتو وجود دارد.
There are also alternative ways to implement nested context menus. One of them is to have a single global object with a handler for `document.oncontextmenu`, and also methods that allow us to store other handlers in it.
-The object will catch any right-click, look through stored handlers and run the appropriate one.
+آبجت هرگونه کلیک راستی را گرفته، نگاهی به هندلرهای آن میاندازد و هندلر مناسب را اجرا میکند.
-But then each piece of code that wants a context menu should know about that object and use its help instead of the own `contextmenu` handler.
+اما در اینصورت هر تکه کدی که بخواهد context menu داشته باشد باید راجع به آن آبجکت بداند و به جای هندلر `contextmenu` خودش از کمک آن آبجکت گلوبال استفاده کند.
```
## خلاصه
From 648043e9d90fdb758df1e5f3011f36c74cc8d8d7 Mon Sep 17 00:00:00 2001
From: Mohammad Hosein Right-click here for the document context menu برای context menu داکیومنت اینجا کلیک راست کنید Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages. Alternative Proxies:Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.