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 * Utility functions. (IE version). 22 */ 23 24FCKTools.CancelEvent = function( e ) 25{ 26 return false ; 27} 28 29// Appends one or more CSS files to a document. 30FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl ) 31{ 32 return documentElement.createStyleSheet( cssFileUrl ).owningElement ; 33} 34 35// Appends a CSS style string to a document. 36FCKTools._AppendStyleString = function( documentElement, cssStyles ) 37{ 38 var s = documentElement.createStyleSheet( "" ) ; 39 s.cssText = cssStyles ; 40 return s ; 41} 42 43// Removes all attributes and values from the element. 44FCKTools.ClearElementAttributes = function( element ) 45{ 46 element.clearAttributes() ; 47} 48 49FCKTools.GetAllChildrenIds = function( parentElement ) 50{ 51 var aIds = new Array() ; 52 for ( var i = 0 ; i < parentElement.all.length ; i++ ) 53 { 54 var sId = parentElement.all[i].id ; 55 if ( sId && sId.length > 0 ) 56 aIds[ aIds.length ] = sId ; 57 } 58 return aIds ; 59} 60 61FCKTools.RemoveOuterTags = function( e ) 62{ 63 e.insertAdjacentHTML( 'beforeBegin', e.innerHTML ) ; 64 e.parentNode.removeChild( e ) ; 65} 66 67FCKTools.CreateXmlObject = function( object ) 68{ 69 var aObjs ; 70 71 switch ( object ) 72 { 73 case 'XmlHttp' : 74 aObjs = [ 'MSXML2.XmlHttp', 'Microsoft.XmlHttp' ] ; 75 break ; 76 77 case 'DOMDocument' : 78 aObjs = [ 'MSXML2.DOMDocument', 'Microsoft.XmlDom' ] ; 79 break ; 80 } 81 82 for ( var i = 0 ; i < 2 ; i++ ) 83 { 84 try { return new ActiveXObject( aObjs[i] ) ; } 85 catch (e) 86 {} 87 } 88 89 if ( FCKLang.NoActiveX ) 90 { 91 alert( FCKLang.NoActiveX ) ; 92 FCKLang.NoActiveX = null ; 93 } 94 return null ; 95} 96 97FCKTools.DisableSelection = function( element ) 98{ 99 element.unselectable = 'on' ; 100 101 var e, i = 0 ; 102 // The extra () is to avoid a warning with strict error checking. This is ok. 103 while ( (e = element.all[ i++ ]) ) 104 { 105 switch ( e.tagName ) 106 { 107 case 'IFRAME' : 108 case 'TEXTAREA' : 109 case 'INPUT' : 110 case 'SELECT' : 111 /* Ignore the above tags */ 112 break ; 113 default : 114 e.unselectable = 'on' ; 115 } 116 } 117} 118 119FCKTools.GetScrollPosition = function( relativeWindow ) 120{ 121 var oDoc = relativeWindow.document ; 122 123 // Try with the doc element. 124 var oPos = { X : oDoc.documentElement.scrollLeft, Y : oDoc.documentElement.scrollTop } ; 125 126 if ( oPos.X > 0 || oPos.Y > 0 ) 127 return oPos ; 128 129 // If no scroll, try with the body. 130 return { X : oDoc.body.scrollLeft, Y : oDoc.body.scrollTop } ; 131} 132 133FCKTools.AddEventListener = function( sourceObject, eventName, listener ) 134{ 135 sourceObject.attachEvent( 'on' + eventName, listener ) ; 136} 137 138FCKTools.RemoveEventListener = function( sourceObject, eventName, listener ) 139{ 140 sourceObject.detachEvent( 'on' + eventName, listener ) ; 141} 142 143// Listeners attached with this function cannot be detached. 144FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray ) 145{ 146 // Ok... this is a closures party, but is the only way to make it clean of memory leaks. 147 var o = new Object() ; 148 o.Source = sourceObject ; 149 o.Params = paramsArray || [] ; // Memory leak if we have DOM objects here. 150 o.Listener = function( ev ) 151 { 152 return listener.apply( o.Source, [ ev ].concat( o.Params ) ) ; 153 } 154 155 if ( FCK.IECleanup ) 156 FCK.IECleanup.AddItem( null, function() { o.Source = null ; o.Params = null ; } ) ; 157 158 sourceObject.attachEvent( 'on' + eventName, o.Listener ) ; 159 160 sourceObject = null ; // Memory leak cleaner (because of the above closure). 161 paramsArray = null ; // Memory leak cleaner (because of the above closure). 162} 163 164// Returns and object with the "Width" and "Height" properties. 165FCKTools.GetViewPaneSize = function( win ) 166{ 167 var oSizeSource ; 168 169 var oDoc = win.document.documentElement ; 170 if ( oDoc && oDoc.clientWidth ) // IE6 Strict Mode 171 oSizeSource = oDoc ; 172 else 173 oSizeSource = win.document.body ; // Other IEs 174 175 if ( oSizeSource ) 176 return { Width : oSizeSource.clientWidth, Height : oSizeSource.clientHeight } ; 177 else 178 return { Width : 0, Height : 0 } ; 179} 180 181FCKTools.SaveStyles = function( element ) 182{ 183 var data = FCKTools.ProtectFormStyles( element ) ; 184 185 var oSavedStyles = new Object() ; 186 187 if ( element.className.length > 0 ) 188 { 189 oSavedStyles.Class = element.className ; 190 element.className = '' ; 191 } 192 193 var sInlineStyle = element.style.cssText ; 194 195 if ( sInlineStyle.length > 0 ) 196 { 197 oSavedStyles.Inline = sInlineStyle ; 198 element.style.cssText = '' ; 199 } 200 201 FCKTools.RestoreFormStyles( element, data ) ; 202 return oSavedStyles ; 203} 204 205FCKTools.RestoreStyles = function( element, savedStyles ) 206{ 207 var data = FCKTools.ProtectFormStyles( element ) ; 208 element.className = savedStyles.Class || '' ; 209 element.style.cssText = savedStyles.Inline || '' ; 210 FCKTools.RestoreFormStyles( element, data ) ; 211} 212 213FCKTools.RegisterDollarFunction = function( targetWindow ) 214{ 215 targetWindow.$ = targetWindow.document.getElementById ; 216} 217 218FCKTools.AppendElement = function( target, elementName ) 219{ 220 return target.appendChild( this.GetElementDocument( target ).createElement( elementName ) ) ; 221} 222 223// This function may be used by Regex replacements. 224FCKTools.ToLowerCase = function( strValue ) 225{ 226 return strValue.toLowerCase() ; 227} 228