2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* FCKStyleDef Class: represents a single stylke definition. (IE specific)
24
FCKStyleDef.prototype.ApplyToSelection = function()
26
var oSelection = FCK.ToolbarSet.CurrentInstance.EditorDocument.selection ;
28
if ( oSelection.type == 'Text' )
30
var oRange = oSelection.createRange() ;
32
// Create the main element.
33
var e = document.createElement( this.Element ) ;
34
e.innerHTML = oRange.htmlText ;
36
// Set the attributes.
37
this._AddAttributes( e ) ;
39
// Remove the duplicated elements.
40
this._RemoveDuplicates( e ) ;
42
// Replace the selection with the resulting HTML.
43
oRange.pasteHTML( e.outerHTML ) ;
45
else if ( oSelection.type == 'Control' )
47
var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ;
48
if ( oControl.tagName == this.Element )
49
this._AddAttributes( oControl ) ;
53
FCKStyleDef.prototype._AddAttributes = function( targetElement )
55
for ( var a in this.Attributes )
57
switch ( a.toLowerCase() )
60
targetElement.style.cssText = this.Attributes[a] ;
64
targetElement.setAttribute( 'className', this.Attributes[a], 0 ) ;
68
targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ;
70
targetElement.setAttribute( a, this.Attributes[a], 0 ) ;
75
FCKStyleDef.prototype._RemoveDuplicates = function( parent )
77
for ( var i = 0 ; i < parent.children.length ; i++ )
79
var oChild = parent.children[i] ;
80
this._RemoveDuplicates( oChild ) ;
82
if ( this.IsEqual( oChild ) )
83
FCKTools.RemoveOuterTags( oChild ) ;
87
FCKStyleDef.prototype.IsEqual = function( e )
89
if ( e.tagName != this.Element )
92
for ( var a in this.Attributes )
94
switch ( a.toLowerCase() )
97
if ( e.style.cssText.toLowerCase() != this.Attributes[a].toLowerCase() )
101
if ( e.getAttribute( 'className', 0 ) != this.Attributes[a] )
105
if ( e.getAttribute( a, 0 ) != this.Attributes[a] )
113
FCKStyleDef.prototype._RemoveMe = function( elementToCheck )
115
if ( ! elementToCheck )
118
var oParent = elementToCheck.parentElement ;
120
if ( this.IsEqual( elementToCheck ) )
122
if ( this.IsObjectElement )
124
for ( var a in this.Attributes )
126
switch ( a.toLowerCase() )
129
elementToCheck.removeAttribute( 'className', 0 ) ;
132
elementToCheck.removeAttribute( a, 0 ) ;
138
FCKTools.RemoveOuterTags( elementToCheck ) ;
141
this._RemoveMe( oParent ) ;
b'\\ No newline at end of file'