[ Index ] |
|
Code source de FCKeditor 2.4 |
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 * File Name: fcktools_gecko.js 22 * Utility functions. (Gecko version). 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 FCKTools.CancelEvent = function( e ) 29 { 30 if ( e ) 31 e.preventDefault() ; 32 } 33 34 FCKTools.DisableSelection = function( element ) 35 { 36 if ( FCKBrowserInfo.IsGecko ) 37 element.style.MozUserSelect = 'none' ; // Gecko only. 38 else 39 element.style.userSelect = 'none' ; // CSS3 (not supported yet). 40 } 41 42 // Appends a CSS file to a document. 43 FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl ) 44 { 45 var e = documentElement.createElement( 'LINK' ) ; 46 e.rel = 'stylesheet' ; 47 e.type = 'text/css' ; 48 e.href = cssFileUrl ; 49 documentElement.getElementsByTagName("HEAD")[0].appendChild( e ) ; 50 return e ; 51 } 52 53 // Removes all attributes and values from the element. 54 FCKTools.ClearElementAttributes = function( element ) 55 { 56 // Loop throw all attributes in the element 57 for ( var i = 0 ; i < element.attributes.length ; i++ ) 58 { 59 // Remove the element by name. 60 element.removeAttribute( element.attributes[i].name, 0 ) ; // 0 : Case Insensitive 61 } 62 } 63 64 // Returns an Array of strings with all defined in the elements inside another element. 65 FCKTools.GetAllChildrenIds = function( parentElement ) 66 { 67 // Create the array that will hold all Ids. 68 var aIds = new Array() ; 69 70 // Define a recursive function that search for the Ids. 71 var fGetIds = function( parent ) 72 { 73 for ( var i = 0 ; i < parent.childNodes.length ; i++ ) 74 { 75 var sId = parent.childNodes[i].id ; 76 77 // Check if the Id is defined for the element. 78 if ( sId && sId.length > 0 ) aIds[ aIds.length ] = sId ; 79 80 // Recursive call. 81 fGetIds( parent.childNodes[i] ) ; 82 } 83 } 84 85 // Start the recursive calls. 86 fGetIds( parentElement ) ; 87 88 return aIds ; 89 } 90 91 // Replaces a tag with its contents. For example "<span>My <b>tag</b></span>" 92 // will be replaced with "My <b>tag</b>". 93 FCKTools.RemoveOuterTags = function( e ) 94 { 95 var oFragment = e.ownerDocument.createDocumentFragment() ; 96 97 for ( var i = 0 ; i < e.childNodes.length ; i++ ) 98 oFragment.appendChild( e.childNodes[i].cloneNode(true) ) ; 99 100 e.parentNode.replaceChild( oFragment, e ) ; 101 } 102 103 FCKTools.CreateXmlObject = function( object ) 104 { 105 switch ( object ) 106 { 107 case 'XmlHttp' : 108 return new XMLHttpRequest() ; 109 case 'DOMDocument' : 110 return document.implementation.createDocument( '', '', null ) ; 111 } 112 return null ; 113 } 114 115 FCKTools.GetScrollPosition = function( relativeWindow ) 116 { 117 return { X : relativeWindow.pageXOffset, Y : relativeWindow.pageYOffset } ; 118 } 119 120 FCKTools.AddEventListener = function( sourceObject, eventName, listener ) 121 { 122 sourceObject.addEventListener( eventName, listener, false ) ; 123 } 124 125 FCKTools.RemoveEventListener = function( sourceObject, eventName, listener ) 126 { 127 sourceObject.removeEventListener( eventName, listener, false ) ; 128 } 129 130 // Listeners attached with this function cannot be detached. 131 FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray ) 132 { 133 sourceObject.addEventListener( 134 eventName, 135 function( e ) 136 { 137 listener.apply( sourceObject, [ e ].concat( paramsArray || [] ) ) ; 138 }, 139 false 140 ) ; 141 } 142 143 // Returns and object with the "Width" and "Height" properties. 144 FCKTools.GetViewPaneSize = function( win ) 145 { 146 return { Width : win.innerWidth, Height : win.innerHeight } ; 147 } 148 149 FCKTools.SaveStyles = function( element ) 150 { 151 var oSavedStyles = new Object() ; 152 153 if ( element.className.length > 0 ) 154 { 155 oSavedStyles.Class = element.className ; 156 element.className = '' ; 157 } 158 159 var sInlineStyle = element.getAttribute( 'style' ) ; 160 161 if ( sInlineStyle && sInlineStyle.length > 0 ) 162 { 163 oSavedStyles.Inline = sInlineStyle ; 164 element.setAttribute( 'style', '', 0 ) ; // 0 : Case Insensitive 165 } 166 167 return oSavedStyles ; 168 } 169 170 FCKTools.RestoreStyles = function( element, savedStyles ) 171 { 172 element.className = savedStyles.Class || '' ; 173 174 if ( savedStyles.Inline ) 175 element.setAttribute( 'style', savedStyles.Inline, 0 ) ; // 0 : Case Insensitive 176 else 177 element.removeAttribute( 'style', 0 ) ; 178 } 179 180 FCKTools.RegisterDollarFunction = function( targetWindow ) 181 { 182 targetWindow.$ = function( id ) 183 { 184 return this.document.getElementById( id ) ; 185 } ; 186 } 187 188 FCKTools.AppendElement = function( target, elementName ) 189 { 190 return target.appendChild( target.ownerDocument.createElement( elementName ) ) ; 191 } 192 193 // Get the coordinates of an element. 194 // @el : The element to get the position. 195 // @relativeWindow: The window to which we want the coordinates relative to. 196 FCKTools.GetElementPosition = function( el, relativeWindow ) 197 { 198 // Initializes the Coordinates object that will be returned by the function. 199 var c = { X:0, Y:0 } ; 200 201 var oWindow = relativeWindow || window ; 202 203 var oOwnerWindow = FCKTools.GetElementWindow( el ) ; 204 205 // Loop throw the offset chain. 206 while ( el ) 207 { 208 var sPosition = oOwnerWindow.getComputedStyle(el, '').position ; 209 210 // Check for non "static" elements. 211 // 'FCKConfig.FloatingPanelsZIndex' -- Submenus are under a positioned IFRAME. 212 if ( sPosition && sPosition != 'static' && el.style.zIndex != FCKConfig.FloatingPanelsZIndex ) 213 break ; 214 215 c.X += el.offsetLeft - el.scrollLeft ; 216 c.Y += el.offsetTop - el.scrollTop ; 217 218 if ( el.offsetParent ) 219 el = el.offsetParent ; 220 else 221 { 222 if ( oOwnerWindow != oWindow ) 223 { 224 el = oOwnerWindow.frameElement ; 225 if ( el ) 226 oOwnerWindow = FCKTools.GetElementWindow( el ) ; 227 } 228 else 229 { 230 c.X += el.scrollLeft ; 231 c.Y += el.scrollTop ; 232 break ; 233 } 234 } 235 } 236 237 // Return the Coordinates object 238 return c ; 239 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |