2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Tool object to manage HTML lists items (UL, OL and LI).
26
OutdentListItem : function( listItem )
28
var eParent = listItem.parentNode ;
30
// It may happen that a LI is not in a UL or OL (Orphan).
31
if ( eParent.tagName.toUpperCase().Equals( 'UL','OL' ) )
33
var oDocument = FCKTools.GetElementDocument( listItem ) ;
34
var oDogFrag = new FCKDocumentFragment( oDocument ) ;
36
// All children and successive siblings will be moved to a a DocFrag.
37
var eNextSiblings = oDogFrag.RootNode ;
38
var eHasLiSibling = false ;
40
// If we have nested lists inside it, let's move it to the list of siblings.
41
var eChildList = FCKDomTools.GetFirstChild( listItem, ['UL','OL'] ) ;
44
eHasLiSibling = true ;
47
// The extra () is to avoid a warning with strict error checking. This is ok.
48
while ( (eChild = eChildList.firstChild) )
49
eNextSiblings.appendChild( eChildList.removeChild( eChild ) ) ;
51
FCKDomTools.RemoveNode( eChildList ) ;
54
// Move all successive siblings.
56
var eHasSuccessiveLiSibling = false ;
57
// The extra () is to avoid a warning with strict error checking. This is ok.
58
while ( (eSibling = listItem.nextSibling) )
60
if ( !eHasLiSibling && eSibling.nodeType == 1 && eSibling.nodeName.toUpperCase() == 'LI' )
61
eHasSuccessiveLiSibling = eHasLiSibling = true ;
63
eNextSiblings.appendChild( eSibling.parentNode.removeChild( eSibling ) ) ;
65
// If a sibling is a incorrectly nested UL or OL, consider only its children.
66
if ( !eHasSuccessiveLiSibling && eSibling.nodeType == 1 && eSibling.nodeName.toUpperCase().Equals( 'UL','OL' ) )
67
FCKDomTools.RemoveNode( eSibling, true ) ;
70
// If we are in a list chain.
71
var sParentParentTag = eParent.parentNode.tagName.toUpperCase() ;
72
var bWellNested = ( sParentParentTag == 'LI' ) ;
73
if ( bWellNested || sParentParentTag.Equals( 'UL','OL' ) )
77
var eChildList = eParent.cloneNode( false ) ;
78
oDogFrag.AppendTo( eChildList ) ;
79
listItem.appendChild( eChildList ) ;
81
else if ( bWellNested )
82
oDogFrag.InsertAfterNode( eParent.parentNode ) ;
84
oDogFrag.InsertAfterNode( eParent ) ;
86
// Move the LI after its parent.parentNode (the upper LI in the hierarchy).
88
FCKDomTools.InsertAfterNode( eParent.parentNode, eParent.removeChild( listItem ) ) ;
90
FCKDomTools.InsertAfterNode( eParent, eParent.removeChild( listItem ) ) ;
96
var eNextList = eParent.cloneNode( false ) ;
97
oDogFrag.AppendTo( eNextList ) ;
98
FCKDomTools.InsertAfterNode( eParent, eNextList ) ;
101
var eBlock = oDocument.createElement( FCKConfig.EnterMode == 'p' ? 'p' : 'div' ) ;
102
FCKDomTools.MoveChildren( eParent.removeChild( listItem ), eBlock ) ;
103
FCKDomTools.InsertAfterNode( eParent, eBlock ) ;
105
if ( FCKConfig.EnterMode == 'br' )
107
// We need the bogus to make it work properly. In Gecko, we
108
// need it before the new block, on IE, after it.
109
if ( FCKBrowserInfo.IsGecko )
110
eBlock.parentNode.insertBefore( FCKTools.CreateBogusBR( oDocument ), eBlock ) ;
112
FCKDomTools.InsertAfterNode( eBlock, FCKTools.CreateBogusBR( oDocument ) ) ;
114
FCKDomTools.RemoveNode( eBlock, true ) ;
118
if ( this.CheckEmptyList( eParent ) )
119
FCKDomTools.RemoveNode( eParent, true ) ;
123
CheckEmptyList : function( listElement )
125
return ( FCKDomTools.GetFirstChild( listElement, 'LI' ) == null ) ;
128
// Check if the list has contents (excluding nested lists).
129
CheckListHasContents : function( listElement )
131
var eChildNode = listElement.firstChild ;
135
switch ( eChildNode.nodeType )
138
if ( !eChildNode.nodeName.IEquals( 'UL','LI' ) )
143
if ( eChildNode.nodeValue.Trim().length > 0 )
147
eChildNode = eChildNode.nextSibling ;