diff --git a/2-ui/2-events/04-default-browser-action/article.md b/2-ui/2-events/04-default-browser-action/article.md index ceac160c1..333598a2e 100644 --- a/2-ui/2-events/04-default-browser-action/article.md +++ b/2-ui/2-events/04-default-browser-action/article.md @@ -1,23 +1,23 @@ -# Browser default actions +# ব্রাউজারের ডিফল্ট অ্যাকশন -Many events automatically lead to certain actions performed by the browser. +অনেক ইভেন্ট আছে তা কিভাবে সংগঠিত হবে তা ব্রাউজারে নির্দেশ করা থাকে। -For instance: +যেমন: -- A click on a link - initiates navigation to its URL. -- A click on a form submit button - initiates its submission to the server. -- Pressing a mouse button over a text and moving it - selects the text. +- কোন লিংকে ক্লিক - URL নেভিগেশন হয়। +- ফর্মের সাবমিট বাটনে ক্লিকড হলে - সার্ভারে ডাটা সাবমিশন শুরু হয়। +- কোন টেক্সটে মাউস ক্লিক করে মুভ করলে - টেক্সট সিলেক্ট হয়। -If we handle an event in JavaScript, we may not want the corresponding browser action to happen, and want to implement another behavior instead. +ইভেন্ট হ্যান্ডেলিং করার সময় অনেক সময় ব্রাউজারের ডিফল্ট বিহেভিয়ারের পরিবর্তে আমরা আমাদের চাহিদামত ইভেন্টগুলো প্রসেস করতে চাই। -## Preventing browser actions +## ব্রাউজারের অ্যাকশনকে বাধাপ্রদান -There are two ways to tell the browser we don't want it to act: +দুইভাবে আমরা ব্রাউজারের ডিফল্ট বিহেভিয়ার থামাতে পারি: -- The main way is to use the `event` object. There's a method `event.preventDefault()`. -- If the handler is assigned using `on` (not by `addEventListener`), then returning `false` also works the same. +- সাধারণত `event` অবজেক্টের মাধ্যমে, এর একটি মেথড আছে যাকে কল করার মাধ্যমে `event.preventDefault()` । +- আর যদি ইভেন্টটি (`addEventListener`) এর পরিবর্তে `on` এর মাধ্যমে অ্যাসাইন করা হয়, তাহলে `false` রিটার্নের মাধ্যমে। -In this HTML a click on a link doesn't lead to navigation, browser doesn't do anything: +নিচের উদাহরণটিতে ব্রাউজারের URL নেভিগেশন কাজ করবে না: ```html autorun height=60 no-beautify Click here @@ -25,19 +25,19 @@ or here ``` -In the next example we'll use this technique to create a JavaScript-powered menu. +পরবর্তী মেন্যু উদাহরণটিতে আমরা জাভাস্ক্রিপ্টের এই কৌশলটি ব্যবহার করব। -```warn header="Returning `false` from a handler is an exception" -The value returned by an event handler is usually ignored. +```warn header="হ্যান্ডালের `false` রিটার্নের মাধ্যমে একটি এক্সেপশন থ্রো হয়" +সাধারণত ইভেন্ট হ্যান্ডালারে কোন ভ্যালু রিটার্ন হলে তা ইগনোরড করে। -The only exception is `return false` from a handler assigned using `on`. + `on` দ্বারা কোন হ্যান্ডালার অ্যাসাইন করা হলে `return false` এক্সেপশন থ্রো করে। -In all other cases, `return` value is ignored. In particular, there's no sense in returning `true`. +অন্য সকল ক্ষেত্রে, `return` ভ্যালু ইগনোরড হয়। বিশেষত, `true` রিটার্নের আলাদা কোন সুবিধা নেই। ``` ### Example: the menu -Consider a site menu, like this: +এইরকম একটি মেন্যু বিবেচনা করুন: ```html ``` -Here's how it looks with some CSS: +কিছু CSS রুলস সহ এটি দেখতে এমন: [iframe height=70 src="menu" link edit] -Menu items are implemented as HTML-links ``, not buttons ` @@ -129,9 +128,9 @@ By default the browser on `contextmenu` event (right mouse click) shows a contex ``` -Now, in addition to that context menu we'd like to implement document-wide context menu. +এখন আমরা এটিকে গ্লোবালি ডিক্লেয়ার করি। -Upon right click, the closest context menu should show up. +কোন কন্টেন্টে ডানের বাটনে প্রেস করলে আমরা একটি অ্যালার্ট দেখতে পারব। ```html autorun height=80 no-beautify run

Right-click here for the document context menu

