注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

百鬼夜行

身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。

 
 
 

日志

 
 

APIs for the browsing context selection  

2015-01-19 15:17:33|  分类: 规范等 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
window . getSelection()
document . getSelection()

Returns the Selection object for the window, which stringifies to the text of the current selection.

The getSelection() method on the Window interface must return the Selection object representing the selection of that Window object's browsing context.

For historical reasons, the getSelection() method on the HTMLDocument interface must return the same Selection object.

[Stringifies] interface Selection {
  readonly attribute Node anchorNode;
  readonly attribute long anchorOffset;
  readonly attribute Node focusNode;
  readonly attribute long focusOffset;
  readonly attribute boolean isCollapsed;
  void collapse(in Node parentNode, in long offset);
  void collapseToStart();
  void collapseToEnd();
  void selectAllChildren(in Node parentNode);
  void deleteFromDocument();
  readonly attribute long rangeCount;
  Range getRangeAt(in long index);
  void addRange(in Range range);
  void removeRange(in Range range);
  void removeAllRanges();
};

The Selection interface is represents a list of Range objects. The first item in the list has index 0, and the last item has index count-1, where count is the number of ranges in the list.[DOM2RANGE]

All of the members of the Selection interface are defined in terms of operations on the Range objects represented by this object. These operations can raise exceptions, as defined for the Rangeinterface; this can therefore result in the members of the Selection interface raising exceptions as well, in addition to any explicitly called out below.

selection . anchorNode

Returns the element that contains the start of the selection.

Returns null if there's no selection.

selection . anchorOffset

Returns the offset of the start of the selection relative to the element that contains the start of the selection.

Returns 0 if there's no selection.

selection . focusNode

Returns the element that contains the end of the selection.

Returns null if there's no selection.

selection . focusOffset

Returns the offset of the end of the selection relative to the element that contains the end of the selection.

Returns 0 if there's no selection.

collapsed = selection . isCollapsed()

Returns true if there's no selection or if the selection is empty. Otherwise, returns false.

selection . collapsed(parentNodeoffset)

Replaces the selection with an empty one at the given position.

Throws a WRONG_DOCUMENT_ERR exception if the given node is in a different document.

selection . collapseToStart()

Replaces the selection with an empty one at the position of the start of the current selection.

Throws an INVALID_STATE_ERR exception if there is no selection.

selection . collapseToEnd()

Replaces the selection with an empty one at the position of the end of the current selection.

Throws an INVALID_STATE_ERR exception if there is no selection.

selection . selectAllChildren(parentNode)

Replaces the selection with one that contains all the contents of the given element.

Throws a WRONG_DOCUMENT_ERR exception if the given node is in a different document.

selection . deleteFromDocument()

Deletes the selection.

selection . rangeCount

Returns the number of ranges in the selection.

selection . getRangeAt(index)

Returns the given range.

Throws an INVALID_STATE_ERR exception if the value is out of range.

selection . addRange(range)

Adds the given range to the selection.

selection . removeRange(range)

Removes the given range from the selection, if the range was one of the ones in the selection.

selection . removeAllRanges()

Removes all the ranges in the selection.

The anchorNode attribute must return the value returned by the startContainer attribute of the last Range object in the list, or null if the list is empty.

The anchorOffset attribute must return the value returned by the startOffset attribute of the last Range object in the list, or 0 if the list is empty.

The focusNode attribute must return the value returned by the endContainer attribute of the last Range object in the list, or null if the list is empty.

The focusOffset attribute must return the value returned by the endOffset attribute of the last Range object in the list, or 0 if the list is empty.

The isCollapsed attribute must return true if there are zero ranges, or if there is exactly one range and its collapsed attribute is itself true. Otherwise it must return false.

The collapse(parentNodeoffset) method must raise a WRONG_DOCUMENT_ERR DOM exception if parentNode's Document is not the HTMLDocument object with which the Selection object is associated. Otherwise it is, and the method must remove all the ranges in the Selection list, then create a new Range object, add it to the list, and invoke its setStart() and setEnd() methods with the parentNode and offsetvalues as their arguments.

The collapseToStart() method must raise an INVALID_STATE_ERR DOM exception if there are no ranges in the list. Otherwise, it must invoke the collapse() method with the startContainer and startOffsetvalues of the first Range object in the list as the arguments.

The collapseToEnd() method must raise an INVALID_STATE_ERR DOM exception if there are no ranges in the list. Otherwise, it must invoke the collapse() method with the endContainer and endOffset values of the last Range object in the list as the arguments.

The selectAllChildren(parentNode) method must invoke the collapse() method with the parentNode value as the first argument and 0 as the second argument, and must then invoke the selectNodeContents()method on the first (and only) range in the list with the parentNode value as the argument.

The deleteFromDocument() method must invoke the deleteContents() method on each range in the list, if any, from first to last.

The rangeCount attribute must return the number of ranges in the list.

The getRangeAt(index) method must return the indexth range in the list. If index is less than zero or greater or equal to the value returned by the rangeCount attribute, then the method must raise an INDEX_SIZE_ERR DOM exception.

The addRange(range) method must add the given range Range object to the list of selections, at the end (so the newly added range is the new last range). Duplicates are not prevented; a range may be added more than once in which case it appears in the list more than once, which (for example) will cause stringification to return the range's text twice.

The removeRange(range) method must remove the first occurrence of range in the list of ranges, if it appears at all.

The removeAllRanges() method must remove all the ranges from the list of ranges, such that the rangeCount attribute returns 0 after the removeAllRanges() method is invoked (and until a new range is added to the list, either through this interface or via user interaction).

Objects implementing this interface must stringify to a concatenation of the results of invoking the toString() method of the Range object on each of the ranges of the selection, in the order they appear in the list (first to last).

In the following document fragment, the emphasized parts indicate the selection.

<p>The cute girl likes the <cite>Oxford English Dictionary</cite>.</p>

If a script invoked window.getSelection().toString(), the return value would be "the Oxford English".

The Selection interface has no relation to the DataGridSelection interface.

  评论这张
 
阅读(54)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017