Skip to content

Commit f7ee8cd

Browse files
authored
Merge pull request #295 from HannaParsa/Selection-Range-2
Selection range
2 parents 4d2e43f + 9540a59 commit f7ee8cd

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

2-ui/99-ui-misc/02-selection-range/article.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
libs:
1+
کتابخانه ها:
22
- d3
33
- domtree
44

55
---
66

77
# Selection and Range
88

9-
In this chapter we'll cover selection in the document, as well as selection in form fields, such as `<input>`.
109

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 را به‌طور کلی یا جزئی انتخاب یا لغو انتخاب کند، محتوای انتخاب‌شده را از سند حذف کند، آن را در یک برچسب قرار دهد و غیره.
1211

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" بیابید. شاید این نیازهای فعلی شما را پوشش دهد، اما اگر متن کامل را بخوانید، خیلی بیشتر به دست خواهید آورد.
1413

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` آسان است، و پس از آن برای اینکه آنها را به آنچه می‌خواهید انجام دهند، به هیچ دستور العملی نیاز نخواهید داشت.
1615

1716
## Range
1817

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"است: شروع محدوده و پایان محدوده.
2019

21-
A `Range` object is created without parameters:
20+
21+
یک `Range` object بدون پارامتر ساخته می شود:
2222

2323
```js
2424
let range = new Range();
2525
```
2626

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)` تنظیم کنیم.
2828

29-
As you might guess, further we'll use the `Range` objects for selection, but first let's create few such objects.
29+
همانطور که ممکن است حدس بزنید، در ادامه از اشیاء `Range` برای انتخاب استفاده خواهیم کرد، اما ابتدا اجازه دهید تعداد کمی از این اشیاء ایجاد کنیم.
3030

3131
### Selecting the text partially
3232

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+
3435

35-
**If `node` is a text node, then `offset` must be the position in its text.**
36+
**اگر `node` یک text nodeاست، `offset` باید موقعیتی در متن آن باشد.**
3637

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» را به صورت زیر ایجاد کنیم:
3839

3940
```html run
4041
<p id="p">Hello</p>
@@ -48,23 +49,24 @@ For example, given the element `<p>Hello</p>`, we can create the range containin
4849
</script>
4950
```
5051

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 است) و موقعیت های متن را در داخل آن مشخص می کنیم:
5253

53-
![](range-hello-1.svg)
5454

55+
![](range-hello-1.svg)
5556
### Selecting element nodes
5657

57-
**Alternatively, if `node` is an element node, then `offset` must be the child number.**
5858

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+
این برای ایجاد محدوده هایی که شامل گره ها به عنوان یک کل هستند، مفید است، نه اینکه در جایی در متن خود متوقف شوند.
6062

61-
For example, we have a more complex document fragment:
63+
به عنوان مثال، ما یک قطعه سند پیچیده تر داریم:
6264

6365
```html autorun
6466
<p id="p">Example: <i>italic</i> and <b>bold</b></p>
6567
```
6668

67-
Here's its DOM structure with both element and text nodes:
69+
در اینجا ساختار DOM آن با هر دو گره عنصر و متن آمده است:
6870

6971
<div class="select-p-domtree"></div>
7072

@@ -102,20 +104,20 @@ let selectPDomtree = {
102104
drawHtmlTree(selectPDomtree, 'div.select-p-domtree', 690, 320);
103105
</script>
104106

105-
Let's make a range for `"Example: <i>italic</i>"`.
106107

107-
As we can see, this phrase consists of exactly two children of `<p>`, with indexes `0` and `1`:
108+
همانطور که می بینیم، این عبارت دقیقاً از دو فرزند `<p>` با نمایه های `0` و `1` تشکیل شده است:
108109

109110
![](range-example-p-0-1.svg)
110111

111-
- The starting point has `<p>` as the parent `node`, and `0` as the offset.
112112

113-
So we can set it as `range.setStart(p, 0)`.
114-
- The ending point also has `<p>` as the parent `node`, but `2` as the offset (it specifies the range up to, but not including `offset`).
113+
- نقطه شروع `<p>` به عنوان `node` والد، و `0` به عنوان آفست است.
114+
115+
بنابراین می‌توانیم آن را به‌عنوان `range.setStart(p, 0)` تنظیم کنیم.
116+
- نقطه پایانی نیز `<p>` را به عنوان `node` والد، اما `2` را به عنوان آفست دارد (محدوده تا را مشخص می کند، اما `offset` را شامل نمی شود).
115117

116-
So we can set it as `range.setEnd(p, 2)`.
118+
بنابراین می‌توانیم آن را به‌عنوان `range.setEnd(p, 2)` تنظیم کنیم.
117119

118-
Here's the demo. If you run it, you can see that the text gets selected:
120+
در اینجا نسخه ی نمایشی است. اگر آن را اجرا کنید، می بینید که متن انتخاب شده است:
119121

120122
```html run
121123
<p id="p">Example: <i>italic</i> and <b>bold</b></p>
@@ -136,7 +138,7 @@ Here's the demo. If you run it, you can see that the text gets selected:
136138
</script>
137139
```
138140

139-
Here's a more flexible test stand where you can set range start/end numbers and explore other variants:
141+
در اینجا یک پایه تست انعطاف‌پذیرتر وجود دارد که در آن می‌توانید اعداد شروع/پایان محدوده را تنظیم کنید و انواع دیگر را بررسی کنیدد:
140142

141143
```html run autorun
142144
<p id="p">Example: <i>italic</i> and <b>bold</b></p>
@@ -159,7 +161,7 @@ From <input id="start" type="number" value=1> – To <input id="end" type="numbe
159161
</script>
160162
```
161163

162-
E.g. selecting in the same `<p>` from offset `1` to `4` gives us the range `<i>italic</i> and <b>bold</b>`:
164+
به عنوان مثال، انتخاب در همان `<p>` از آفست `1` تا `4`، محدوده `<i>italic</i> and <b>bold</b>` را به ما می‌دهد:
163165

164166
![](range-example-p-1-3.svg)
165167

0 commit comments

Comments
 (0)