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