@@ -150,9 +149,9 @@ 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` এর জন্য একটি সমস্যা দেখা যাচ্ছে, এটির জন্য দুটি অ্যালার্ট দেখায়: একটি button-level এবং অন্যটি document-level। -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()`: +কিভাবে এটি ফিক্স করা যায়? একটি সমাধান এভাবে হতে পারে: "যখন আমরা বাটনে ডানের বাটনে প্রেস, তখন `event.stopPropagation()` এর মাধ্যমে bubbling কে থামাতে পারি": ```html autorun height=80 no-beautify run

Right-click for the document menu

@@ -174,9 +173,9 @@ How to fix it? One of solutions is to think like: "When we handle right-click in ``` -Now the button-level menu works as intended. But the price is high. We forever deny access to information about right-clicks for any outer code, including counters that gather statistics and so on. That's quite unwise. +এখন এটি শুধুমাত্র button-level এর জন্য কাজ করছে। তবে এর জন্য আমাদের চরম মূল্য দেয়া লাগতে পারে। এর জন্য আমাদের অন্যান্য লেভেলের ইভেন্ট গুলো আর কাজ করবে না, সুতরা এভাবে করা বোকামি। -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. +তবে আমাদের কাছে একটি বিকল্প ব্যবস্থা আছে যার মাধ্যমে আমরা এটি সমাধান করতে পারি। আমরা `document` হ্যান্ডেলারে যাচাই করব আমাদের ইভেন্ট কি `defaultPrevented` হয়েছে কিনা? যদি হয়ে থাকে, তাহলে ইভেন্ট টি আগে সংগঠিত হয়েছে, এর ফলে document-level এ কোন কিছু আর ঘটবে না। ```html autorun height=80 no-beautify run @@ -200,45 +199,44 @@ 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. +উপরের কোডটি নির্ভুল্ভাবে কাজ করবে। যদি আমাদের নেস্টেড এলিমেন্ট থাকে এবং প্রতিটির নিজস্ব কনট্যাক্স মেন্যু থাকে, তাও কাজ করবে। তবে আমাদের শুধু নিশ্চিত হতে হবে যেন প্রতিটি `contextmenu` হ্যান্ডালারে যেন `event.defaultPrevented` যাচায় করা হয়। -```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. +```smart header="event.stopPropagation() এবং event.preventDefault()" +আমাদের কাছে এখন পরিষ্কার, `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. +```smart header="নেস্টেড কনট্যাক্স মেন্যু আর্কিটেকচার" +নেস্টেড কনট্যাক্স মেন্যু লিখার বিকল্প উপায়ও আছে। এদের মধ্যে একটি হল `document.oncontextmenu` এর জন্য একটি একক গ্লোবাল অবজেক্ট এবং চাইল্ড এলিমেন্ট প্রত্যেকের জন্য আলাদা আলাদা হ্যান্ডেলার ব্যবহার। -The object will catch any right-click, look through stored handlers and run the appropriate one. +প্রতিবার *right-click* এর জন্য অবজেক্টটি কল হবে এবং এলিমেন্ট অনুযায়ী নির্দিষ্ট হ্যান্ডেলার কল হবে। -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`. -- `submit` -- clicking an `` or hitting `key:Enter` inside a form field causes this event to happen, and the browser submits the form after it. -- `keydown` -- pressing a key may lead to adding a character into a field, or other actions. -- `contextmenu` -- the event happens on a right-click, the action is to show the browser context menu. -- ...there are more... +- `mousedown` -- সিলেকশন (মাউস মুভ করলে কোন কিছু সিলেক্ট হবে)। +- `click` `` -- ক্লিকে `input` এর checks/unchecks হয়। +- `submit` -- form এর মধ্যে `` এ ক্লিকে বা `key:Enter` প্রেসে ইভেন্টটি সংগঠিত হয়, এবং এর পরে ফর্মটি সাবমিট হয়। +- `keydown` -- কী-বোর্ডে কোন বাটনে ক্লিক হলে ক্যারাক্টার অ্যাড হবে অথবা অন্য কোন অ্যাকশন সংগঠিত হবে। +- `contextmenu` -- মাউসের right-click এ ইভেন্টটি সংগঠিত হয়, এবং এটি ব্রাউজারের context menu দেখায়। +- ...এবং আরো অনেক... -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 `on`. +সকল ডিফল্ট অ্যাকশন রোধ করতে `event.preventDefault()` বা `return false` ব্যবহার করতে পারি। দ্বিতীয়টি শুধুমাত্র `on` এর সাথেই কাজ করে। -The `passive: true` option of `addEventListener` tells the browser that the action is not going to be prevented. That's useful for some mobile events, like `touchstart` and `touchmove`, to tell the browser that it should not wait for all handlers to finish before scrolling. +`addEventListener` এ `passive: true` অপশনটি দ্বারা বুঝায় ইভেন্টটি কোনখানে রোধ হবে না। কিছু টাচস্ক্রিন ইভেন্টের জন্য এটি ব্যবহার সুবিধাজনক, যেমন `touchstart` এবং `touchmove`, যা ব্রাউজারকে নির্দেশ করে হ্যান্ডেলারের কারণে স্ক্রলিংয়ে কোন বাধাপ্রাপ্ত হবে না। -If the default action was prevented, the value of `event.defaultPrevented` becomes `true`, otherwise it's `false`. +যদি ডিফল্ট অ্যাকশন বাধাপ্রাপ্ত হয়, তাহলে `event.defaultPrevented` এর ভ্যালু `true` হবে, অন্যথায় `false`। ```warn header="Stay semantic, don't abuse" -Technically, by preventing default actions and adding JavaScript we can customize the behavior of any elements. For instance, we can make a link `
` work like a button, and a button `