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/02-selection-range/article.md
+29-27Lines changed: 29 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,41 @@
1
-
libs:
1
+
کتابخانه ها:
2
2
- d3
3
3
- domtree
4
4
5
5
---
6
6
7
7
# Selection and Range
8
8
9
-
In this chapter we'll cover selection in the document, as well as selection in form fields, such as `<input>`.
10
9
11
-
JavaScript can access an existing selection, select/deselect DOM nodes as a whole or partially, remove the selected content from the document, wrap it into a tag, and so on.
10
+
جاوااسکریپت میتواند به یک انتخاب موجود دسترسی داشته باشد، گرههای DOM را بهطور کلی یا جزئی انتخاب یا لغو انتخاب کند، محتوای انتخابشده را از سند حذف کند، آن را در یک برچسب قرار دهد و غیره.
12
11
13
-
You can find some recipes for common tasks at the end of the chapter, in "Summary" section. Maybe that covers your current needs, but you'll get much more if you read the whole text.
12
+
میتوانید دستور العملهایی برای کارهای رایج در انتهای فصل، در بخش "Summary" بیابید. شاید این نیازهای فعلی شما را پوشش دهد، اما اگر متن کامل را بخوانید، خیلی بیشتر به دست خواهید آورد.
14
13
15
-
The underlying `Range`and `Selection`objects are easy to grasp, and then you'll need no recipes to make them do what you want.
14
+
درک اشیاء زیربنایی `Range`و`Selection`آسان است، و پس از آن برای اینکه آنها را به آنچه میخواهید انجام دهند، به هیچ دستور العملی نیاز نخواهید داشت.
16
15
17
16
## Range
18
17
19
-
The basic concept of selection is [Range](https://dom.spec.whatwg.org/#ranges), that is essentially a pair of "boundary points": range start and range end.
18
+
فهوم اصلی انتخاب [Range](https://dom.spec.whatwg.org/#ranges) است، که اساساً یک جفت "boundary points"است: شروع محدوده و پایان محدوده.
20
19
21
-
A `Range` object is created without parameters:
20
+
21
+
یک `Range` object بدون پارامتر ساخته می شود:
22
22
23
23
```js
24
24
let range =newRange();
25
25
```
26
26
27
-
Then we can set the selection boundaries using`range.setStart(node, offset)`and`range.setEnd(node, offset)`.
27
+
پس میتوانیم مرزهای انتخاب را با استفاده از`range.setStart(node, offset)`و`range.setEnd(node, offset)` تنظیم کنیم.
28
28
29
-
As you might guess, further we'll use the `Range`objects for selection, but first let's create few such objects.
29
+
همانطور که ممکن است حدس بزنید، در ادامه از اشیاء `Range` برای انتخاب استفاده خواهیم کرد، اما ابتدا اجازه دهید تعداد کمی از این اشیاء ایجاد کنیم.
30
30
31
31
### Selecting the text partially
32
32
33
-
The interesting thing is that the first argument `node` in both methods can be either a text node or an element node, and the meaning of the second argument depends on that.
33
+
نکته جالب این است که آرگومان اول `node` در هر دو روش می تواند یک text node یا یelement node عنصر باشد و معنای آرگومان دوم به آن بستگی دارد.
34
+
34
35
35
-
**If`node`is a text node, then `offset`must be the position in its text.**
36
+
**اگر`node`یک text nodeاست، `offset`باید موقعیتی در متن آن باشد.**
36
37
37
-
For example, given the element `<p>Hello</p>`, we can create the range containing the letters "ll" as follows:
38
+
به عنوان مثال، با توجه به عنصر `<p>Hello</p>`، میتوانیم محدوده حاوی حروف «ll» را به صورت زیر ایجاد کنیم:
38
39
39
40
```html run
40
41
<pid="p">Hello</p>
@@ -48,23 +49,24 @@ For example, given the element `<p>Hello</p>`, we can create the range containin
48
49
</script>
49
50
```
50
51
51
-
Here we take the first child of `<p>`(that's the text node) and specify the text positions inside it:
52
+
در اینجا اولین فرزند `<p>`را می گیریم (این text node است) و موقعیت های متن را در داخل آن مشخص می کنیم:
52
53
53
-

54
54
55
+

55
56
### Selecting element nodes
56
57
57
-
**Alternatively, if `node` is an element node, then `offset` must be the child number.**
58
58
59
-
That's handy for making ranges that contain nodes as a whole, not stop somewhere inside their text.
59
+
** متناوباً، اگر `node` یک element node است، `offset` باید شماره فرزند باشد.**
60
+
61
+
این برای ایجاد محدوده هایی که شامل گره ها به عنوان یک کل هستند، مفید است، نه اینکه در جایی در متن خود متوقف شوند.
60
62
61
-
For example, we have a more complex document fragment:
63
+
به عنوان مثال، ما یک قطعه سند پیچیده تر داریم:
62
64
63
65
```html autorun
64
66
<pid="p">Example: <i>italic</i> and <b>bold</b></p>
65
67
```
66
68
67
-
Here's its DOM structure with both element and text nodes:
69
+
در اینجا ساختار DOM آن با هر دو گره عنصر و متن آمده است:
0 commit comments