1075 |
ddelon |
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: fckstylesloader.js
|
|
|
14 |
* FCKStylesLoader Class: this class define objects that are responsible
|
|
|
15 |
* for loading the styles defined in the XML file.
|
|
|
16 |
*
|
|
|
17 |
* File Authors:
|
|
|
18 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
var FCKStylesLoader = function()
|
|
|
22 |
{
|
|
|
23 |
this.Styles = new Object() ;
|
|
|
24 |
this.StyleGroups = new Object() ;
|
|
|
25 |
this.Loaded = false ;
|
|
|
26 |
this.HasObjectElements = false ;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
FCKStylesLoader.prototype.Load = function( stylesXmlUrl )
|
|
|
30 |
{
|
|
|
31 |
// Load the XML file into a FCKXml object.
|
|
|
32 |
var oXml = new FCKXml() ;
|
|
|
33 |
oXml.LoadUrl( stylesXmlUrl ) ;
|
|
|
34 |
|
|
|
35 |
// Get the "Style" nodes defined in the XML file.
|
|
|
36 |
var aStyleNodes = oXml.SelectNodes( 'Styles/Style' ) ;
|
|
|
37 |
|
|
|
38 |
// Add each style to our "Styles" collection.
|
|
|
39 |
for ( var i = 0 ; i < aStyleNodes.length ; i++ )
|
|
|
40 |
{
|
|
|
41 |
var sElement = aStyleNodes[i].attributes.getNamedItem('element').value.toUpperCase() ;
|
|
|
42 |
|
|
|
43 |
// Create the style definition object.
|
|
|
44 |
var oStyleDef = new FCKStyleDef( aStyleNodes[i].attributes.getNamedItem('name').value, sElement ) ;
|
|
|
45 |
|
|
|
46 |
if ( oStyleDef.IsObjectElement )
|
|
|
47 |
this.HasObjectElements = true ;
|
|
|
48 |
|
|
|
49 |
// Get the attributes defined for the style (if any).
|
|
|
50 |
var aAttNodes = oXml.SelectNodes( 'Attribute', aStyleNodes[i] ) ;
|
|
|
51 |
|
|
|
52 |
// Add the attributes to the style definition object.
|
|
|
53 |
for ( var j = 0 ; j < aAttNodes.length ; j++ )
|
|
|
54 |
{
|
|
|
55 |
var sAttName = aAttNodes[j].attributes.getNamedItem('name').value ;
|
|
|
56 |
var sAttValue = aAttNodes[j].attributes.getNamedItem('value').value ;
|
|
|
57 |
|
|
|
58 |
// IE changes the "style" attribute value when applied to an element
|
|
|
59 |
// so we must get the final resulting value (for comparision issues).
|
|
|
60 |
if ( sAttName.toLowerCase() == 'style' )
|
|
|
61 |
{
|
|
|
62 |
var oTempE = document.createElement( 'SPAN' ) ;
|
|
|
63 |
oTempE.style.cssText = sAttValue ;
|
|
|
64 |
sAttValue = oTempE.style.cssText ;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
oStyleDef.AddAttribute( sAttName, sAttValue ) ;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Add the style to the "Styles" collection using it's name as the key.
|
|
|
71 |
this.Styles[ oStyleDef.Name ] = oStyleDef ;
|
|
|
72 |
|
|
|
73 |
// Add the style to the "StyleGroups" collection.
|
|
|
74 |
var aGroup = this.StyleGroups[sElement] ;
|
|
|
75 |
if ( aGroup == null )
|
|
|
76 |
{
|
|
|
77 |
this.StyleGroups[sElement] = new Array() ;
|
|
|
78 |
aGroup = this.StyleGroups[sElement] ;
|
|
|
79 |
}
|
|
|
80 |
aGroup[aGroup.length] = oStyleDef ;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
this.Loaded = true ;
|
|
|
84 |
}
|