Ticket #1858: fckjustifycommands.js.patch
File fckjustifycommands.js.patch, 3.9 KB (added by , 15 years ago) |
---|
-
editor/_source/commandclasses/fckjustifycommands.js
1 /*1 /* 2 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 4 * … … 88 88 { 89 89 // Save an undo snapshot before doing anything. 90 90 FCKUndo.SaveUndoStep() ; 91 91 92 92 var range = new FCKDomRange( FCK.EditorWindow ) ; 93 93 range.MoveToSelection() ; 94 94 95 95 var currentState = this.GetState() ; 96 96 if ( currentState == FCK_TRISTATE_DISABLED ) 97 97 return ; 98 99 // Store a bookmark of the selection since the paragraph iterator might 100 // change the DOM tree and break selections. 101 var bookmark = range.CreateBookmark() ; 102 103 var cssClassName = this._CssClassName ; 104 105 // Apply alignment setting for each paragraph. 106 var iterator = new FCKDomRangeIterator( range ) ; 107 var block ; 108 while ( ( block = iterator.GetNextParagraph() ) ) 98 99 if ( FCKBrowserInfo.IsGecko ) 109 100 { 110 block.removeAttribute( 'align' ) ; 111 112 if ( cssClassName ) 101 var node = range._Range.startContainer ; 102 var aCells = [] ; 103 104 while ( node ) 113 105 { 114 // Remove the any of the alignment classes from the className. 115 var className = block.className.replace( FCKJustifyCommand._GetClassNameRegex(), '' ) ; 116 117 // Append the desired class name. 118 if ( currentState == FCK_TRISTATE_OFF ) 106 if ( node.nodeType == 1 ) 119 107 { 120 if ( className.length > 0 ) 121 className += ' ' ; 122 block.className = className + cssClassName ; 108 if ( node.tagName.IEquals(['tr', 'table']) ) 109 { 110 aCells = FCKTableHandler.GetSelectedCells() ; 111 break ; 112 } 123 113 } 124 else if ( className.length == 0 )125 FCKDomTools.RemoveAttribute( block, 'class' );114 115 node = node.parentNode ; 126 116 } 127 else 128 { 129 var style = block.style ; 130 if ( currentState == FCK_TRISTATE_OFF ) 131 style.textAlign = this.AlignValue ; 132 else 117 118 if ( aCells.length > 1 ) 119 { 120 for ( var i = 0 ; i < aCells.length ; i++ ) 133 121 { 134 style.textAlign = '' ; 135 if ( style.cssText.length == 0 ) 136 block.removeAttribute( 'style' ) ; 122 this._SetAlign( aCells[i], currentState ) ; 137 123 } 124 125 FCK.Focus() ; 126 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 127 128 return ; 138 129 } 139 130 } 140 131 132 // Store a bookmark of the selection since the paragraph iterator might 133 // change the DOM tree and break selections. 134 var bookmark = range.CreateBookmark() ; 135 136 // Apply alignment setting for each paragraph. 137 var iterator = new FCKDomRangeIterator( range ) ; 138 var block ; 139 while ( ( block = iterator.GetNextParagraph() ) ) 140 { 141 this._SetAlign( block, currentState ) ; 142 } 143 141 144 // Restore previous selection. 142 145 range.MoveToBookmark( bookmark ) ; 143 146 range.Select() ; 144 147 145 148 FCK.Focus() ; 146 149 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 147 150 }, 151 152 _SetAlign : function( block, currentState ) 153 { 154 var cssClassName = this._CssClassName ; 155 156 block.removeAttribute( 'align' ) ; 157 158 if ( cssClassName ) 159 { 160 // Remove the any of the alignment classes from the className. 161 var className = block.className.replace( FCKJustifyCommand._GetClassNameRegex(), '' ) ; 162 163 // Append the desired class name. 164 if ( currentState == FCK_TRISTATE_OFF ) 165 { 166 if ( className.length > 0 ) 167 className += ' ' ; 168 block.className = className + cssClassName ; 169 } 170 else if ( className.length == 0 ) 171 FCKDomTools.RemoveAttribute( block, 'class' ) ; 172 } 173 else 174 { 175 var style = block.style ; 176 if ( currentState == FCK_TRISTATE_OFF ) 177 { 178 style.textAlign = this.AlignValue ; 179 } 180 else 181 { 182 style.textAlign = '' ; 183 if ( style.cssText.length == 0 ) 184 block.removeAttribute( 'style' ) ; 185 } 186 } 187 }, 148 188 149 189 GetState : function() 150 190 {