[ Index ] |
|
Code source de GeekLog 1.4.1 |
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: fcktools.js 14 * Utility functions. 15 * 16 * File Authors: 17 * Frederico Caldeira Knabben (fredck@fckeditor.net) 18 */ 19 20 var FCKTools = new Object() ; 21 22 /** 23 * Gets the value of the hidden INPUT element that is associated to the editor. 24 * This element has its ID set to the editor's instance name so the user refers 25 * to the instance name when getting the posted data. 26 */ 27 FCKTools.GetLinkedFieldValue = function() 28 { 29 return FCK.LinkedField.value ; 30 } 31 32 /** 33 * Attachs a function call to the submit event of the linked field form. This 34 * function us generally used to update the linked field value before 35 * submitting the form. 36 */ 37 FCKTools.AttachToLinkedFieldFormSubmit = function( functionPointer ) 38 { 39 // Gets the linked field form 40 var oForm = FCK.LinkedField.form ; 41 42 // Return now if no form is available 43 if (!oForm) return ; 44 45 // Attaches the functionPointer call to the onsubmit event 46 if ( FCKBrowserInfo.IsIE ) 47 oForm.attachEvent( "onsubmit", functionPointer ) ; 48 else 49 oForm.addEventListener( 'submit', functionPointer, false ) ; 50 51 //** 52 // Attaches the functionPointer call to the submit method 53 // This is done because IE doesn't fire onsubmit when the submit method is called 54 // BEGIN -- 55 56 // Creates a Array in the form object that will hold all Attached function call 57 // (in the case there are more than one editor in the same page) 58 if (! oForm.updateFCKeditor) oForm.updateFCKeditor = new Array() ; 59 60 // Adds the function pointer to the array of functions to call when "submit" is called 61 oForm.updateFCKeditor[oForm.updateFCKeditor.length] = functionPointer ; 62 63 // Switches the original submit method with a new one that first call all functions 64 // on the above array and the call the original submit 65 // IE sees it oForm.submit function as an 'object'. 66 if (! oForm.originalSubmit && ( typeof( oForm.submit ) == 'function' || ( !oForm.submit.tagName && !oForm.submit.length ) ) ) 67 { 68 // Creates a copy of the original submit 69 oForm.originalSubmit = oForm.submit ; 70 71 // Creates our replacement for the submit 72 oForm.submit = FCKTools_SubmitReplacer ; 73 } 74 // END -- 75 } 76 77 function FCKTools_SubmitReplacer() 78 { 79 if (this.updateFCKeditor) 80 { 81 // Calls all functions in the functions array 82 for (var i = 0 ; i < this.updateFCKeditor.length ; i++) 83 this.updateFCKeditor[i]() ; 84 } 85 // Calls the original "submit" 86 this.originalSubmit() ; 87 } 88 89 // Get the window object where the element is placed in. 90 FCKTools.GetElementWindow = function( element ) 91 { 92 return this.GetDocumentWindow( this.GetElementDocument( element ) ) ; 93 } 94 95 FCKTools.GetDocumentWindow = function( doc ) 96 { 97 // With Safari, there is not way to retrieve the window from the document, so we must fix it. 98 if ( FCKBrowserInfo.IsSafari && !doc.parentWindow ) 99 this.FixDocumentParentWindow( window.top ) ; 100 101 return doc.parentWindow || doc.defaultView ; 102 } 103 104 FCKTools.GetElementPosition = function( el, relativeWindow ) 105 { 106 // Initializes the Coordinates object that will be returned by the function. 107 var c = { X:0, Y:0 } ; 108 109 var oWindow = relativeWindow || window ; 110 111 // Loop throw the offset chain. 112 while ( el ) 113 { 114 c.X += el.offsetLeft - el.scrollLeft ; 115 c.Y += el.offsetTop - el.scrollTop ; 116 117 if ( el.offsetParent == null ) 118 { 119 var oOwnerWindow = FCKTools.GetElementWindow( el ) ; 120 121 if ( oOwnerWindow != oWindow ) 122 el = oOwnerWindow.frameElement ; 123 else 124 { 125 c.X += el.scrollLeft ; 126 c.Y += el.scrollTop ; 127 break ; 128 } 129 } 130 else 131 el = el.offsetParent ; 132 } 133 134 // Return the Coordinates object 135 return c ; 136 } 137 138 /* 139 This is a Safari specific function that fix the reference to the parent 140 window from the document object. 141 */ 142 FCKTools.FixDocumentParentWindow = function( targetWindow ) 143 { 144 targetWindow.document.parentWindow = targetWindow ; 145 146 for ( var i = 0 ; i < targetWindow.frames.length ; i++ ) 147 FCKTools.FixDocumentParentWindow( targetWindow.frames[i] ) ; 148 } 149 150 FCKTools.GetParentWindow = function( document ) 151 { 152 return document.contentWindow ? document.contentWindow : document.parentWindow ; 153 } 154 155 FCKTools.HTMLEncode = function( text ) 156 { 157 if ( !text ) 158 return '' ; 159 160 text = text.replace( /&/g, '&' ) ; 161 text = text.replace( /</g, '<' ) ; 162 text = text.replace( />/g, '>' ) ; 163 164 return text ; 165 } 166 167 /** 168 * Adds an option to a SELECT element. 169 */ 170 FCKTools.AddSelectOption = function( selectElement, optionText, optionValue ) 171 { 172 var oOption = FCKTools.GetElementDocument( selectElement ).createElement( "OPTION" ) ; 173 174 oOption.text = optionText ; 175 oOption.value = optionValue ; 176 177 selectElement.options.add(oOption) ; 178 179 return oOption ; 180 } 181 182 FCKTools.RunFunction = function( func, thisObject, paramsArray, timerWindow ) 183 { 184 if ( func ) 185 this.SetTimeout( func, 0, thisObject, paramsArray, timerWindow ) ; 186 } 187 188 FCKTools.SetTimeout = function( func, milliseconds, thisObject, paramsArray, timerWindow ) 189 { 190 return ( timerWindow || window ).setTimeout( 191 function() 192 { 193 if ( paramsArray ) 194 func.apply( thisObject, [].concat( paramsArray ) ) ; 195 else 196 func.apply( thisObject ) ; 197 }, 198 milliseconds ) ; 199 } 200 201 FCKTools.SetInterval = function( func, milliseconds, thisObject, paramsArray, timerWindow ) 202 { 203 return ( timerWindow || window ).setInterval( 204 function() 205 { 206 func.apply( thisObject, paramsArray || [] ) ; 207 }, 208 milliseconds ) ; 209 } 210 211 FCKTools.ConvertStyleSizeToHtml = function( size ) 212 { 213 return size.endsWith( '%' ) ? size : parseInt( size ) ; 214 } 215 216 FCKTools.ConvertHtmlSizeToStyle = function( size ) 217 { 218 return size.endsWith( '%' ) ? size : ( size + 'px' ) ; 219 } 220 221 // START iCM MODIFICATIONS 222 // Amended to accept a list of one or more ascensor tag names 223 // Amended to check the element itself before working back up through the parent hierarchy 224 FCKTools.GetElementAscensor = function( element, ascensorTagNames ) 225 { 226 // var e = element.parentNode ; 227 var e = element ; 228 var lstTags = "," + ascensorTagNames.toUpperCase() + "," ; 229 230 while ( e ) 231 { 232 if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 ) 233 return e ; 234 235 e = e.parentNode ; 236 } 237 return null ; 238 } 239 // END iCM MODIFICATIONS 240 241 FCKTools.CreateEventListener = function( func, params ) 242 { 243 var f = function() 244 { 245 var aAllParams = [] ; 246 247 for ( var i = 0 ; i < arguments.length ; i++ ) 248 aAllParams.push( arguments[i] ) ; 249 250 func.apply( this, aAllParams.concat( params ) ) ; 251 } 252 253 return f ; 254 } 255 256 FCKTools.GetElementDocument = function ( element ) 257 { 258 return element.ownerDocument || element.document ; 259 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |