[389] | 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_gecko.js |
---|
| 14 | * FCKStyleDef Class: represents a single stylke definition. (Gecko specific) |
---|
| 15 | * |
---|
| 16 | * File Authors: |
---|
| 17 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | FCKStyleDef.prototype.ApplyToSelection = function() |
---|
| 21 | { |
---|
| 22 | if ( FCKSelection.GetType() == 'Text' && !this.IsObjectElement ) |
---|
| 23 | { |
---|
| 24 | var oSelection = FCK.ToolbarSet.CurrentInstance.EditorWindow.getSelection() ; |
---|
| 25 | |
---|
| 26 | // Create the main element. |
---|
| 27 | var e = FCK.ToolbarSet.CurrentInstance.EditorDocument.createElement( this.Element ) ; |
---|
| 28 | |
---|
| 29 | for ( var i = 0 ; i < oSelection.rangeCount ; i++ ) |
---|
| 30 | { |
---|
| 31 | e.appendChild( oSelection.getRangeAt(i).extractContents() ) ; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | // Set the attributes. |
---|
| 35 | this._AddAttributes( e ) ; |
---|
| 36 | |
---|
| 37 | // Remove the duplicated elements. |
---|
| 38 | this._RemoveDuplicates( e ) ; |
---|
| 39 | |
---|
| 40 | var oRange = oSelection.getRangeAt(0) ; |
---|
| 41 | oRange.insertNode( e ) ; |
---|
| 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ; |
---|
| 46 | if ( oControl.tagName == this.Element ) |
---|
| 47 | this._AddAttributes( oControl ) ; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | FCKStyleDef.prototype._AddAttributes = function( targetElement ) |
---|
| 52 | { |
---|
| 53 | for ( var a in this.Attributes ) |
---|
| 54 | { |
---|
| 55 | switch ( a.toLowerCase() ) |
---|
| 56 | { |
---|
| 57 | case 'src' : |
---|
| 58 | targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ; |
---|
| 59 | |
---|
| 60 | default : |
---|
| 61 | targetElement.setAttribute( a, this.Attributes[a], 0 ) ; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | FCKStyleDef.prototype._RemoveDuplicates = function( parent ) |
---|
| 67 | { |
---|
| 68 | for ( var i = 0 ; i < parent.childNodes.length ; i++ ) |
---|
| 69 | { |
---|
| 70 | var oChild = parent.childNodes[i] ; |
---|
| 71 | |
---|
| 72 | if ( oChild.nodeType != 1 ) |
---|
| 73 | continue ; |
---|
| 74 | |
---|
| 75 | this._RemoveDuplicates( oChild ) ; |
---|
| 76 | |
---|
| 77 | if ( this.IsEqual( oChild ) ) |
---|
| 78 | FCKTools.RemoveOuterTags( oChild ) ; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | FCKStyleDef.prototype.IsEqual = function( e ) |
---|
| 83 | { |
---|
| 84 | if ( e.tagName != this.Element ) |
---|
| 85 | return false ; |
---|
| 86 | |
---|
| 87 | for ( var a in this.Attributes ) |
---|
| 88 | { |
---|
| 89 | if ( e.getAttribute( a ) != this.Attributes[a] ) |
---|
| 90 | return false ; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return true ; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | FCKStyleDef.prototype._RemoveMe = function( elementToCheck ) |
---|
| 97 | { |
---|
| 98 | if ( ! elementToCheck ) |
---|
| 99 | return ; |
---|
| 100 | |
---|
| 101 | var oParent = elementToCheck.parentNode ; |
---|
| 102 | |
---|
| 103 | if ( elementToCheck.nodeType == 1 && this.IsEqual( elementToCheck ) ) |
---|
| 104 | { |
---|
| 105 | if ( this.IsObjectElement ) |
---|
| 106 | { |
---|
| 107 | for ( var a in this.Attributes ) |
---|
| 108 | elementToCheck.removeAttribute( a, 0 ) ; |
---|
| 109 | return ; |
---|
| 110 | } |
---|
| 111 | else |
---|
| 112 | FCKTools.RemoveOuterTags( elementToCheck ) ; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | this._RemoveMe( oParent ) ; |
---|
| 116 | } |
---|