[44] | 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: fckstyledef_ie.js
|
---|
| 14 | * FCKStyleDef Class: represents a single stylke definition. (IE specific)
|
---|
| 15 | *
|
---|
| 16 | * File Authors:
|
---|
| 17 | * Frederico Caldeira Knabben (fredck@fckeditor.net)
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | FCKStyleDef.prototype.ApplyToSelection = function()
|
---|
| 21 | {
|
---|
| 22 | var oSelection = FCK.ToolbarSet.CurrentInstance.EditorDocument.selection ;
|
---|
| 23 |
|
---|
| 24 | if ( oSelection.type == 'Text' )
|
---|
| 25 | {
|
---|
| 26 | var oRange = oSelection.createRange() ;
|
---|
| 27 |
|
---|
| 28 | // Create the main element.
|
---|
| 29 | var e = document.createElement( this.Element ) ;
|
---|
| 30 | e.innerHTML = oRange.htmlText ;
|
---|
| 31 |
|
---|
| 32 | // Set the attributes.
|
---|
| 33 | this._AddAttributes( e ) ;
|
---|
| 34 |
|
---|
| 35 | // Remove the duplicated elements.
|
---|
| 36 | this._RemoveDuplicates( e ) ;
|
---|
| 37 |
|
---|
| 38 | // Replace the selection with the resulting HTML.
|
---|
| 39 | oRange.pasteHTML( e.outerHTML ) ;
|
---|
| 40 | }
|
---|
| 41 | else if ( oSelection.type == 'Control' )
|
---|
| 42 | {
|
---|
| 43 | var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ;
|
---|
| 44 | if ( oControl.tagName == this.Element )
|
---|
| 45 | this._AddAttributes( oControl ) ;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | FCKStyleDef.prototype._AddAttributes = function( targetElement )
|
---|
| 50 | {
|
---|
| 51 | for ( var a in this.Attributes )
|
---|
| 52 | {
|
---|
| 53 | switch ( a.toLowerCase() )
|
---|
| 54 | {
|
---|
| 55 | case 'style' :
|
---|
| 56 | targetElement.style.cssText = this.Attributes[a] ;
|
---|
| 57 | break ;
|
---|
| 58 |
|
---|
| 59 | case 'class' :
|
---|
| 60 | targetElement.setAttribute( 'className', this.Attributes[a], 0 ) ;
|
---|
| 61 | break ;
|
---|
| 62 |
|
---|
| 63 | case 'src' :
|
---|
| 64 | targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ;
|
---|
| 65 |
|
---|
| 66 | default :
|
---|
| 67 | targetElement.setAttribute( a, this.Attributes[a], 0 ) ;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | FCKStyleDef.prototype._RemoveDuplicates = function( parent )
|
---|
| 73 | {
|
---|
| 74 | for ( var i = 0 ; i < parent.children.length ; i++ )
|
---|
| 75 | {
|
---|
| 76 | var oChild = parent.children[i] ;
|
---|
| 77 | this._RemoveDuplicates( oChild ) ;
|
---|
| 78 |
|
---|
| 79 | if ( this.IsEqual( oChild ) )
|
---|
| 80 | FCKTools.RemoveOuterTags( oChild ) ;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | FCKStyleDef.prototype.IsEqual = function( e )
|
---|
| 85 | {
|
---|
| 86 | if ( e.tagName != this.Element )
|
---|
| 87 | return false ;
|
---|
| 88 |
|
---|
| 89 | for ( var a in this.Attributes )
|
---|
| 90 | {
|
---|
| 91 | switch ( a.toLowerCase() )
|
---|
| 92 | {
|
---|
| 93 | case 'style' :
|
---|
| 94 | if ( e.style.cssText.toLowerCase() != this.Attributes[a].toLowerCase() )
|
---|
| 95 | return false ;
|
---|
| 96 | break ;
|
---|
| 97 | case 'class' :
|
---|
| 98 | if ( e.getAttribute( 'className', 0 ) != this.Attributes[a] )
|
---|
| 99 | return false ;
|
---|
| 100 | break ;
|
---|
| 101 | default :
|
---|
| 102 | if ( e.getAttribute( a, 0 ) != this.Attributes[a] )
|
---|
| 103 | return false ;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | return true ;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | FCKStyleDef.prototype._RemoveMe = function( elementToCheck )
|
---|
| 111 | {
|
---|
| 112 | if ( ! elementToCheck )
|
---|
| 113 | return ;
|
---|
| 114 |
|
---|
| 115 | var oParent = elementToCheck.parentElement ;
|
---|
| 116 |
|
---|
| 117 | if ( this.IsEqual( elementToCheck ) )
|
---|
| 118 | {
|
---|
| 119 | if ( this.IsObjectElement )
|
---|
| 120 | {
|
---|
| 121 | for ( var a in this.Attributes )
|
---|
| 122 | {
|
---|
| 123 | switch ( a.toLowerCase() )
|
---|
| 124 | {
|
---|
| 125 | case 'class' :
|
---|
| 126 | elementToCheck.removeAttribute( 'className', 0 ) ;
|
---|
| 127 | break ;
|
---|
| 128 | default :
|
---|
| 129 | elementToCheck.removeAttribute( a, 0 ) ;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | return ;
|
---|
| 133 | }
|
---|
| 134 | else
|
---|
| 135 | FCKTools.RemoveOuterTags( elementToCheck ) ;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | this._RemoveMe( oParent ) ;
|
---|
| 139 | } |
---|