1 | |
---|
2 | function SelectInitialText(){ |
---|
3 | this.Name = 'SelectInitialText'; |
---|
4 | } |
---|
5 | |
---|
6 | SelectInitialText.prototype.Execute = function(){ |
---|
7 | //if ( FCK.Selection != null ) FCK.Selection.Release(false); |
---|
8 | var children = null; |
---|
9 | if ( FCK.EditorWindow.document.body.childNodes != null ) children = FCK.EditorWindow.document.body.childNodes; |
---|
10 | else children = FCK.EditorWindow.document.body.children; |
---|
11 | |
---|
12 | if ( children == null ) return; |
---|
13 | else if ( children.length == 0 ) return; |
---|
14 | FCK.Focus(); |
---|
15 | //alert(children[0].tagName ); |
---|
16 | // if there is only one child (text), we will put a span at the end of it. This is to prevent the background color bug in IE. |
---|
17 | var setEndVal = 2; |
---|
18 | if ( !FCKBrowserInfo.IsIE ) setEndVal = 4; |
---|
19 | //if (((children.length == 1) || (children[children.length-1].tagName == null)) && FCKBrowserInfo.IsIE){ |
---|
20 | if (DoInsert(children)){ |
---|
21 | this.InsertEmptySpan(); |
---|
22 | // refresh the children. |
---|
23 | if ( FCK.EditorWindow.document.body.childNodes != null ) children = FCK.EditorWindow.document.body.childNodes; |
---|
24 | else children = FCK.EditorWindow.document.body.children; |
---|
25 | setEndVal = 4; |
---|
26 | } |
---|
27 | |
---|
28 | var range = new FCKDomRange(FCK.EditorWindow); |
---|
29 | range.SetStart( children[0] , 3 ); |
---|
30 | range.SetEnd( children[children.length - 1] , setEndVal ); |
---|
31 | range.Select(); |
---|
32 | } |
---|
33 | |
---|
34 | function DoInsert(children){ |
---|
35 | if ( !FCKBrowserInfo.IsIE ) return false; |
---|
36 | |
---|
37 | if (children.length == 1) return true; |
---|
38 | var lastChild = children[children.length-1]; |
---|
39 | if (lastChild.tagName == null) return true; |
---|
40 | if (lastChild.tagName != null && lastChild.innerHTML != '') return true; |
---|
41 | return false; |
---|
42 | } |
---|
43 | |
---|
44 | SelectInitialText.prototype.InsertEmptySpan = function(){ |
---|
45 | if ( !FCKBrowserInfo.IsIE ) return; // only an IE issue |
---|
46 | |
---|
47 | var domItem = FCK.EditorWindow.document.createElement('span'); |
---|
48 | domItem.style.display = 'none'; |
---|
49 | FCK.EditorWindow.document.body.appendChild(domItem); |
---|
50 | } |
---|
51 | |
---|
52 | SelectInitialText.prototype.GetState = function() |
---|
53 | { |
---|
54 | return FCK_TRISTATE_OFF; |
---|
55 | } |
---|
56 | |
---|
57 | FCKCommands.RegisterCommand( 'SelectInitialText', new SelectInitialText()) ; |
---|