aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/selection
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/selection
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/ru/web/api/selection')
-rw-r--r--files/ru/web/api/selection/getrangeat/index.html118
-rw-r--r--files/ru/web/api/selection/index.html223
-rw-r--r--files/ru/web/api/selection/tostring/index.html66
3 files changed, 407 insertions, 0 deletions
diff --git a/files/ru/web/api/selection/getrangeat/index.html b/files/ru/web/api/selection/getrangeat/index.html
new file mode 100644
index 0000000000..b69ef6a122
--- /dev/null
+++ b/files/ru/web/api/selection/getrangeat/index.html
@@ -0,0 +1,118 @@
+---
+title: Selection.getRangeAt()
+slug: Web/API/Selection/getRangeAt
+translation_of: Web/API/Selection/getRangeAt
+---
+<div>
+<div>
+<div>
+<div>{{ ApiRef("DOM") }}{{SeeCompatTable}}</div>
+</div>
+</div>
+</div>
+
+<p>Метод <strong><code>Selection.getRangeAt()</code></strong> возвращает объект диапазона, который представляет один из диапазонов, выделенного на данный момент.</p>
+
+<h2 id="Syntax" name="Syntax">Синтаксис</h2>
+
+<pre class="syntaxbox"><em>range</em> = <em>sel</em>.getRangeAt(<em>index</em>)
+</pre>
+
+<h3 id="Parameters" name="Parameters">Параметры</h3>
+
+<dl>
+ <dt><em><code>range</code></em></dt>
+ <dd>Объект {{domxref("Range")}}, который будет возвращён.</dd>
+ <dt><em><code>index</code></em></dt>
+ <dd>Индекс диапазона, начинающийся с нуля, который необходимо вернуть. Отрицательное значение или значение выше или равное {{domxref("Selection.rangeCount")}} приведёт к ошибке.</dd>
+</dl>
+
+<h2 id="Examples" name="Examples">Примеры</h2>
+
+<pre class="brush:js">var ranges = [];
+
+sel = window.getSelection();
+
+for(var i = 0; i &lt; sel.rangeCount; i++) {
+ ranges[i] = sel.getRangeAt(i);
+}
+/* Каждый элемент в массиве диапазонов является
+ * объектом диапазона, который представляет
+ * один из диапазонов текущего выделения */
+</pre>
+
+<h2 id="Спецификации">Спецификации</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Спецификация</th>
+ <th scope="col">Статус</th>
+ <th scope="col">Комментарий</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML Editing', '#dom-selection-getrangeat', 'Selection.getRangeAt()')}}</td>
+ <td>{{Spec2('HTML Editing')}}</td>
+ <td>Первоначальное определение</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Совместимость</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Особенность</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Базовая поддержка</td>
+ <td>Да</td>
+ <td>{{CompatVersionUnknown()}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Особенность</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Базовая поддержка</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown()}}</td>
+ <td>1.0</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also" name="See_also">Смотрите также</h2>
+
+<ul>
+ <li>{{domxref("Selection")}}, интерфейс, к которому принадлежит метод.</li>
+ <li><a href="/en-US/docs/XUL_Tutorial/Tree_Selection" title="XUL_Tutorial/Tree_Selection">Tree Selection</a> (для метода <code>getRangeAt()</code> в интерфейсе <code>nsITreeSelection</code>)</li>
+</ul>
diff --git a/files/ru/web/api/selection/index.html b/files/ru/web/api/selection/index.html
new file mode 100644
index 0000000000..183e9a7cb7
--- /dev/null
+++ b/files/ru/web/api/selection/index.html
@@ -0,0 +1,223 @@
+---
+title: Selection
+slug: Web/API/Selection
+tags:
+ - API
+ - Experimental
+ - Interface
+ - NeedsTranslation
+ - Reference
+ - Selection
+ - TopicStub
+translation_of: Web/API/Selection
+---
+<div>{{ ApiRef("DOM") }}{{SeeCompatTable}}</div>
+
+<div>A <code><strong>Selection</strong></code> object represents the range of text selected by the user or the current position of the caret. To obtain a Selection object for examination or modification, call {{domxref("window.getSelection()")}}.</div>
+
+<div> </div>
+
+<h2 id="Properties" name="Properties">Свойства</h2>
+
+<dl>
+ <dt>{{domxref("Selection.anchorNode")}}</dt>
+ <dd>Returns the {{domxref("Node")}} in which the selection begins.</dd>
+ <dt>{{domxref("Selection.anchorOffset")}}</dt>
+ <dd>Returns a number representing the offset of the selection's anchor within the anchorNode. If anchorNode is a text node, this is the number of characters within anchorNode preceding the anchor. If anchorNode is an element, this is the number of child nodes of the anchorNode preceding the anchor.</dd>
+ <dt>{{domxref("Selection.focusNode")}}</dt>
+ <dd>Returns the {{domxref("Node")}} in which the selection ends.</dd>
+ <dt>{{domxref("Selection.focusOffset")}}</dt>
+ <dd>Returns a number representing the offset of the selection's anchor within the focusNode. If focusNode is a text node, this is the number of characters within focusNode preceding the focus. If focusNode is an element, this is the number of child nodes of the focusNode preceding the focus.</dd>
+ <dt>{{domxref("Selection.isCollapsed")}}</dt>
+ <dd>Returns a Boolean indicating whether the selection's start and end points are at the same position.</dd>
+ <dt>{{domxref("Selection.rangeCount")}}</dt>
+ <dd>Returns the number of ranges in the selection.</dd>
+</dl>
+
+<h2 id="Methods" name="Methods">Методы</h2>
+
+<dl>
+ <dt>{{domxref("Selection.getRangeAt()")}}</dt>
+ <dd>Returns a {{domxref("Range")}} object representing one of the ranges currently selected.</dd>
+ <dt>{{domxref("Selection.collapse()")}}</dt>
+ <dd>Collapses the current selection to a single point.</dd>
+ <dt>{{domxref("Selection.extend()")}}</dt>
+ <dd>Moves the focus of the selection to a specified point.</dd>
+ <dt>{{domxref("Selection.modify()")}}{{non-standard_inline}}</dt>
+ <dd>Changes the current selection.</dd>
+ <dt>{{domxref("Selection.collapseToStart()")}}</dt>
+ <dd>Collapses the selection to the start of the first range in the selection.</dd>
+ <dt>{{domxref("Selection.collapseToEnd()")}}</dt>
+ <dd>Collapses the selection to the end of the last range in the selection.</dd>
+ <dt>{{domxref("Selection.selectAllChildren()")}}</dt>
+ <dd>Adds all the children of the specified node to the selection.</dd>
+ <dt>{{domxref("Selection.addRange()")}}</dt>
+ <dd>A {{domxref("Range")}} object that will be added to the selection.</dd>
+ <dt>{{domxref("Selection.removeRange()")}}</dt>
+ <dd>Removes a range from the selection.</dd>
+ <dt>{{domxref("Selection.removeAllRanges()")}}</dt>
+ <dd>Removes all ranges from the selection.</dd>
+ <dt>{{domxref("Selection.deleteFromDocument()")}}</dt>
+ <dd>Deletes the selection's content from the document.</dd>
+ <dt>{{domxref("Selection.toString()")}}</dt>
+ <dd>Returns a string currently being represented by the selection object, i.e. the currently selected text.</dd>
+ <dt>{{domxref("Selection.containsNode()")}}</dt>
+ <dd>Indicates if a certain node is part of the selection.</dd>
+</dl>
+
+<h2 id="Notes">Notes</h2>
+
+<h3 id="String_representation_of_a_selection">String representation of a selection</h3>
+
+<p>Calling the {{domxref("Selection.toString()")}} method returns the text contained in the selection, e.g.:</p>
+
+<pre class="brush: js">var selObj = window.getSelection();
+window.alert(selObj);
+</pre>
+
+<p>Note that using a selection object as the argument to <code>window.alert</code> will call the object's <code>toString</code> method.</p>
+
+<h3 id="Multiple_ranges_in_a_selection">Multiple ranges in a selection</h3>
+
+<p>A selection object represents the {{domxref("range","ranges")}} that the user has selected. Typically, it holds only one range, accessed as follows:</p>
+
+<div style="overflow: hidden;">
+<pre class="brush:js">var selObj = window.getSelection();
+var range = selObj.getRangeAt(0);</pre>
+</div>
+
+<ul>
+ <li><code>selObj</code> is a Selection object</li>
+ <li><code>range</code> is a {{domxref("Range")}} object</li>
+</ul>
+
+<p>As the <a href="http://www.w3.org/TR/selection-api/#h_note_15">Selection API specification notes</a>, the Selection API was initially created by Netscape and used multiple ranges, for instance, to allow the user to select a column from a {{HTMLElement("table")}}. However browsers other than Gecko did not implement multiple ranges, and the specification also requires the selection to always have a single range.</p>
+
+<h3 id="Selection_and_input_focus">Selection and input focus</h3>
+
+<p>Selection and input focus (indicated by {{domxref("Document.activeElement")}}) have a complex relation, that depends on the browser. In cross-browser compatible code it's better to handle them separately.</p>
+
+<p>Safari and Chrome (unlike Firefox) historically focus the element containing selection when modifying the selection programmatically, but this might change in the future (see <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=14383">W3C bug 14383</a> and {{webkitbug("38696")}}).</p>
+
+<h3 id="Glossary" name="Glossary">Glossary</h3>
+
+<p>Other key terms used in this section.</p>
+
+<dl>
+ <dt>anchor</dt>
+ <dd>The anchor of a selection is the beginning point of the selection. When making a selection with a mouse, the anchor is where in the document the mouse button is initially pressed. As the user changes the selection using the mouse or the keyboard, the anchor does not move.</dd>
+ <dt>focus of a selection</dt>
+ <dd>The focus of a selection is the end point of the selection. When making a selection with a mouse, the focus is where in the document the mouse button is released. As the user changes the selection using the mouse or the keyboard, the focus is the end of the selection that moves.<strong> Note:</strong> This is not the same as the focused <em>element</em> of the document, as returned by {{domxref("document.activeElement")}}.</dd>
+ <dt>range</dt>
+ <dd>A range is a contiguous part of a document. A range can contain entire nodes as well as portions of nodes, such as a portion of a text node. A user will normally only select a single range at a time, but it's possible for a user to select multiple ranges (e.g. by using the Control key). A range can be retrieved from a selection as a {{domxref("range")}} object. Range objects can also be created via the DOM and programmatically added or removed from a selection.</dd>
+</dl>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML Editing', '#selection', 'Selection')}}</td>
+ <td>{{Spec2('HTML Editing')}}</td>
+ <td>Initial (older) definition</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Selection API', '#definition', 'Selection')}}</td>
+ <td>{{Spec2('Selection API')}}</td>
+ <td>The Selection API specification is based on the HTML Editing APIs specification and focuses on the Selection-related functionality.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown()}}</td>
+ <td>9</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>modify()</code></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop(2)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown()}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>modify()</code></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(2)}}</td>
+ <td>1.0</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also" name="See_also">См. также</h2>
+
+<ul>
+ <li>{{domxref("Window.getSelection")}}, {{domxref("Document.getSelection")}}, {{domxref("Range")}}</li>
+ <li>HTML inputs provide simpler helper APIs for working with selection (see {{domxref("HTMLInputElement.setSelectionRange()")}})</li>
+ <li>{{domxref("Document.activeElement")}}, {{domxref("HTMLElement.focus()")}}, and {{domxref("HTMLElement.blur()")}}</li>
+</ul>
+
+<h2 id="Gecko_notes">Gecko notes</h2>
+
+<ul>
+ <li>Gecko/Firefox provide additional features, available to chrome (internal and add-on) code only. These are defined in {{interface("nsISelectionPrivate")}}.</li>
+ <li>Mozilla source code: {{source("dom/webidl/Selection.webidl")}}</li>
+ <li>{{obsolete_inline("gecko29")}} {{domxref("Selection.selectionLanguageChange()")}} used to be exposed to the web content until Firefox 29</li>
+</ul>
+
+<dl>
+</dl>
diff --git a/files/ru/web/api/selection/tostring/index.html b/files/ru/web/api/selection/tostring/index.html
new file mode 100644
index 0000000000..9726f381b9
--- /dev/null
+++ b/files/ru/web/api/selection/tostring/index.html
@@ -0,0 +1,66 @@
+---
+title: Selection.toString()
+slug: Web/API/Selection/toString
+translation_of: Web/API/Selection/toString
+---
+<div>
+<div>
+<div>{{ ApiRef("DOM") }}{{SeeCompatTable}}</div>
+</div>
+</div>
+
+<p>Метод <strong><code>Selection.toString()</code></strong> возвращает строку, содержащуюся в выделенном объекте, т.е. выделенный текст.</p>
+
+<h2 id="Syntax" name="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><em>str</em> =<em> sel</em>.toString()
+</pre>
+
+<h3 id="Return_value">Return value</h3>
+
+<ul>
+ <li><em><code>str</code></em> -- это строка, содержащаяся в выделении.</li>
+</ul>
+
+<h3 id="Parameters" name="Parameters">Parameters</h3>
+
+<p><em>None (отсутствуют).</em></p>
+
+<h2 id="Description" name="Description">Description</h2>
+
+<p>Этото метод возвращает выделенный текст.</p>
+
+<p>В <a href="en/JavaScript">JavaScript</a>, этот метод вызывается автоматически, когда функция, которой он передается, требует строку:</p>
+
+<pre class="brush: js">alert(window.getSelection()) // What is called
+alert(window.getSelection().toString()) // What is actually being effectively called.
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML Editing', '#dom-selection-stringifier', 'Selection.toString()')}}</td>
+ <td>{{Spec2('HTML Editing')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.Selection.toString")}}</p>
+
+<h2 id="See_also" name="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("Selection")}}, the interface it belongs to.</li>
+</ul>