Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 ddelon 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2005 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
 * File Name: fckstylecommand.js
12
 * 	FCKStyleCommand Class: represents the "Style" command.
13
 *
14
 * File Authors:
15
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
16
 */
17
 
18
var FCKStyleCommand = function()
19
{
20
	this.Name = 'Style' ;
21
 
22
	// Load the Styles defined in the XML file.
23
	this.StylesLoader = new FCKStylesLoader() ;
24
	this.StylesLoader.Load( FCKConfig.StylesXmlPath ) ;
25
	this.Styles = this.StylesLoader.Styles ;
26
}
27
 
28
FCKStyleCommand.prototype.Execute = function( styleName, styleComboItem )
29
{
30
	if ( styleComboItem.Selected )
31
		styleComboItem.Style.RemoveFromSelection() ;
32
	else
33
		styleComboItem.Style.ApplyToSelection() ;
34
 
35
	FCK.Focus() ;
36
 
37
	FCK.Events.FireEvent( "OnSelectionChange" ) ;
38
}
39
 
40
FCKStyleCommand.prototype.GetState = function()
41
{
42
	var oSelection = FCK.EditorDocument.selection ;
43
 
44
	if ( FCKSelection.GetType() == 'Control' )
45
	{
46
		var e = FCKSelection.GetSelectedElement() ;
47
			if ( e )
48
				return this.StylesLoader.StyleGroups[ e.tagName ] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
49
			else
50
				FCK_TRISTATE_OFF ;
51
	}
52
	else
53
		return FCK_TRISTATE_OFF ;
54
}
55
 
56
FCKStyleCommand.prototype.GetActiveStyles = function()
57
{
58
	var aActiveStyles = new Array() ;
59
 
60
	if ( FCKSelection.GetType() == 'Control' )
61
		this._CheckStyle( FCKSelection.GetSelectedElement(), aActiveStyles, false ) ;
62
	else
63
		this._CheckStyle( FCKSelection.GetParentElement(), aActiveStyles, true ) ;
64
 
65
	return aActiveStyles ;
66
}
67
 
68
FCKStyleCommand.prototype._CheckStyle = function( element, targetArray, checkParent )
69
{
70
	if ( ! element )
71
		return ;
72
 
73
	if ( element.nodeType == 1 )
74
	{
75
		var aStyleGroup = this.StylesLoader.StyleGroups[ element.tagName ] ;
76
		if ( aStyleGroup )
77
		{
78
			for ( var i = 0 ; i < aStyleGroup.length ; i++ )
79
			{
80
				if ( aStyleGroup[i].IsEqual( element ) )
81
					targetArray[ targetArray.length ] = aStyleGroup[i] ;
82
			}
83
		}
84
	}
85
 
86
	if ( checkParent )
87
		this._CheckStyle( element.parentNode, targetArray, checkParent ) ;
88
}