| | 30 | |
| | 31 | FCKIndentCommand._InitIndentModeParameters = function() |
| | 32 | { |
| | 33 | if ( FCKConfig.IndentClasses && FCKConfig.IndentClasses.length > 0 ) |
| | 34 | { |
| | 35 | this._UseIndentClasses = true ; |
| | 36 | this._IndentClassMap = {} ; |
| | 37 | for ( var i = 0 ; i < FCKConfig.IndentClasses.length ;i++ ) |
| | 38 | this._IndentClassMap[FCKConfig.IndentClasses[i]] = i + 1 ; |
| | 39 | this._ClassNameRegex = new RegExp( '(?:^|\\s+)(' + FCKConfig.IndentClasses.join( '|' ) + ')(?=$|\\s)' ) ; |
| | 40 | } |
| | 41 | else |
| | 42 | this._UseIndentClasses = false ; |
| | 43 | } |
| | 44 | |
| 58 | | // TODO: If we're not in a list, and the starting block's indentation is zero, and the current |
| | 73 | // Disabled if not WYSIWYG. |
| | 74 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG || ! FCK.EditorWindow ) |
| | 75 | return FCK_TRISTATE_DISABLED ; |
| | 76 | |
| | 77 | // Initialize parameters if not already initialzed. |
| | 78 | if ( FCKIndentCommand._UseIndentClasses == undefined ) |
| | 79 | FCKIndentCommand._InitIndentModeParameters() ; |
| | 80 | |
| | 81 | // If we're not in a list, and the starting block's indentation is zero, and the current |
| 60 | | return FCK_TRISTATE_OFF; |
| | 83 | var startContainer = FCKSelection.GetBoundaryParentElement( true ) ; |
| | 84 | var endContainer = FCKSelection.GetBoundaryParentElement( false ) ; |
| | 85 | var listNode = FCKDomTools.GetCommonParentNode( startContainer, endContainer, ['ul','ol'] ) ; |
| | 86 | |
| | 87 | if ( ( ! FCKIndentCommand._UseIndentClasses && this.Name.IEquals( 'indent' ) ) || listNode ) |
| | 88 | return FCK_TRISTATE_OFF; |
| | 89 | |
| | 90 | var path = new FCKElementPath( startContainer ) ; |
| | 91 | if ( FCKIndentCommand._UseIndentClasses ) |
| | 92 | { |
| | 93 | var indentClass = path.Block.className.match( FCKIndentCommand._ClassNameRegex ) ; |
| | 94 | var indentStep = 0 ; |
| | 95 | if ( indentClass != null ) |
| | 96 | { |
| | 97 | indentClass = indentClass[1] ; |
| | 98 | indentStep = FCKIndentCommand._IndentClassMap[indentClass] ; |
| | 99 | } |
| | 100 | if ( ( this.Name == 'outdent' && indentStep == 0 ) || |
| | 101 | ( this.Name == 'indent' && indentStep == FCKConfig.IndentClasses.length ) ) |
| | 102 | return FCK_TRISTATE_DISABLED ; |
| | 103 | return FCK_TRISTATE_OFF ; |
| | 104 | } |
| | 105 | else |
| | 106 | { |
| | 107 | var indent = parseInt( path.Block.style[this.IndentCSSProperty], 10 ) ; |
| | 108 | if ( isNaN( indent ) ) |
| | 109 | indent = 0 ; |
| | 110 | if ( indent <= 0 ) |
| | 111 | return FCK_TRISTATE_DISABLED ; |
| | 112 | return FCK_TRISTATE_OFF ; |
| | 113 | } |
| 78 | | // Offset distance is assumed to be in pixels for now. |
| 79 | | var currentOffset = parseInt( block.style[this.IndentCSSProperty], 10 ) ; |
| 80 | | if ( isNaN( currentOffset ) ) |
| 81 | | currentOffset = 0 ; |
| 82 | | currentOffset += this.Offset ; |
| 83 | | currentOffset = Math.max( currentOffset, 0 ) ; |
| 84 | | block.style[this.IndentCSSProperty] = currentOffset + 'px' ; |
| | 131 | if ( FCKIndentCommand._UseIndentClasses ) |
| | 132 | { |
| | 133 | // Transform current class name to indent step index. |
| | 134 | var indentClass = block.className.match( FCKIndentCommand._ClassNameRegex ) ; |
| | 135 | var indentStep = 0 ; |
| | 136 | if ( indentClass != null ) |
| | 137 | { |
| | 138 | indentClass = indentClass[1] ; |
| | 139 | indentStep = FCKIndentCommand._IndentClassMap[indentClass] ; |
| | 140 | } |
| | 141 | |
| | 142 | // Operate on indent step index, transform indent step index back to class name. |
| | 143 | if ( this.Name.IEquals( 'outdent' ) ) |
| | 144 | indentStep-- ; |
| | 145 | else if ( this.Name.IEquals( 'indent' ) ) |
| | 146 | indentStep++ ; |
| | 147 | indentStep = Math.min( indentStep, FCKConfig.IndentClasses.length ) ; |
| | 148 | indentStep = Math.max( indentStep, 0 ) ; |
| | 149 | var className = block.className.replace( FCKIndentCommand._ClassNameRegex, '' ) ; |
| | 150 | if ( indentStep < 1 ) |
| | 151 | block.className = className ; |
| | 152 | else |
| | 153 | block.className = ( className.length > 0 ? className + ' ' : '' ) + |
| | 154 | FCKConfig.IndentClasses[indentStep - 1] ; |
| | 155 | } |
| | 156 | else |
| | 157 | { |
| | 158 | // Offset distance is assumed to be in pixels for now. |
| | 159 | var currentOffset = parseInt( block.style[this.IndentCSSProperty], 10 ) ; |
| | 160 | if ( isNaN( currentOffset ) ) |
| | 161 | currentOffset = 0 ; |
| | 162 | currentOffset += this.Offset ; |
| | 163 | currentOffset = Math.max( currentOffset, 0 ) ; |
| | 164 | block.style[this.IndentCSSProperty] = currentOffset + 'px' ; |
| | 165 | } |
| 92 | | // TODO |
| | 173 | var startContainer = range.StartContainer ; |
| | 174 | var endContainer = range.EndContainer ; |
| | 175 | while ( startContainer && ! startContainer.nodeName.IEquals( ['li', 'ul', 'ol'] ) ) |
| | 176 | startContainer = startContainer.parentNode ; |
| | 177 | while ( endContainer && ! endContainer.nodeName.IEquals( ['li', 'ul', 'ol'] ) ) |
| | 178 | endContainer = endContainer.parentNode ; |
| | 179 | range.SetStart( startContainer, 1 ) ; |
| | 180 | range.SetEnd( endContainer, 2 ) ; |
| | 181 | |
| | 182 | if ( ! startContainer || ! endContainer ) |
| | 183 | return ; |
| | 184 | |
| | 185 | // Now we can iterate over the individual items. |