You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/99-ui-misc/01-mutation-observer/article.md
+13-10Lines changed: 13 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,25 +99,26 @@ mutationRecords = [{
99
99
100
100
## Usage for integration
101
101
102
-
When such thing may be useful?
102
+
چه زمانی این اتفاقات به صورت دیفالت رخ می دهند؟
103
103
104
-
Imagine the situation when you need to add a third-party script that contains useful functionality, but also does something unwanted, e.g. shows ads `<div class="ads">Unwanted ads</div>`.
104
+
شرایطی را تصور کنید که باید یک اسکریپت شخص ثالث اضافه کنید که حاوی عملکرد مفید باشد، اما همچنین کاری ناخواسته انجام دهد، به عنوان مثال تبلیغات `<div class="ads">Unwanted ads</div>` را نشان می دهد.
105
105
106
-
Naturally, the third-party script provides no mechanisms to remove it.
107
106
108
-
Using `MutationObserver`, we can detect when the unwanted element appears in our DOM and remove it.
107
+
به طور طبیعی، اسکریپت شخص ثالث هیچ مکانیزمی برای حذف آن ارائه نمی دهد.
109
108
110
-
There are other situations when a third-party script adds something into our document, and we'd like to detect, when it happens, to adapt our page, dynamically resize something etc.
109
+
با استفاده از `MutationObserver`، می توانیم تشخیص دهیم که عنصر ناخواسته در DOM ما ظاهر می شود و آن را حذف می کنیم.
111
110
112
-
`MutationObserver` allows to implement this.
111
+
موقعیتهای دیگری هم وجود دارد که یک اسکریپت شخص ثالث چیزی را به سند ما اضافه میکند، و ما میخواهیم زمانی که این اتفاق میافتد، صفحه خود را تطبیق دهیم، اندازه چیزی را به صورت پویا تغییر اندازه دهیم و غیره.
112
+
113
+
هم چنین `MutationObserver` امکان اجرای این را فراهم می کند.
113
114
114
115
## Usage for architecture
115
116
116
-
There are also situations when`MutationObserver`is good from architectural standpoint.
117
+
همچنین شرایطی وجود دارد که`MutationObserver`از نظر معماری خوب است.
117
118
118
-
Let's say we're making a website about programming. Naturally, articles and other materials may contain source code snippets.
119
+
فرض کنید در حال ساخت یک وب سایت در مورد برنامه نویسی هستیم. به طور طبیعی، مقالات و سایر مطالب ممکن است حاوی کد منبع باشند.
119
120
120
-
Such snippet in an HTML markup looks like this:
121
+
چنین قطعه ای در نشانه گذاری HTML به شکل زیر است:
121
122
122
123
```html
123
124
...
@@ -130,7 +131,9 @@ Such snippet in an HTML markup looks like this:
130
131
131
132
For better readability and at the same time, to beautify it, we'll be using a JavaScript syntax highlighting library on our site, like [Prism.js](https://prismjs.com/). To get syntax highlighting for above snippet in Prism, `Prism.highlightElem(pre)` is called, which examines the contents of such `pre` elements and adds special tags and styles for colored syntax highlighting into those elements, similar to what you see in examples here, on this page.
132
133
133
-
When exactly should we run that highlighting method? Well, we can do it on `DOMContentLoaded` event, or put the script at the bottom of the page. The moment our DOM is ready, we can search for elements `pre[class*="language"]` and call `Prism.highlightElem` on them:
134
+
برای خوانایی بهتر و در عین حال برای زیباتر کردن آن، از کتابخانه برجسته سازی نحوی جاوا اسکریپت در سایت خود مانند [Prism.js](https://prismjs.com/) استفاده خواهیم کرد. برای دریافت برجستهسازی نحو برای قطعه بالا در `(Prism.highlightElem(pre` نامیده میشود، که محتویات چنین عناصر`pre`را بررسی میکند و تگها و سبکهای خاصی را برای برجسته کردن نحو رنگی به آن عناصر اضافه میکند، مشابه آنچه میبینید. در مثال های اینجا، در این صفحه.
135
+
136
+
دقیقاً چه زمانی باید آن روش برجسته سازی را اجرا کنیم؟ خوب، میتوانیم این کار را در رویداد `DOMContentLoaded` انجام دهیم یا اسکریپت را در پایین صفحه قرار دهیم. لحظهای که DOM ما آماده است، میتوانیم عناصر `pre[class*="language"]` را جستجو کنیم و روی آنها `Prism.highlightElem` را صدا کنیم:
0 commit comments