1 | /* |
---|
2 | * FCKeditor - The text editor for internet |
---|
3 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
4 | * |
---|
5 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
6 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
7 | * |
---|
8 | * For further information visit: |
---|
9 | * http://www.fckeditor.net/ |
---|
10 | * |
---|
11 | * "Support Open Source software. What about a donation today?" |
---|
12 | * |
---|
13 | * File Name: fckstylecommand.js |
---|
14 | * FCKStyleCommand Class: represents the "Style" command. |
---|
15 | * |
---|
16 | * File Authors: |
---|
17 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
18 | */ |
---|
19 | |
---|
20 | var FCKStyleCommand = function() |
---|
21 | { |
---|
22 | this.Name = 'Style' ; |
---|
23 | |
---|
24 | // Load the Styles defined in the XML file. |
---|
25 | this.StylesLoader = new FCKStylesLoader() ; |
---|
26 | this.StylesLoader.Load( FCKConfig.StylesXmlPath ) ; |
---|
27 | this.Styles = this.StylesLoader.Styles ; |
---|
28 | } |
---|
29 | |
---|
30 | FCKStyleCommand.prototype.Execute = function( styleName, styleComboItem ) |
---|
31 | { |
---|
32 | FCKUndo.SaveUndoStep() ; |
---|
33 | |
---|
34 | if ( styleComboItem.Selected ) |
---|
35 | styleComboItem.Style.RemoveFromSelection() ; |
---|
36 | else |
---|
37 | styleComboItem.Style.ApplyToSelection() ; |
---|
38 | |
---|
39 | FCKUndo.SaveUndoStep() ; |
---|
40 | |
---|
41 | FCK.Focus() ; |
---|
42 | |
---|
43 | FCK.Events.FireEvent( "OnSelectionChange" ) ; |
---|
44 | } |
---|
45 | |
---|
46 | FCKStyleCommand.prototype.GetState = function() |
---|
47 | { |
---|
48 | if ( !FCK.EditorDocument ) |
---|
49 | return FCK_TRISTATE_DISABLED ; |
---|
50 | |
---|
51 | var oSelection = FCK.EditorDocument.selection ; |
---|
52 | |
---|
53 | if ( FCKSelection.GetType() == 'Control' ) |
---|
54 | { |
---|
55 | var e = FCKSelection.GetSelectedElement() ; |
---|
56 | if ( e ) |
---|
57 | return this.StylesLoader.StyleGroups[ e.tagName ] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ; |
---|
58 | } |
---|
59 | |
---|
60 | return FCK_TRISTATE_OFF ; |
---|
61 | } |
---|
62 | |
---|
63 | FCKStyleCommand.prototype.GetActiveStyles = function() |
---|
64 | { |
---|
65 | var aActiveStyles = new Array() ; |
---|
66 | |
---|
67 | if ( FCKSelection.GetType() == 'Control' ) |
---|
68 | this._CheckStyle( FCKSelection.GetSelectedElement(), aActiveStyles, false ) ; |
---|
69 | else |
---|
70 | this._CheckStyle( FCKSelection.GetParentElement(), aActiveStyles, true ) ; |
---|
71 | |
---|
72 | return aActiveStyles ; |
---|
73 | } |
---|
74 | |
---|
75 | FCKStyleCommand.prototype._CheckStyle = function( element, targetArray, checkParent ) |
---|
76 | { |
---|
77 | if ( ! element ) |
---|
78 | return ; |
---|
79 | |
---|
80 | if ( element.nodeType == 1 ) |
---|
81 | { |
---|
82 | var aStyleGroup = this.StylesLoader.StyleGroups[ element.tagName ] ; |
---|
83 | if ( aStyleGroup ) |
---|
84 | { |
---|
85 | for ( var i = 0 ; i < aStyleGroup.length ; i++ ) |
---|
86 | { |
---|
87 | if ( aStyleGroup[i].IsEqual( element ) ) |
---|
88 | targetArray[ targetArray.length ] = aStyleGroup[i] ; |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if ( checkParent ) |
---|
94 | this._CheckStyle( element.parentNode, targetArray, checkParent ) ; |
---|
95 | } |
---|