]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_editor/selection.js
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit._editor.selection"]){
9 dojo
._hasResource
["dijit._editor.selection"]=true;
10 dojo
.provide("dijit._editor.selection");
11 dojo
.mixin(dijit
._editor
.selection
,{getType:function(){
13 return dojo
.doc
.selection
.type
.toLowerCase();
18 _2
=dojo
.global
.getSelection();
22 if(_2
&&_2
.rangeCount
==1){
23 var _3
=_2
.getRangeAt(0);
24 if((_3
.startContainer
==_3
.endContainer
)&&((_3
.endOffset
-_3
.startOffset
)==1)&&(_3
.startContainer
.nodeType
!=3)){
30 },getSelectedText:function(){
32 if(dijit
._editor
.selection
.getType()=="control"){
35 return dojo
.doc
.selection
.createRange().text
;
37 var _4
=dojo
.global
.getSelection();
43 },getSelectedHtml:function(){
45 if(dijit
._editor
.selection
.getType()=="control"){
48 return dojo
.doc
.selection
.createRange().htmlText
;
50 var _5
=dojo
.global
.getSelection();
51 if(_5
&&_5
.rangeCount
){
54 for(i
=0;i
<_5
.rangeCount
;i
++){
55 var _7
=_5
.getRangeAt(i
).cloneContents();
56 var _8
=dojo
.doc
.createElement("div");
64 },getSelectedElement:function(){
65 if(dijit
._editor
.selection
.getType()=="control"){
67 var _9
=dojo
.doc
.selection
.createRange();
69 return dojo
.doc
.selection
.createRange().item(0);
72 var _a
=dojo
.global
.getSelection();
73 return _a
.anchorNode
.childNodes
[_a
.anchorOffset
];
77 },getParentElement:function(){
78 if(dijit
._editor
.selection
.getType()=="control"){
79 var p
=this.getSelectedElement();
85 var r
=dojo
.doc
.selection
.createRange();
87 return r
.parentElement();
89 var _b
=dojo
.global
.getSelection();
92 while(_c
&&(_c
.nodeType
!=1)){
100 },hasAncestorElement:function(_d
){
101 return this.getAncestorElement
.apply(this,arguments
)!=null;
102 },getAncestorElement:function(_e
){
103 var _f
=this.getSelectedElement()||this.getParentElement();
104 return this.getParentOfType(_f
,arguments
);
105 },isTag:function(_10
,_11
){
106 if(_10
&&_10
.tagName
){
107 var _12
=_10
.tagName
.toLowerCase();
108 for(var i
=0;i
<_11
.length
;i
++){
109 var _13
=String(_11
[i
]).toLowerCase();
116 },getParentOfType:function(_14
,_15
){
118 if(this.isTag(_14
,_15
).length
){
124 },collapse:function(_16
){
125 if(window
.getSelection
){
126 var _17
=dojo
.global
.getSelection();
127 if(_17
.removeAllRanges
){
129 _17
.collapseToStart();
138 var _18
=dojo
.doc
.selection
.createRange();
144 var sel
=dojo
.doc
.selection
;
146 if(sel
.type
.toLowerCase()!="none"){
151 sel
=dojo
.global
.getSelection();
152 sel
.deleteFromDocument();
155 },selectElementChildren:function(_19
,_1a
){
160 if(doc
.selection
&&dojo
.isIE
&&dojo
.body().createTextRange
){
161 _1b
=_19
.ownerDocument
.body
.createTextRange();
162 _1b
.moveToElementText(_19
);
171 if(win
.getSelection
){
172 var _1c
=dojo
.global
.getSelection();
175 _1b
=_1c
.getRangeAt(0);
177 _1b
=doc
.createRange();
180 _1b
.setEnd(_19
,(_19
.nodeType
==3)?_19
.length
:_19
.childNodes
.length
);
183 _1c
.selectAllChildren(_19
);
187 },selectElement:function(_1d
,_1e
){
192 if(dojo
.isIE
&&dojo
.body().createTextRange
){
194 _1f
=dojo
.body().createControlRange();
201 this.selectElementChildren(_1d
,_1e
);
204 if(dojo
.global
.getSelection
){
205 var _20
=win
.getSelection();
206 _1f
=doc
.createRange();
207 if(_20
.removeAllRanges
){
209 if(_20
.getRangeAt(0)){
210 _1f
=_20
.getRangeAt(0);
214 _20
.removeAllRanges();
219 },inSelection:function(_21
){
224 if(dojo
.global
.getSelection
){
225 var sel
=dojo
.global
.getSelection();
226 if(sel
&&sel
.rangeCount
>0){
227 _23
=sel
.getRangeAt(0);
229 if(_23
&&_23
.compareBoundaryPoints
&&doc
.createRange
){
231 _22
=doc
.createRange();
233 if(_23
.compareBoundaryPoints(_23
.START_TO_END
,_22
)===1){
242 _23
=doc
.selection
.createRange();
244 _22
=_21
.ownerDocument
.body
.createControlRange();
251 _22
=_21
.ownerDocument
.body
.createTextRange();
252 _22
.moveToElementText(_21
);
258 if(_23
.compareEndPoints("EndToStart",_22
)===1){