[ Index ] |
|
Code source de FCKeditor 2.4 |
1 /* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * File Name: fcklisthandler.js 22 * Tool object to manage HTML lists items (UL, OL and LI). 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 var FCKListHandler = 29 { 30 OutdentListItem : function( listItem ) 31 { 32 var eParent = listItem.parentNode ; 33 34 // It may happen that a LI is not in a UL or OL (Orphan). 35 if ( eParent.tagName.toUpperCase().Equals( 'UL','OL' ) ) 36 { 37 var oDocument = FCKTools.GetElementDocument( listItem ) ; 38 var oDogFrag = new FCKDocumentFragment( oDocument ) ; 39 40 // All children and successive siblings will be moved to a a DocFrag. 41 var eNextSiblings = oDogFrag.RootNode ; 42 var eHasLiSibling = false ; 43 44 // If we have nested lists inside it, let's move it to the list of siblings. 45 var eChildList = FCKDomTools.GetFirstChild( listItem, ['UL','OL'] ) ; 46 if ( eChildList ) 47 { 48 eHasLiSibling = true ; 49 50 var eChild ; 51 // The extra () is to avoid a warning with strict error checking. This is ok. 52 while ( (eChild = eChildList.firstChild) ) 53 eNextSiblings.appendChild( eChildList.removeChild( eChild ) ) ; 54 55 FCKDomTools.RemoveNode( eChildList ) ; 56 } 57 58 // Move all successive siblings. 59 var eSibling ; 60 var eHasSuccessiveLiSibling = false ; 61 // The extra () is to avoid a warning with strict error checking. This is ok. 62 while ( (eSibling = listItem.nextSibling) ) 63 { 64 if ( !eHasLiSibling && eSibling.nodeType == 1 && eSibling.nodeName.toUpperCase() == 'LI' ) 65 eHasSuccessiveLiSibling = eHasLiSibling = true ; 66 67 eNextSiblings.appendChild( eSibling.parentNode.removeChild( eSibling ) ) ; 68 69 // If a sibling is a incorrectly nested UL or OL, consider only its children. 70 if ( !eHasSuccessiveLiSibling && eSibling.nodeType == 1 && eSibling.nodeName.toUpperCase().Equals( 'UL','OL' ) ) 71 FCKDomTools.RemoveNode( eSibling, true ) ; 72 } 73 74 // If we are in a list chain. 75 var sParentParentTag = eParent.parentNode.tagName.toUpperCase() ; 76 var bWellNested = ( sParentParentTag == 'LI' ) ; 77 if ( bWellNested || sParentParentTag.Equals( 'UL','OL' ) ) 78 { 79 if ( eHasLiSibling ) 80 { 81 var eChildList = eParent.cloneNode( false ) ; 82 oDogFrag.AppendTo( eChildList ) ; 83 listItem.appendChild( eChildList ) ; 84 } 85 else if ( bWellNested ) 86 oDogFrag.InsertAfterNode( eParent.parentNode ) ; 87 else 88 oDogFrag.InsertAfterNode( eParent ) ; 89 90 // Move the LI after its parent.parentNode (the upper LI in the hierarchy). 91 if ( bWellNested ) 92 FCKDomTools.InsertAfterNode( eParent.parentNode, eParent.removeChild( listItem ) ) ; 93 else 94 FCKDomTools.InsertAfterNode( eParent, eParent.removeChild( listItem ) ) ; 95 } 96 else 97 { 98 if ( eHasLiSibling ) 99 { 100 var eNextList = eParent.cloneNode( false ) ; 101 oDogFrag.AppendTo( eNextList ) ; 102 FCKDomTools.InsertAfterNode( eParent, eNextList ) ; 103 } 104 105 var eBlock = oDocument.createElement( 'p' ) ; // TODO: Get from configuration. 106 FCKDomTools.MoveChildren( eParent.removeChild( listItem ), eBlock ) ; 107 FCKDomTools.InsertAfterNode( eParent, eBlock ) ; 108 109 listItem = eBlock ; 110 } 111 112 if ( this.CheckEmptyList( eParent ) ) 113 FCKDomTools.RemoveNode( eParent, true ) ; 114 } 115 116 return listItem ; 117 }, 118 119 CheckEmptyList : function( listElement ) 120 { 121 return ( FCKDomTools.GetFirstChild( listElement, 'LI' ) == null ) ; 122 }, 123 124 // Check if the list has contents (excluding nested lists). 125 CheckListHasContents : function( listElement ) 126 { 127 var eChildNode = listElement.firstChild ; 128 129 while ( eChildNode ) 130 { 131 switch ( eChildNode.nodeType ) 132 { 133 case 1 : 134 if ( !eChildNode.nodeName.IEquals( 'UL','LI' ) ) 135 return true ; 136 break ; 137 138 case 3 : 139 if ( eChildNode.nodeValue.Trim().length > 0 ) 140 return true ; 141 } 142 143 eChildNode = eChildNode.nextSibling ; 144 } 145 146 return false ; 147 } 148 } ;
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |