[795] | 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 | * FCKStyleCommand Class: represents the "Style" command. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | var FCKStyleCommand = function() |
---|
| 25 | { |
---|
| 26 | this.Name = 'Style' ; |
---|
| 27 | |
---|
| 28 | // Load the Styles defined in the XML file. |
---|
| 29 | this.StylesLoader = new FCKStylesLoader() ; |
---|
| 30 | this.StylesLoader.Load( FCKConfig.StylesXmlPath ) ; |
---|
| 31 | this.Styles = this.StylesLoader.Styles ; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | FCKStyleCommand.prototype.Execute = function( styleName, styleComboItem ) |
---|
| 35 | { |
---|
| 36 | FCKUndo.SaveUndoStep() ; |
---|
| 37 | |
---|
| 38 | if ( styleComboItem.Selected ) |
---|
| 39 | styleComboItem.Style.RemoveFromSelection() ; |
---|
| 40 | else |
---|
| 41 | styleComboItem.Style.ApplyToSelection() ; |
---|
| 42 | |
---|
| 43 | FCKUndo.SaveUndoStep() ; |
---|
| 44 | |
---|
| 45 | FCK.Focus() ; |
---|
| 46 | |
---|
| 47 | FCK.Events.FireEvent( "OnSelectionChange" ) ; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | FCKStyleCommand.prototype.GetState = function() |
---|
| 51 | { |
---|
| 52 | if ( !FCK.EditorDocument ) |
---|
| 53 | return FCK_TRISTATE_DISABLED ; |
---|
| 54 | |
---|
| 55 | var oSelection = FCK.EditorDocument.selection ; |
---|
| 56 | |
---|
| 57 | if ( FCKSelection.GetType() == 'Control' ) |
---|
| 58 | { |
---|
| 59 | var e = FCKSelection.GetSelectedElement() ; |
---|
| 60 | if ( e ) |
---|
| 61 | return this.StylesLoader.StyleGroups[ e.tagName ] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | return FCK_TRISTATE_OFF ; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | FCKStyleCommand.prototype.GetActiveStyles = function() |
---|
| 68 | { |
---|
| 69 | var aActiveStyles = new Array() ; |
---|
| 70 | |
---|
| 71 | if ( FCKSelection.GetType() == 'Control' ) |
---|
| 72 | this._CheckStyle( FCKSelection.GetSelectedElement(), aActiveStyles, false ) ; |
---|
| 73 | else |
---|
| 74 | this._CheckStyle( FCKSelection.GetParentElement(), aActiveStyles, true ) ; |
---|
| 75 | |
---|
| 76 | return aActiveStyles ; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | FCKStyleCommand.prototype._CheckStyle = function( element, targetArray, checkParent ) |
---|
| 80 | { |
---|
| 81 | if ( ! element ) |
---|
| 82 | return ; |
---|
| 83 | |
---|
| 84 | if ( element.nodeType == 1 ) |
---|
| 85 | { |
---|
| 86 | var aStyleGroup = this.StylesLoader.StyleGroups[ element.tagName ] ; |
---|
| 87 | if ( aStyleGroup ) |
---|
| 88 | { |
---|
| 89 | for ( var i = 0 ; i < aStyleGroup.length ; i++ ) |
---|
| 90 | { |
---|
| 91 | if ( aStyleGroup[i].IsEqual( element ) ) |
---|
| 92 | targetArray[ targetArray.length ] = aStyleGroup[i] ; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if ( checkParent ) |
---|
| 98 | this._CheckStyle( element.parentNode, targetArray, checkParent ) ; |
---|
| 99 | } |
---|