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
+59-58Lines changed: 59 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,74 +199,74 @@ From <input id="start" type="number" value=1> – To <input id="end" type="numbe
199
199
200
200
Ба більше, якщо ми хочемо взяти вузли як ціле, треба передати елементи замість текстових вузлів в `setStart/setEnd`. Інакше це буде працювати на рівні тексту.
201
201
202
-
## Range properties
202
+
## Властивості Range
203
203
204
-
The range object that we created in the example above has following properties:
204
+
Об’єкт діапазону, який ми використовували у прикладі вище, має такі властивості:
205
205
206
206

207
207
208
-
-`startContainer`, `startOffset` -- node and offset of the start,
209
-
-in the example above: first text node inside`<p>`and`2`.
210
-
-`endContainer`, `endOffset` -- node and offset of the end,
211
-
-in the example above: first text node inside`<b>`and`3`.
212
-
-`collapsed` -- boolean, `true`if the range starts and ends on the same point (so there's no content inside the range),
213
-
-in the example above: `false`
214
-
-`commonAncestorContainer` -- the nearest common ancestor of all nodes within the range,
215
-
-in the example above: `<p>`
208
+
-`startContainer`, `startOffset` -- node і offset початку,
209
+
-у наведеному вище прикладі: перший текстовий вузол всередині`<p>`і`2`.
210
+
-`endContainer`, `endOffset` -- node і offset кінця,
211
+
-у прикладі вище: перший текстовий вузол всередині`<b>`і`3`.
212
+
-`collapsed` -- значення логічного типу, `true`якщо діапазон починається і закінчується в одній точці (тому всередині діапазону немає вмісту),
213
+
-у прикладі вище: `false`
214
+
-`commonAncestorContainer` -- найближчий спільний предок усіх вузлів у діапазоні,
215
+
-у прикладі вище: `<p>`
216
216
217
217
218
-
## Range selection methods
218
+
## Методи виділення в Range
219
219
220
-
There are many convenient methods to manipulate ranges.
220
+
Існує багато зручних методів по роботі з діапазонами.
221
221
222
-
We've already seen`setStart`and`setEnd`, here are other similar methods.
222
+
Ми вже бачили`setStart`і`setEnd`, ось інші подібні методи.
-`setStartBefore(node)`set start at: right before`node`
228
-
-`setStartAfter(node)`set start at: right after`node`
226
+
-`setStart(node, offset)`встановити початок у: позиції`offset`в`node`
227
+
-`setStartBefore(node)`встановити початок о: безпосередньо перед`node`
228
+
-`setStartAfter(node)`встановити початок о: відразу після`node`
229
229
230
-
Set range end (similar methods):
230
+
Встановити кінець діапазону (подібні методи):
231
231
232
-
-`setEnd(node, offset)`set end at: position`offset`in`node`
233
-
-`setEndBefore(node)`set end at: right before`node`
234
-
-`setEndAfter(node)`set end at: right after`node`
232
+
-`setEnd(node, offset)`встановити кінець у: позиції`offset`в`node`
233
+
-`setEndBefore(node)`встановити кінець о: безпосередньо перед`node`
234
+
-`setEndAfter(node)`встановити кінець о: одразу після`node`
235
235
236
-
Technically,`setStart/setEnd`can do anything, but more methods provide more convenience.
236
+
Технічно`setStart/setEnd`можуть робити що завгодно, але більше методів забезпечують більшу зручність.
237
237
238
-
In all these methods,`node`can be both a text or element node: for text nodes`offset`skips that many of characters, while for element nodes that many child nodes.
238
+
У всіх цих методах`node`може бути як текстовим, так і вузлом елементом: для текстових вузлів`offset`пропускає таку кількість символів, тоді як для вузлів елементів стільки ж дочірніх вузлів.
239
239
240
-
Even more methods to create ranges:
241
-
-`selectNode(node)`set range to select the whole`node`
242
-
-`selectNodeContents(node)`set range to select the whole`node` contents
243
-
-`collapse(toStart)`if`toStart=true`set end=start, otherwise set start=end, thus collapsing the range
244
-
-`cloneRange()`creates a new range with the same start/end
240
+
Ще більше методів створення діапазонів:
241
+
-`selectNode(node)`встановити діапазон для виділення всього`node`
242
+
-`selectNodeContents(node)`встановити діапазон для виділення всього вмісту`node`
243
+
-`collapse(toStart)`якщо`toStart=true`встановити кінець=початок, інакше встановити початок=кінець, таким чином згорнувши діапазон
244
+
-`cloneRange()`створює новий діапазон із тим самим початком/кінцем
245
245
246
-
## Range editing methods
246
+
## Методи редагування Range
247
247
248
-
Once the range is created, we can manipulate its content using these methods:
248
+
Після створення діапазону ми можемо маніпулювати його вмістом за допомогою таких методів:
249
249
250
-
-`deleteContents()` -- remove range content from the document
251
-
-`extractContents()` -- remove range content from the document and return as[DocumentFragment](info:modifying-document#document-fragment)
252
-
-`cloneContents()` -- clone range content and return as[DocumentFragment](info:modifying-document#document-fragment)
253
-
-`insertNode(node)` -- insert`node`into the document at the beginning of the range
254
-
-`surroundContents(node)` -- wrap`node`around range content. For this to work, the range must contain both opening and closing tags for all elements inside it: no partial ranges like`<i>abc`.
250
+
-`deleteContents()` -- видалити вміст діапазону з документа
251
+
-`extractContents()` -- видалити вміст діапазону з документа та повернутися як[DocumentFragment](info:modifying-document#document-fragment)
252
+
-`cloneContents()` -- клонувати вміст діапазону та повернутися як[DocumentFragment](info:modifying-document#document-fragment)
253
+
-`insertNode(node)` -- вставити`node`в документ на початку діапазону
254
+
-`surroundContents(node)` -- обернути`node`навколо вмісту діапазону. Щоб це працювало, діапазон має містити відкриваючі та закриваючі теги для всіх елементів у ньому: жодних часткових діапазонів, як-от`<i>abc`.
255
255
256
-
With these methods we can do basically anything with selected nodes.
256
+
За допомогою цих методів ми можемо робити що завгодно з виділенними вузлами.
257
257
258
-
Here's the test stand to see them in action:
258
+
Ось тестовий приклад, щоб побачити їх у дії:
259
259
260
260
```html run refresh autorun height=260
261
-
Click buttons to run methods on the selection, "resetExample" to reset it.
261
+
Натисніть кнопки, щоб запустити методи для виділення, "resetExample", щоб скинути його.
262
262
263
263
<pid="p">Example: <i>italic</i> and <b>bold</b></p>
264
264
265
265
<pid="result"></p>
266
266
<script>
267
267
let range =newRange();
268
268
269
-
//Each demonstrated method is represented here:
269
+
//Кожен продемонстрований метод представлений тут:
270
270
let methods = {
271
271
deleteContents() {
272
272
range.deleteContents()
@@ -312,45 +312,46 @@ Click buttons to run methods on the selection, "resetExample" to reset it.
312
312
</script>
313
313
```
314
314
315
-
There also exist methods to compare ranges, but these are rarely used. When you need them, please refer to the [spec](https://dom.spec.whatwg.org/#interface-range) or[MDN manual](mdn:/api/Range).
315
+
Існують також методи порівняння діапазонів, але вони використовуються рідко. Коли вони вам знадобляться, ви можете з ними познайомитись ось тут [spec](https://dom.spec.whatwg.org/#interface-range), або тут[MDN manual](mdn:/api/Range).
316
316
317
317
318
318
## Selection
319
319
320
-
`Range`is a generic object for managing selection ranges. Although, creating a `Range`doesn't mean that we see a selection on screen.
320
+
`Range`-- це загальний об'єкт для керування діапазонами виділення. Хоча створення `Range`не означає, що ми бачимо виділення на екрані.
321
321
322
-
We may create `Range` objects, pass them around -- they do not visually select anything on their own.
322
+
Ми можемо створювати об’єкти `Range`, передавати їх -- вони самі по собі нічого візуально не виділяють.
323
323
324
-
The document selection is represented by `Selection` object, that can be obtained as `window.getSelection()`or`document.getSelection()`. A selection may include zero or more ranges. At least, the [Selection API specification](https://www.w3.org/TR/selection-api/)says so. In practice though, only Firefox allows to select multiple ranges in the document by using `key:Ctrl+click` (`key:Cmd+click`for Mac).
324
+
Вибраний документ представлений об’єктом `Selection`, який можна отримати як `window.getSelection()`або`document.getSelection()`. Виділення може містити нуль або більше діапазонів. Принаймні, [Selection API specification](https://www.w3.org/TR/selection-api/)каже саме так. Однак на практиці лише Firefox дозволяє вибирати кілька діапазонів у документі за допомогою `key:Ctrl+click` (`key:Cmd+click`для Mac).
325
325
326
-
Here's a screenshot of a selection with 3 ranges, made in Firefox:
326
+
Ось скріншот вибору з 3 діапазонами, зроблений у Firefox:
327
327
328
328

329
329
330
-
Other browsers support at maximum 1 range. As we'll see, some of `Selection`methods imply that there may be many ranges, but again, in all browsers except Firefox, there's at maximum 1.
330
+
Інші браузери підтримують максимум 1 діапазон. Як ми побачимо, деякі з методів `Selection`означають, що може бути багато діапазонів, але знову ж таки, у всіх браузерах, крім Firefox, їх не більше 1.
331
331
332
-
Here's a small demo that shows the current selection (select something and click) as text:
332
+
Ось невеликий приклад, який показує поточний вибір (виберіть щось і натисніть) у вигляді тексту:
0 commit comments