[ 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.js 22 * Utility functions. 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 // Constant for the Gecko Bogus Node. 29 //var GECKO_BOGUS = '<br _moz_editor_bogus_node="TRUE">' ; 30 var GECKO_BOGUS = '<br type="_moz">' ; 31 32 var FCKTools = new Object() ; 33 34 FCKTools.CreateBogusBR = function( targetDocument ) 35 { 36 var eBR = targetDocument.createElement( 'br' ) ; 37 // eBR.setAttribute( '_moz_editor_bogus_node', 'TRUE' ) ; 38 eBR.setAttribute( 'type', '_moz' ) ; 39 return eBR ; 40 } 41 42 // Returns a reference to the appended style sheet or an array with all the appended references 43 FCKTools.AppendStyleSheet = function( documentElement, cssFileUrlOrArray ) 44 { 45 if ( typeof( cssFileUrlOrArray ) == 'string' ) 46 return this._AppendStyleSheet( documentElement, cssFileUrlOrArray ) ; 47 else 48 { 49 var aStyleSheeArray = new Array() ; 50 51 for ( var i = 0 ; i < cssFileUrlOrArray.length ; i++ ) 52 aStyleSheeArray.push(this._AppendStyleSheet( documentElement, cssFileUrlOrArray[i] ) ) ; 53 54 return aStyleSheeArray ; 55 } 56 } 57 58 FCKTools.GetElementDocument = function ( element ) 59 { 60 return element.ownerDocument || element.document ; 61 } 62 63 // Get the window object where the element is placed in. 64 FCKTools.GetElementWindow = function( element ) 65 { 66 return this.GetDocumentWindow( this.GetElementDocument( element ) ) ; 67 } 68 69 FCKTools.GetDocumentWindow = function( document ) 70 { 71 // With Safari, there is not way to retrieve the window from the document, so we must fix it. 72 if ( FCKBrowserInfo.IsSafari && !document.parentWindow ) 73 this.FixDocumentParentWindow( window.top ) ; 74 75 return document.parentWindow || document.defaultView ; 76 } 77 78 /* 79 This is a Safari specific function that fix the reference to the parent 80 window from the document object. 81 */ 82 FCKTools.FixDocumentParentWindow = function( targetWindow ) 83 { 84 targetWindow.document.parentWindow = targetWindow ; 85 86 for ( var i = 0 ; i < targetWindow.frames.length ; i++ ) 87 FCKTools.FixDocumentParentWindow( targetWindow.frames[i] ) ; 88 } 89 90 FCKTools.HTMLEncode = function( text ) 91 { 92 if ( !text ) 93 return '' ; 94 95 text = text.replace( /&/g, '&' ) ; 96 text = text.replace( /</g, '<' ) ; 97 text = text.replace( />/g, '>' ) ; 98 99 return text ; 100 } 101 102 /** 103 * Adds an option to a SELECT element. 104 */ 105 FCKTools.AddSelectOption = function( selectElement, optionText, optionValue ) 106 { 107 var oOption = FCKTools.GetElementDocument( selectElement ).createElement( "OPTION" ) ; 108 109 oOption.text = optionText ; 110 oOption.value = optionValue ; 111 112 selectElement.options.add(oOption) ; 113 114 return oOption ; 115 } 116 117 FCKTools.RunFunction = function( func, thisObject, paramsArray, timerWindow ) 118 { 119 if ( func ) 120 this.SetTimeout( func, 0, thisObject, paramsArray, timerWindow ) ; 121 } 122 123 FCKTools.SetTimeout = function( func, milliseconds, thisObject, paramsArray, timerWindow ) 124 { 125 return ( timerWindow || window ).setTimeout( 126 function() 127 { 128 if ( paramsArray ) 129 func.apply( thisObject, [].concat( paramsArray ) ) ; 130 else 131 func.apply( thisObject ) ; 132 }, 133 milliseconds ) ; 134 } 135 136 FCKTools.SetInterval = function( func, milliseconds, thisObject, paramsArray, timerWindow ) 137 { 138 return ( timerWindow || window ).setInterval( 139 function() 140 { 141 func.apply( thisObject, paramsArray || [] ) ; 142 }, 143 milliseconds ) ; 144 } 145 146 FCKTools.ConvertStyleSizeToHtml = function( size ) 147 { 148 return size.EndsWith( '%' ) ? size : parseInt( size, 10 ) ; 149 } 150 151 FCKTools.ConvertHtmlSizeToStyle = function( size ) 152 { 153 return size.EndsWith( '%' ) ? size : ( size + 'px' ) ; 154 } 155 156 // START iCM MODIFICATIONS 157 // Amended to accept a list of one or more ascensor tag names 158 // Amended to check the element itself before working back up through the parent hierarchy 159 FCKTools.GetElementAscensor = function( element, ascensorTagNames ) 160 { 161 // var e = element.parentNode ; 162 var e = element ; 163 var lstTags = "," + ascensorTagNames.toUpperCase() + "," ; 164 165 while ( e ) 166 { 167 if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 ) 168 return e ; 169 170 e = e.parentNode ; 171 } 172 return null ; 173 } 174 // END iCM MODIFICATIONS 175 176 FCKTools.CreateEventListener = function( func, params ) 177 { 178 var f = function() 179 { 180 var aAllParams = [] ; 181 182 for ( var i = 0 ; i < arguments.length ; i++ ) 183 aAllParams.push( arguments[i] ) ; 184 185 func.apply( this, aAllParams.concat( params ) ) ; 186 } 187 188 return f ; 189 } 190 191 FCKTools.IsStrictMode = function( document ) 192 { 193 // There is no compatMode in Safari, but it seams that it always behave as 194 // CSS1Compat, so let's assume it as the default. 195 return ( 'CSS1Compat' == ( document.compatMode || 'CSS1Compat' ) ) ; 196 } 197 198 // Transforms a "arguments" object to an array. 199 FCKTools.ArgumentsToArray = function( args, startIndex, maxLength ) 200 { 201 startIndex = startIndex || 0 ; 202 maxLength = maxLength || args.length ; 203 204 var argsArray = new Array() ; 205 206 for ( var i = startIndex ; i < startIndex + maxLength && i < args.length ; i++ ) 207 argsArray.push( args[i] ) ; 208 209 return argsArray ; 210 } 211 212 FCKTools.CloneObject = function( sourceObject ) 213 { 214 var fCloneCreator = function() {} ; 215 fCloneCreator.prototype = sourceObject ; 216 return new fCloneCreator ; 217 }
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 |